【问题标题】:OpenCV QR Code Detector gives circle instead of boxOpenCV QR码检测器给出圆圈而不是框
【发布时间】:2022-10-13 15:56:35
【问题描述】:

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

我正在尝试使 QR 码检测器(来自图像而不是来自凸轮源)工作。我在互联网上搜索,找到了一个代码以便开始从中学习,代码是错误的,所以我尝试用我有限的知识和来自这里的线程来修复它,但现在图像而不是二维码周围的框图像给出了一个以0,0坐标为中心的圆,我不明白为什么..下面的代码:

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

【问题讨论】:

    标签: python opencv qr-code


    【解决方案1】:

    问题在于你的显示功能,你可以使用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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多