OpenCV二维码检测器给出的是圆圈而不是方框



我对OpenCV和更高级的python代码处于相当初级的水平

我正在尝试制作一个二维码检测器(来自图像而不是来自摄像头(来工作。我在互联网上搜索过,找到了一个代码,以便开始学习,代码是错误的,所以我试图用我有限的知识和线索来修复它,但现在图像而不是qr码图像周围的方框,给出了一个以0,0坐标为中心的圆(将厚度改为100而不是2(,我不明白为什么。。下面的代码:

import cv2
import numpy as np
import sys
import time
if len(sys.argv)>1:
inputImage = cv2.imread(sys.argv[1])
else:
inputImage = cv2.imread("path/qrcode.jpg")
# Display barcode and QR code location
def display(im, bbox):
n = len(bbox)
bbox = bbox.astype(int)
for j in range(n):
cv2.line(im, tuple(bbox[j][0]), tuple(bbox[ (j+1) % n][0]), (255,0,0), 3)
# Display results
cv2.imshow("Results", im)
# Create a qrCodeDetector Object
qrDecoder = cv2.QRCodeDetector()
# Detect and decode the qrcode
t = time.time()
data,bbox,rectifiedImage = qrDecoder.detectAndDecode(inputImage)
print("Time Taken for Detect and Decode : {:.3f} seconds".format(time.time() - t))
if len(data)>0:
print("Decoded Data : {}".format(data))
display(inputImage, bbox)
rectifiedImage = np.uint8(rectifiedImage);
cv2.imshow("Rectified QRCode", rectifiedImage);
else:
print("QR Code not detected")
cv2.imshow("Results", inputImage)
cv2.waitKey(0)
cv2.destroyAllWindows()

问题在于您的显示功能,您可以使用cv2.rectangle

def display(im, bbox):
bbox = bbox.astype(int)
cv2.rectangle(im, bbox[0][0], bbox[0][2], (255, 0, 0), 2)
# Display results
cv2.imshow("Results", im)

最新更新