2

I am working on Android development where once I get byte array from Google Glass frame, I am trying to scan array using Zxing library and trying to detect 1d barcode(UPC code). I have tried this code snippet.

BufferedImage image = ImageIO.read(game);
BufferedImageLuminanceSource bils = new BufferedImageLuminanceSource(image);
HybridBinarizer hb = new HybridBinarizer(bils);
BitMatrix bm = **hb.getBlackMatrix();**
MultiDetector detector = new MultiDetector(bm);
DetectorResult dResult = detector.detect();
if(dResult == null)
{
    System.out.println("Image does not contain any barcode");
}
else
{
    BitMatrix QRImageData = dResult.getBits();
    Decoder decoder = new Decoder();
    DecoderResult decoderResult = decoder.decode(QRImageData);
    String QRString = decoderResult.getText();
    System.out.println(QRString);
} 

It works fine for QRcode, detects and decodes QR code well. But does not detect UPC code.

I also tried this code snippet,

InputStream barCodeInputStream = new FileInputStream(game);
BufferedImage barCodeBufferedImage = ImageIO.read(barCodeInputStream);
BufferedImage image = ImageIO.read(game);
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source));
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
int rowNumber = bitmap.getHeight()/2;
BitArray row = **bitmap.getBlackRow(0, null);**
Result theResult = rssExpandedReader.decodeRow(rowNumber, row, new Hashtable());

and in both I am getting "Exception in thread "main" com.google.zxing.NotFoundException".

Does anyone know how to fix this issue?

getBlackMatrix() - Converts a 2D array of luminance data to 1 bit. As above, assume this method is expensive and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or may not apply sharpening. Therefore, a row from this matrix may not be identical to one fetched using getBlackRow(), so don't mix and match between them.

getBlackRow()- Converts one row of luminance data to 1 bit data. May actually do the conversion, or return cached data. Callers should assume this method is expensive and call it as seldom as possible. This method is intended for decoding 1D barcodes and may choose to apply sharpening.

Dan Bonachea
  • 2,408
  • 5
  • 16
  • 31
  • Possible duplicate? http://stackoverflow.com/questions/10583622/com-google-zxing-notfoundexception-exception-comes-when-core-java-program-execut – rlegendi Jun 13 '14 at 14:45
  • 1
    Hi, It is not duplicate. :) The one discussed in the link is for decoding qr code. It is working for me. I am trying to scan, detect and decode 1D UPC code.Somehow, Zxing does not detect if image has UPC code or not. If I use clear UPC code, it decodes fine. For that I am using MultiFormatUPCEANReader to read UPC code. Right now, I am facing trouble detecting UPC code if it is anywhere in the image. – user3735642 Jun 13 '14 at 17:57

0 Answers0