1

I'm working on a project which involves taking an image file as input on my desktop and then detecting and decoding all the barcodes present, both 1D and 2D.

I've been working with zxing and with the help of GenericMultipleBarcodeReader I was able to read multiple 1D barcodes from the image. However, it fails to detect 2D barcodes. But if I crop the 2D barcode and input this cropped part separately it detects and decodes it without any problem.

So, if my image has 2 1D barcode and a 2D barcode my output consists of just the 2 1D barcodes decoded.

I also tried using ByQuadrantReader but that doesn't work either.

My code:

LuminanceSource source = new BufferedImageLuminanceSource(image); 
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); 
Result[] result; 
HashMap<DecodeHintType,Object> hints = new HashMap<>(); 
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); 
    try 
    { 
result = new GenericMultipleBarcodeReader(new MultiFormatReader()).decodeMultiple(bitmap, hints); 
     } 
    catch (ReaderException re) 
    {
    return re.toString(); 
    } 
    List<String> strings = new ArrayList<String>();
     for (Result r: result)
    {
    strings.add(r.getText()); 
    } 
    return String.valueOf(Arrays.toString(strings.toArray()));

Could anyone tell me a way to do this?

Rohit
  • 31
  • 1
  • 7
  • @Skippy `LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Result[] result; HashMap hints = new HashMap<>(); hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); try { result = new GenericMultipleBarcodeReader(new MultiFormatReader()).decodeMultiple(bitmap, hints); } catch (ReaderException re) { return re.toString(); } List strings = new ArrayList(); for (Result r: result){ strings.add(r.getText()); } return String.valueOf(Arrays.toString(strings.toArray()));` – Rohit Aug 01 '13 at 17:55
  • Sorry for the poor formatting. I'm new here and haven't figured out how to format my code here yet. – Rohit Aug 01 '13 at 17:56
  • @Skippy thanks for the formatting link, will be waiting for your help on the code. – Rohit Aug 02 '13 at 05:15
  • @Skippy Is there any way I can ask a particular person to answer a question? – Rohit Aug 02 '13 at 09:45

1 Answers1

0

QR codes can be found anywhere in the image, but Data Matrix must be in the center of the image to be found. This is why it's working when you crop the image.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
  • Is there any way I could read a Data Matrix from anywhere in an image? Changing the code somehow? I saw two different online barcode readers which could do that but they weren't not open source. – Rohit Aug 05 '13 at 08:36
  • also is there any way I could mark the barcodes which are decoded? Like draw a colored rectangle around them in the image or something to show that those are the barcodes which have been detected and decoded? This way I would be able to tell which of a set of barcodes was not decoded! – Rohit Aug 05 '13 at 13:00
  • Hi, I really need help on this. I tried further but couldn't come up with anything. Can you please help me out here if possible? – Rohit Aug 13 '13 at 12:21