Code 128 not being detected

104 views
Skip to first unread message

Abdeali Kothari

unread,
May 29, 2016, 10:48:46 PM5/29/16
to zxing
Hi,

I tried finding the code from the image at https://commons.wikimedia.org/wiki/File:Wikipedia_barcode_128.svg ad zxing doesn't seem to be able to recognize it. I would have thought this was a simple and very clear barcode ?

I was trying out the zxing library and downloaded the core and javase jar files from maven. I ran the command using:

java -cp $HOME/Downloads/javase-3.2.1.jar:$HOME/Downloads/core-3.2.1.jar:$HOME/Downloads/jcommander-1.48.jar com.google.zxing.client.j2se.CommandLineRunner file:///home/ajk/Documents/barcode.png

and it gives no barcode found.

I was wondering why this could be ? I thought this was a very clean and easy to read barcode ...

PS: It does work fine for:
- https://commons.wikimedia.org/wiki/File:Rationalized-codabar.png
- https://commons.wikimedia.org/wiki/File:Qrcode_wikipedia.jpg
- https://commons.wikimedia.org/wiki/File:Datamatrix.svg

But doesn't work for:
- https://commons.wikimedia.org/wiki/File:Code39_Wikipedia.svg

Lachezar Dobrev

unread,
May 30, 2016, 5:43:17 AM5/30/16
to Abdeali Kothari, zxing
  ZXing Java-SE module can only scan images that can be loaded from the Java Imaging IO.
  The Java Imaging IO does not support reading SVG.
  The Wikipedia article for the Code-128 and Code-39 features a SVG (Scalable Vector Graphics) image for demonstration. To make matters worse the PNG images that you see are quite small, and the lines are smoothed/blurred which makes them unnecessarily hard to read, as they blend and end up looking like a solid black block, rather than thin black lines.
  You can see the problem using:
  ...CommandLineRunner --dump_black_point file:///home/ajk/Documents/barcode.png
  This will create a file:///home/ajk/Documents/barcode.mono.png file that shows the black regions.

  You can see that the bar-codes are read correctly if you choose to download a higher resolution PNG image, for instance the 640×394 variant of the Code-128 is read correctly. I suspect that if you find a SVG-PNG converter that does not perform blurring even the smaller resolution images will work.

  As for the Data-Matrix: this is a 2D bar-code that is much less sensitive to image blurring, since the width of the black dots is irrelevant.
  As for the Coda-Bar: the image is a sharp raster image in PNG format, and does not suffer from line blurring.



--
You received this message because you are subscribed to the Google Groups "zxing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zxing+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sean Owen

unread,
May 30, 2016, 4:39:59 PM5/30/16
to zxing
Yeah that's right. The javase module already pulls in https://github.com/jai-imageio/jai-imageio-core to add support for reading some extra formats like TIFF and BMP. There is also a nice-looking project https://github.com/haraldk/TwelveMonkeys/tree/master/imageio/imageio-batik that would add SVG support via ImageIO and Batik. I had some Batik problems when playing with it, and in the end didn't seem to read SVG barcodes correctly. But someone more determined than I could probably get it to work. If so, we might take that solution and break out a new optional module for the extra ImageIO dependencies.

Abdeali Kothari

unread,
May 30, 2016, 10:08:46 PM5/30/16
to zx...@googlegroups.com
Hi Sean, Lachezar,

Thank you for the replies.
I tried using the larger image and it did work fine. It seems the SVG to PNG conversion is the issue and is making the barcode blurred (as Lachezar pointed out).
Sean, thanks for pointing out the additional libraries :) I'll take a look at them !

Thanks :)

Reply all
Reply to author
Forward
0 new messages