Detect the size of a QR Code in Python using OpenCV and Zbar

柔情痞子 提交于 2019-12-12 05:28:29

问题


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

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


回答1:


Regarding the size of Code

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

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

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

Skewness of QRCode

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



来源:https://stackoverflow.com/questions/22743213/detect-the-size-of-a-qr-code-in-python-using-opencv-and-zbar

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