Python 如何使用zbar获取检测到的二维码在图像上的x、y位置?
我将数字1639编码在下图的两个二维码中(可下载)。我打印了它,拍了一张照片,并试图检测它:Python 如何使用zbar获取检测到的二维码在图像上的x、y位置?,python,image-processing,qr-code,zbar,Python,Image Processing,Qr Code,Zbar,我将数字1639编码在下图的两个二维码中(可下载)。我打印了它,拍了一张照片,并试图检测它: 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, 'Y8
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
即使二维码的大小很小(~1x1厘米),它也能工作,这太棒了
问题:如何获取二维码角点的x、y位置?
可以肯定的是,zbar
内部有此信息(必须能够解码二维码!),但是如何访问它呢
注意:在Windows和Python 2.7上
如评论中的提示所示
print(symbol.location)
给出坐标。如注释中的提示所示
print(symbol.location)
给出了坐标。
< P> >在ZLIB的C++文档中,符号< >代码>类有方法:代码> GETSyLosixOx()/CUT>,<代码> GETSLoopyTyOy()/<代码>和位置
字段可用于获取QR码的位置:
import zbar
image = read_image_into_numpy_array(...) # whatever function you use to read an image file into a numpy array
scanner = zbar.Scanner()
results = scanner.scan(image)
for result in results:
print(result.type, result.data, result.quality, result.position)
代码的大小也可能作为代码< >结果< /code >中的字段(例如<代码>结果,大小<代码> >,并且可以使用它来查找3个其他的角。 :在C++的DOCs中,<<代码> ZBAR::符号< /code >类有方法:代码> GETSyLosixx()/code >,<代码> GETSyLosiTyx()和,所以你的直觉是正确的 回到Python,当阅读zbar Python绑定时,看起来有一个获取位置大小()
字段可用于获取QR码的位置:位置
二维码的大小也可能作为import zbar image = read_image_into_numpy_array(...) # whatever function you use to read an image file into a numpy array scanner = zbar.Scanner() results = scanner.scan(image) for result in results: print(result.type, result.data, result.quality, result.position)
中的一个字段提供(例如result
),您可以使用它查找其他3个角。您是否尝试过result.size
?是否尝试过dir(symbol)
?dir(symbol)