使用OpenCV和Zbar在Python中检测QR码的大小 [英] Detect the size of a QR Code in Python using OpenCV and Zbar

查看:204
本文介绍了使用OpenCV和Zbar在Python中检测QR码的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码,可以从网络摄像头中获取图像,然后使用zBar扫描QR码,并返回代码值和高亮显示QR码的图像(基于

I have code that takes an image from the webcam, scans it for QR codes using zBar and returns the value of the code and an image with the QR code highlighted (based off http://sourceforge.net/p/qrtracker/wiki/Home/). How can I also make it tell me the size of the code (as a pixel value or % of the screen)?

另一个问题:是否有办法检测其倾斜度(例如Z绕Y轴旋转)?

Additional question: is there a way to detect how skewed it is (e.g rotation in Z about the Y-axis)?

推荐答案

关于代码的大小

zBar提供了一种根据像素值执行此操作的方法(一旦您知道像素值的大小,就可以按百分比找到它)

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

我想在此处扩展代码: http://sourceforge.net/apps/mediawiki/zbar/index.php?title=HOWTO:_Scan_images_using_the_API

I would like to extend the code here: http://sourceforge.net/apps/mediawiki/zbar/index.php?title=HOWTO:_Scan_images_using_the_API

以上代码在图像中找到QR码,打印其数据等.现在检查最后几行代码:

Above code finds a QR code in an image, prints its data etc. Now checking last few lines of code:

import math
scanner.scan(image)
[a,b,c,d] = x.location   # it returns the four corners of the QR code in an order
w = math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)  # Just distance between two points
h = math.sqrt((b[0]-c[0])**2 + (b[1]-c[1])**2)
Area = w*h

QRCode的倾斜度

我认为您想将其转换为预定义的形状(例如正方形,矩形等).如果是这样,则可以定义预定义形状的角,例如((100,100),(300,100),(300,300),(100,300)).然后找到透视变换并根据需要应用变换.此处提供了OpenCV中的示例: http://docs.opencv.org/trunk/doc/py_tutorials/py_imgproc/py_geometric_transformations/py_geometric_transformations.html#perspective-transformation

I think you want to transform it into a pre-defined shape (like square, rectangle, etc). If so, you can define corners of a pre-defined shape, say ((100,100), (300,100),(300,300),(100,300)). Then find the perspective transform and apply the transformation if you would like. An example in OpenCV is provided here: http://docs.opencv.org/trunk/doc/py_tutorials/py_imgproc/py_geometric_transformations/py_geometric_transformations.html#perspective-transformation

这篇关于使用OpenCV和Zbar在Python中检测QR码的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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