I am at an fairly beginner level with OpenCV,and more advanced python code
I am trying to make a QR Code Detector (from an image-not from cam feed) to work. I ve searched on the internet, found a code in order to start learning from it, the code was wrong so I tried, with my limited knowledge and threads from here, to fix it but now the image instead of a box around the qr code image gives a circle with the 0,0 coordinates as its center(change the thickness to 100 instead of 2), and I can't understand why..The code below:
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()
CodePudding user response:
The problem is with your display function, you can use 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)