我在 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()
uj5u.com熱心網友回復:
問題在于您的顯示功能,您可以使用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)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/514999.html
上一篇:OpenCV檢測哪些引腳彎曲
