zxingify / zxingify-objc

An Objective-C Port of ZXing
Apache License 2.0
3.07k stars 753 forks source link

DataMatrix barcode not recognized #474

Closed skogsbaer closed 1 year ago

skogsbaer commented 5 years ago

I'm trying to scan DataMatrix barcodes under iOS with ZXing. Some barcodes are recognized but many are not. Here is a picture for which ZXing fails to recognize the barcode on my iPhone 8:

datamatrix

Here is the code that invokes ZXing on a given CGImageRef:

- (BarcodeResult *)findBarcode:(CGImageRef)img
{
    ZXLuminanceSource *source = [[ZXCGImageLuminanceSource alloc] initWithCGImage:img];
    ZXBinaryBitmap *bitmap = [ZXBinaryBitmap binaryBitmapWithBinarizer:[ZXHybridBinarizer binarizerWithSource:source]];
    NSError *error = nil;
    ZXMultiFormatReader *reader = [ZXMultiFormatReader reader];
    ZXResult *result = [reader decode:bitmap
                                hints:self.hints
                                error:&error];
    if (result) {
        NSString *contents = result.text;
        ZXBarcodeFormat format = result.barcodeFormat;
        NSString *kindString = barcodeFormatToString(format);
        return [[BarcodeResult alloc] initWithKind:kindString text:contents];
    } else {
        return nil;
    }

}

The hints are configured as follows:

    ZXDecodeHints *hints = [ZXDecodeHints hints];
    hints.tryHarder = YES;
    [hints addPossibleFormat:kBarcodeFormatDataMatrix];
    [hints setEncoding:NSISOLatin1StringEncoding]; // I know that the code is latin1 encoded

Any suggestions how to get barcode scanning to work for such DataMatrix codes?

skogsbaer commented 5 years ago

any progress on this ticket?

SNThunderbolt commented 4 years ago

any progress on this ticket?

Could you find any workarounds? I have the exact same issue

akshardarji commented 4 years ago

@skogsbaer Not sure, however, you can try by downsize the resolution of the image and pass that image in method findBarcode.

benjohnde commented 4 years ago

I am going to look into that issue as I am bringing some fixes to the DataMatrix reader. Hopefully that fixes your issue. I cannot give extended support for that port besides bringing the main functionality back as good as I can.

benjohnde commented 1 year ago

Unfortunately, I can no longer provide support for this codebase, the topic will be closed. I recommend to take a look at https://github.com/zxing-cpp/zxing-cpp created and maintained by the very ambitious @axxel!