makiuchi-d / gozxing

Port of ZXing (https://github.com/zxing/zxing) core to pure Go.
Other
549 stars 66 forks source link

QRCodeReader sometimes fails to extract a qr code from an image #10

Closed krvs-esoptra closed 5 years ago

krvs-esoptra commented 5 years ago

The QRCodeReader fails to extract the QR code from the attached image: img_0448

It responds with a NotFoundException Go snippet:

...
img, _, _ := image.Decode(file)
bmp, _ := gozxing.NewBinaryBitmapFromImage(img)
qrReader := qrcode.NewQRCodeReader()
result, err := qrReader.Decode(bmp, nil)
...

The Java equivalent (https://github.com/zxing/zxing) on the other hand is able to do it Java snippet:

...
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source));
Reader reader = new QRCodeReader();
Result theResult = reader.decode(bitmap, null);
...
makiuchi-d commented 5 years ago

NewBinaryBitmapFromImage uses HybridBinarizer instead of GlobalHistgramBinarizer. Please try this:

img, _, _ := image.Decode(file)
src := gozxing.NewLuminanceSourceFromImage(img)
bmp, _ := gozxing.NewBinaryBitmap(gozxing.NewGlobalHistgramBinarizer(src))
qrReader := qrcode.NewQRCodeReader()
result, err := qrReader.Decode(bmp, nil)

I got a result without error.

krvs-esoptra commented 5 years ago

Yes, indeed it is working for all my images when explicitly specifying the GlobalHistgramBinarizer. Thank you so much