如何使用zbar获取检测到的QR码的x,y位置? [英] How to get the x, y position of a detected QR code on an image with zbar?

查看:745
本文介绍了如何使用zbar获取检测到的QR码的x,y位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面图片的两个QR码中编码了1639号(可下载

解决方案

根据评论中的提示建议,

  print(symbol.location)

给出坐标。


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

解决方案

As suggested by a hint in a comment,

print(symbol.location)

gives the coordinates.

这篇关于如何使用zbar获取检测到的QR码的x,y位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆