I have a test program that creates a bunch of different bar/image codes and reads them back. Not all codes survive a roundtrip. For example UPC_A and UPC_E can be successfully written, but not read. Interestingly, reading the same images with the android app works perfectly fine.
Here's the relevant code snippets.
private static final LinkedHashSet<BarcodeFormat> formats = new LinkedHashSet<>();
static {
formats.add(BarcodeFormat.CODABAR);
formats.add(BarcodeFormat.CODE_39);
formats.add(BarcodeFormat.CODE_93);
formats.add(BarcodeFormat.CODE_128);
formats.add(BarcodeFormat.DATA_MATRIX);
formats.add(BarcodeFormat.EAN_8);
formats.add(BarcodeFormat.EAN_13);
formats.add(BarcodeFormat.ITF);
formats.add(BarcodeFormat.QR_CODE);
formats.add(BarcodeFormat.RSS_14);
formats.add(BarcodeFormat.RSS_EXPANDED);
formats.add(BarcodeFormat.UPC_A);
formats.add(BarcodeFormat.UPC_E);
}
...
BufferedImage read = ImageIO.read(inStream);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(read)));
HashMap<DecodeHintType, Object> decodeHints = new HashMap<DecodeHintType, Object>();
decodeHints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
decodeHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
MultiFormatReader reader = new MultiFormatReader();
reader.setHints(decodeHints);
Result result = reader.decodeWithState(binaryBitmap);
For UPC_A and UPC_E, decpdong fails with NotFoundException.
What's wrong? The android app uses the same value of "POSSIBLE_FORMATS" (except TRY_HARDER, but with or without it my code still fails). The sequence of api calls is also the same except a different luminance source.
What am I missing?
Thanks,
Yury
--
You received this message because you are subscribed to a topic in the Google Groups "zxing" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/zxing/iCODr5bZKHk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to zxing+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Another thing is even with the app the scanned values are different from what I was encoding.
Namely for UPC_A the encoded value is "12345678901", but the app gives me 123456789012.
for UPC_E, the encoded value if "12345670". It's really hard to scan, takes a lot of camera positioning and the result is 12870561. In contrast, UPC_A scans immediately.
Thanks Sean.
Few points.
1. Yes, UPC-A image is read fine if it's generated with a larger margin. It's a bit odd though. If I specify the hint margin 5 vs margin 6, the image look like the a lot more than 1 pixel of margin was added. See attached.
2. How can my program validate the min margin value for the above (it's user-supplied). I would like to guard users from producing unreadable images.
3. In regards to UPC-E. I am a little confused here. This writer requires that I supply 8 digits and explicitly fails for 6 or 7. I am under impression that the last digit being the check digit should be the 7th? Not sure what the 8th one should be.
4. Also, analogous to UPS-A, where the check digit is added if missing from the data (which is a nice service) or validated when present, should UPC-E writer similarly allow 6 or 7?
"In addition, a UPC-A symbol requires a quiet zone (extra space of 9 modules wide) before the S (start) and after the E (end) guard patterns"
UPCAWriter does not add any. It fills an area of 95 modules and then you at the mercy of the scaling algorithm and your MARGIN value so you might inadvertently get enough of a quiet zone that way.
UPCAReader, when decoding, only expects "a quiet zone at least as big as the start pattern" which is only 3 modules, not 9 (see UPCEANReader.findStartGuardPattern(BitArray row)), i.e. sounds like an opportunity for some false positives.
--