zbar snippets

How to read barcodes with ZXing and ZBar

Tagged barcode, code 39, data matrix, qr code, zbar, zxing  Languages bash

How to read barcodes

$ java -cp javase.jar:core.jar com.google.zxing.client.j2se.CommandLineRunner barcode.png --try_harder --format=DATA_MATRIX
$ zbarimg barcode.png

Note that cropping might improve detection accuracy. For example, crop image to show only the top-right corner using imagemagick’s convert (width 1500, height 500):

$ convert example.png -gravity northeast -crop 1500x500+0+0 cropped.png


  • if you need data correction (reliability) use a Data Matrix (used on e.g. products), Aztec (used on e.g. tickets), or QR code. These allow up to 30% of the image to be unreadable.
  • do not use a barcode that uses code 39 or 128. There is no error correction in code 39 and 128.
  • SimpleCV can also be used to detect barcodes.