ZXing: Scanning Barcode with UPC + 5 Supplemental - android

I'm trying to scan barcode as shown below using the ZXing library.
(source: minus.com)
// start scanning
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "ONE_D_MODE");
startActivityForResult(intent, REQUEST_CODE);
If I replace "ONE_D_MODE" with "TWO_D_MODE", the app can successfully detect both barcodes; but the value of result won't change (still 051488005995).
// onActivityResult
if(requestCode == REQUEST_CODE && resultCode == RESULT_OK)
String result = intent.getStringExtra("SCAN_RESULT");
Is there any way to get both barcode value 051488005995 and 50115?
Any other way to obtain the isbn (0142501158) above the barcodes without getting the supplemental +5 barcode (50115) would also be great.
Thanks.

ONE_D_MODE will work for you. You probably really want PRODUCT_MODE. There is no such thing as TWO_D_MODE. By setting this it just scans all default formats.
It is not scanning both barcodes. It is just scanning the product code. So I'm not sure what you mean about getting just the product code: that's what you already have. I assume you want both.
MultipleBarcodeReader is not quite for this situation as no part of the library scans for the UPC/EAN supplement by itself. It is scanned for as an extension to UPC and EAN codes only.
It will already scan for some types of extension barcode in UPCEANExtensionSupport. It doesn't give you back the raw values but rather tries to parse out metadata and returns that in result metadata. If that's what you really want, it already does this. Otherwise you have to modify the code.
If it reads the UPC/EAN code but can't find an extension code, it will not fail the scan, and will only return the primary code. If you want it to only return if both are found, again you'd have to change your copy of the core library.

FYI you can scan UPC 12+5 codes via Intent/zxing. The only catch is that you have to force the +5, so you can't scan normal barcodes.
From my thread with #srowen: https://github.com/zxing/zxing/issues/217#issuecomment-54818496
Passed the hint as an extra to the Intent, inside IntentIntegrator=>initiateScan (I'll have to make an overriden method to make this optional later):
// Force 5 digit extension
intentScan.putExtra("ALLOWED_EAN_EXTENSIONS", new int[] {5});
I confirmed it was recognized from my Android logcat:
DecodeHintManager﹕ Hints from the Intent: {ALLOWED_EAN_EXTENSIONS=[I#42a38540}
Retrieved extension values in my scan result:
String extension = intent.getStringExtra("SCAN_RESULT_UPC_EAN_EXTENSION");
Now I got some UPC 12+5 :)
Content:079808007955, Format:UPC_A, Extension: 74700

As far as I know, this is not possible using zxing via an Intent.
However, you can embed ZXing in your code directly (by adding the ZXing source to your code directory). Then you are able to use the com.google.zxing.MultipleBarcodeReader. The function decodeMultiple() returns an array of barcodes which then can be processed further.
A small example:
// data: YUV camera preview; width/height: preview size
Result[] decode(byte[] data, int width, int height) {
PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
MultipleBarcodeReader reader = new MultipleBarcodeReader(new MultiFormatOneDReader(null));
return reader.decodeMultiple(bitmap);
}

Related

Google Barcode API PDF417 not working

I've followed the directions in the Google codelab to get the Baracode API to detect and decode a standard QR code. I've done a simple integration to get the camera to provide the image and it works. Then I try a PDF417 bar code, and nothing.
Bitmap myBitmap = BitmapFactory.decodeResource(
getApplicationContext().getResources(),
R.drawable.barcode);
BarcodeDetector detector =
new BarcodeDetector.Builder(getApplicationContext())
.setBarcodeFormats(Barcode.PDF417)
.build();
Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
SparseArray<Barcode> barcodes = detector.detect(frame);
Barcode thisCode = barcodes.valueAt(0);
barcodes is a zero length object and thisCode fails trying to get the value at position 0. I've tried feeding a PDF417 barcode I took a picture of as well as a barcode from an online generator.
Can someone help me?
Thanks in advance!!
A quick answer to your question, you either need to change the barcode flag to ALL_FORMATS (Barcode.ALL_FORMATS) or you should only provide the barcode. In other words, there should be no other visual information alongside the barcode (crop it). Otherwise, the API can't find the PDF-417 barcode.

Android ZBar QR Code Scanner - How to read every QR Code

I currently implemented ZBar QR Code Scanner Library into my own app. But, so far, I am just able to read a QR Code that leads to a website. What should I do if I want to scan a QR Code that leads you to dial a phone number or text messages? How do I make my app read any QR Code?
The content of the QR code should be irrelevant -- it's just text. It might happen to contain a URL, but that doesn't change the format of the QR code.
int result = imageScanner.scanImage(image);
// Nonzero means a result was found
if (result != 0) {
// Typical only one symbol unless multiple codes were found
// in the scanned image
for (Symbol symbol : imageScanner.getResults()) {
// .getData() gives the string content of the QR code
String qrCodeContent = symbol.getData();
}
}

Zxing detects on Android device but not on pc

I am using Zxing core.jar to scan bar codes and qr codes and it's working perfectly, but I want to make tests using Robolectric, to run automated tests without an emulator or device, that will take N number of images through zxing, so my problem is that zxing for some reason is not detecting any type of code format from the .jpg files, I'm not sure if there is a limit size on the image, or something else that I'm missing. The piece of code that does the detection is this, which works fine with frame previews converted to jpgs
BinaryBitmap bitmap = getBitmapFromImageData(input);
Collection<BarcodeFormat> decodeFormats = getDecodeFormats();
Map<DecodeHintType, Object> hints = getHints(decodeFormats);
MultiFormatReader multiFormatReader = getMultiFormatReader(hints);
Result rawResult;
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
} catch (NotFoundException e) {
// not really an error, just QR code not found
Log.e(LOG_TAG, "Code Detection not found exception.");
return null;
}
Where the input contains the byte array in jpg format and is being converted by getBitmapFromImageData to Zxings internal formats. And like I said the library is working fine in the device, but I can't find any logical reason on why running this code from my pc won't work.
You're not showing any key code, like how you are reading your image. You should check whether it is being read correctly, being binarized correctly by your code, etc. Look at the unit tests in the project to see how to correctly read and process and image on the desktop. I don't know what your code may be doing in the "get" methods that is different.

Feed image to android emulators camera

I have developed an application that calls the ZXing library to invoke the camera.
I have now just been told that we need this working in the emulator for testing purposes.
I don't want to change the code to read from a file, I wan't to call the library, which will call the camera and I wan't the camera to think its looking at an image (if that makes sense).
I've seen a lot around of using webcams but I don't want a live feed.
Does anyone know if this is at all possible?
It depends on how you're integrating with Zxing. If you are scanning barcodes via intent, then the web-cam style live feed may be your only option.
AFAIK there is a reader class that expects you to supply the images. Something like this...
Reader reader = new MultiFormatReader(); //If you are calling the reader in your code
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); //The source as
//supplied by you
Result result = reader.decode(bitmap);
String text = result.getText();
Note that the above code is bits and pieces taken from here .
So it looks like you should be able to supply some image and have the bar code reader take a shot at it.

zxing not found exception in android

Hello everyone,
If any one of you can help me this. I am using zxing to decode barCode image, but it returns com.google.zxing.NotFoundException, don't know why. The same image gets decoded via Intent provided to zxing, but not when I use it to decode from image file.
The code that I am using is below :
mMultiFormatReader = new MultiFormatReader();
mMultiFormatReader.setHints(null);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(new RGBLuminanceSource(path)));
Result result = mMultiFormatReader.decodeWithState(bitmap);
I don't think it's exactly the same image, since you can't have it scan a file by Intent. I assume you mean that you can scan the image off your screen fine, but the image itself does not decode.
That's just life, really. Some images won't happen to decode. But you may try TRY_HARDER mode or use a different binarizer to see if that works.

Categories

Resources