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

耗尽温柔 提交于 2019-12-10 05:32:11

问题


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).


回答1:


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



来源:https://stackoverflow.com/questions/23796025/python-code-for-determining-corner-locations-of-a-qr-code-using-zbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!