Reputation: 903
i created a simple program that detects qr code on image :
self.qrReader=cv2.QRCodeDetector()
self.text,points,_=self.qrReader.detectAndDecode(self.img)
now when im drawing rectangle on detected qr code :
cv2.rectangle(self.img,points[0][0],points[0][2],color,thickness)
im getting an error :
File "e:\Users\Abhimanyu\Documents\aiocv\aiocv\qr_code_reader_module.py", line 19, in findQRCode
cv2.rectangle(self.img,points[0][0],points[0][2],color,thickness)
cv2.error: OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'rectangle'
> Overload resolution failed:
> - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
> - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
> - Can't parse 'rec'. Expected sequence length 4, got 2
> - Can't parse 'rec'. Expected sequence length 4, got 2
when im printing points[0][0] :
[ 40. 40. ]
and when im printing points[0][2] :
[288.99997 288.99997]
the complete array looks like this :
[[[ 40. 40. ]
[288.99997 40. ]
[288.99997 288.99997]
[ 40. 288.99997]]]
whats wrong here?
Upvotes: 0
Views: 339
Reputation: 27547
Given in your post that print(points[0][0])
outputs [ 40. 40. ]
and print(points[0][2])
outputs [288.99997 288.99997]
, simply replace:
cv2.rectangle(self.img, points[0][0], points[0][2], color, thickness)
with:
pt1 = int(points[0][0][0]), int(points[0][0][1])
pt2 = int(points[0][2][0]), int(points[0][2][1])
cv2.rectangle(self.img, pt1, pt2, color, thickness)
Upvotes: 1