Search code examples
pythonimage-processingqr-codezbar

How to get the x, y position of a detected QR code on an image with zbar?


I encoded the number 1639 in the two QR codes of the image below (downloadable here). I printed it, took a photo and tried to detect it:

import zbar
from PIL import Image 

scanner = zbar.ImageScanner()
pil = Image.open('20180520_170027_2.jpg').convert('L')
width, height = pil.size
raw = pil.tobytes()
image = zbar.Image(width, height, 'Y800', raw)
result = scanner.scan(image)

for symbol in image:
    print symbol.data.decode(u'utf-8')     # 1639

It works, even if the size of the QR code is small (~1x1 cm), which is great!

Question: how to get the x, y position of the corners of the QR codes?

It's sure that zbar has this information internally (mandatory to be able to decode the QR code!), but how to get access to it?

Note: here is how to install zbar on Windows and Python 2.7

enter image description here


Solution

  • As suggested by a hint in a comment,

    print(symbol.location)
    

    gives the coordinates.