Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python code for determining corner locations of a QR Code using Zbar

I would like to extend the code here to extract the corners of the QCodes.

#!/usr/bin/python
from sys import argv
import zbar
from PIL import Image

if len(argv) < 2: exit(1)

# create a reader
scanner = zbar.ImageScanner()

# configure the reader
scanner.parse_config('enable')

# obtain image data
pil = Image.open(argv[1]).convert('L')
width, height = pil.size
raw = pil.tostring()

# wrap image data
image = zbar.Image(width, height, 'Y800', raw)

# scan the image for barcodes
scanner.scan(image)

# extract results
for symbol in image.symbols:
    # do something useful with results
    print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data

# clean up
del(image)

In a previous posting, the author indicates that this is possible "*zBar provides a method to do this in terms of pixel values (Once you know the size in pixel values, you can find it in %**>"

See Detect the size of a QR Code in Python using OpenCV and Zbar )

I referred to the Zbar SDK ( http://zbar.sourceforge.net/api/classzbar_1_1Symbol.html ), and still couldn't figure out how to extract the corners. I'd appreciate it if someone could show me how (to extract the corners using Python).

like image 613
user3614305 Avatar asked May 22 '14 00:05

user3614305


People also ask

What are the corners of QR code?

Three corners of the QR Code contain the finder pattern, a nested series of black and white squares that, when detected by an optical scanner and interpreted by software, allow the scanning device to determine the orientation of the QR Code. Two other patterns are also present.


1 Answers

In your loop, try:

topLeftCorners, bottomLeftCorners, bottomRightCorners, topRightCorners = [item for item in symbol.location]

You'll get the 4 corners

Late answer but this can help others Dom

like image 172
Dominique Avatar answered Oct 05 '22 23:10

Dominique