QRCodeReader.decode / BarcodeReader.Decode gives null in return

Apr 13, 2015 at 9:38 AM
I'm trying to decode a QR code with C# (inside webAPI).
I receive the image in a base64 format.
When I get a generated QR image, the decode works fine.
But when I send a photo of the same QR image, the decoding returns null,

How can I manage that the decoder recognized the scanned QR code?

Used code:
            //imageString = base64 string of image
            var bitmapData = Convert.FromBase64String(FixBase64ForImage(imageString));
            var streamBitmap = new System.IO.MemoryStream(bitmapData);
            var bitmap = new System.Drawing.Bitmap((System.Drawing.Bitmap)System.Drawing.Image.FromStream(streamBitmap));

            //test1
            var luminanceSource1 = new ZXing.BitmapLuminanceSource(bitmap);
            var binarizer1 = new ZXing.Common.HybridBinarizer(luminanceSource1);
            var mapa1 = new ZXing.BinaryBitmap(binarizer1);
            var readCode1 = new ZXing.QrCode.QRCodeReader();
            var result1 = readCode1.decode(mapa1);

            //test2
            var options2 = new ZXing.Common.DecodingOptions();
            options2.TryHarder = true;
            var formats2 = new List<ZXing.BarcodeFormat>();
            formats2.Add(ZXing.BarcodeFormat.QR_CODE);
            options2.PossibleFormats = formats2;
            var reader2 = new ZXing.BarcodeReader { AutoRotate = true, TryInverted = true, Options = options2 };
            var result2 = reader2.Decode(bitmap);
when I send the generated image:
https://drive.google.com/file/d/0Bx3ZNv0eWcu0dHNhcEROVXpuRW8/view?pli=1
The qr code is decoded successfully

When I send the photo of the same image:
https://drive.google.com/file/d/0Bx3ZNv0eWcu0N192eXFuZGdWT1k/view?pli=1
the qr code decode returnes null

What can I do to get the photo correctly decoded?
Coordinator
Apr 13, 2015 at 6:46 PM
Sometimes small differences in the binarized image can make a difference.
In your case if you try the GlobalHistogramBinarizer instead of the default HybridBinarizer.
...
var reader2 = new ZXing.BarcodeReader(null, null, ls => new GlobalHistogramBinarizer(ls)) { AutoRotate = true, TryInverted = true, Options = options2 };
...
Apr 14, 2015 at 6:30 AM
Thank you micjahn!
The photo-image is now detected!