我正在使用AR无人机的底部摄像头来检测二维码,以便我知道棋盘上无人机的下落。无人机悬停在棋盘上,每个方块都是一个保存位置的二维码(例如A1、C5、E7等)。当我按下某个键时,它会扫描二维码并将位置返回给我。
现在,我希望能够从众多的二维码中检测出一个。因为无人机可能有多个二维码在视线内。因为我需要知道无人机在哪个正方形上,或者至少是最近的一个(例如: A1上的2/3和A2上的1/3应该会产生A1)。下面是我目前使用的代码:
#!/usr/bin/python
from sys import argv
import zbar
import Image
import cv2
class DetectQRCode(object):
@classmethod
def detect_qr(self, image):
# create a reader
scanner = zbar.ImageScanner()
# configure the reader
scanner.parse_config('enable')
# obtain image data
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY,dstCn=0)
pil = Image.fromarray(gray)
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:
# do something useful with results
if symbol.data == "None":
return "Drone bevindt zich buiten het raster"
else:
return symbol.data这可以使用OpenCV,Python来完成吗?zbar有没有我可以用的东西?
发布于 2015-01-29 17:25:37
发布于 2015-05-03 07:06:52
如果在
for symbol in image:你输入print symbol.location,它会给出如下格式的坐标
((334,407),(497,424),(512,272),(340,251))
它给出了相机图像中二维码的四个角
然后,您可以使用如下命令来获取中心坐标
loc = symbol.location
x = (loc[0][0]+loc[2][0])/2
y = (loc[0][1]+loc[2][1])/2离相机图像中心的距离,如果中心是500,500,
distance_from_centre_squared = (x-500)**2 + (y-500)**2然后使用到中心距离最短的QR
https://stackoverflow.com/questions/28210912
复制相似问题