When scanning for a QR code like this:
no results are found with zxing. With my phone, there is no problem to scan it.
I'm using latest Java zwing 3.5.2.
Here is the used algorithm (the hard work is done by zxing):
class Results {
public final double rotation;
public final List<Result> results;
Results(double rotation, List<Result> results) {
this.rotation = rotation;
this.results = results;
}
}
protected Results getResults(BufferedImage image) {
LuminanceSource source = new BufferedImageLuminanceSource(image);
Reader reader = new MultiFormatReader();
for (int i=0; i<2; ++i) {
BinaryBitmap bitmap;
if (i == 0) {
bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source));
} else {
bitmap = new BinaryBitmap(new HybridBinarizer(source));
}
for (int r=0; r<4; ++r) {
if (r > 0) {
bitmap = bitmap.rotateCounterClockwise();
}
List<Result> results = tryDetect(reader, bitmap);
if (results != null) {
return new Results(r*90, results);
}
}
}
return null;
}
protected List<Result> tryDetect(Reader reader, BinaryBitmap bitmap) {
// We should just be catching ReaderException in here but we discovered
// an ArrayIndexOutOfBoundsException in the zxing library which prevents
// us from continuing. So we catch everything.
try {
// Look for multiple barcodes
MultipleBarcodeReader multiReader = new GenericMultipleBarcodeReader(reader);
Result[] theResults = multiReader.decodeMultiple(bitmap, HINTS);
if (theResults != null) {
return Arrays.asList(theResults);
}
} catch (Exception re) {
}
try {
// Look for multiple barcodes by quadrant
MultipleBarcodeReader multiReader = new GenericMultipleBarcodeReader(new ByQuadrantReader(reader));
Result[] theResults = multiReader.decodeMultiple(bitmap, HINTS);
if (theResults != null) {
return Arrays.asList(theResults);
}
} catch (Exception re) {
}
try {
// Look for pure barcode
Result theResult = reader.decode(bitmap, HINTS_PURE);
if (theResult != null) {
return Arrays.asList(theResult);
}
} catch (Exception re) {
}
try {
// Look for normal barcode in photo
Result theResult = reader.decode(bitmap, HINTS);
if (theResult != null) {
return Arrays.asList(theResult);
}
} catch (Exception re) {
}
return null;
}
}
Nearly all uses of zxing I've seen are quite similar.
I could be a bug in zwing or in my code. How to overcome this limitation?
I've tried to increase the resolution of the image, by interpolating, with no success.
Had the same issue, was able to fix it by adding white borders to the qrCode image before decoding
and then simply: