How to get QR / barcode style coding type with python-qrtools / ZBar?

On my Ubuntu server, I installed the python-qrtools package (which uses zbar ) using sudo apt-get install python-qrtools to decode QR code and barcode images in Python as follows:

 >>> qr = qrtools.QR() >>> qr.decode('the_qrcode_or_barcode_image.jpg') True >>> print qr.data Hello! :) 

It works great.

Now I want to save this data and restore the image at a later point in time. But the problem is that I don’t know if the source image was a QR code or some type of barcode. I checked all the properties of the qr object, but none of them gave me the type of coding style (QR / bar / other).

This SO thread describes that ZBar does return a coding style type, but it only gives an example in Objective-C, plus I'm not sure if this is actually the answer to what I'm looking for.

Does anyone know how I can find out the type of coding style (e.g. QR code / BAR code / other) in Python (preferably using the python-qrtools package)? And if not in Python, are there any Linux command line tools that can figure this out? All tips are welcome!

+4
source share
1 answer

Looking at the source of qrtools, I see no way to get this type, but there is a zbar python lib based on the scan_image example , the code seems to do what you want:

 import zbar import Image scanner = zbar.ImageScanner() scanner.parse_config('enable') img = Image.open("br.png").convert('L') width, height = img.size stream = zbar.Image(width, height, 'Y800', img.tostring()) scanner.scan(stream) for symbol in stream: print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data 

Using a random barcode that I grabbed from net :

 decoded UPCA symbol "123456789012" 

Using this qr code :

  decoded QRCODE symbol "http://www.reichmann-racing.de" 
+5
source

All Articles