I know all the solutions on the internet say to give integer co-ordinates but that isn't working for me.
def box(x,y,w,h):
print(x,y,w,h)
print(type(x),type(y),type(w),type(h))
cv2.rectangle(image, (int(x),int(y)) , (int(x+w),int(y+h)) , (255,0,0) , 2.0) ----> error
for i in indices.flatten():
x,y,w,h = boxes[i][0],boxes[i][1],boxes[i][2],boxes[i][3]
box(int(x),int(y),int(w),int(h))
Output of debug
414 1308 53 404
<class 'int'> <class 'int'> <class 'int'> <class 'int'>
Python version - 3.7.0 OpenCv version - 4.4.0.42
TypeError: function takes exactly 4 arguments (2 given)
happens if any coordinate is not int
.
Consider below snippets:
arr = np.zeros([200, 100, 3], np.int8)
_ = cv2.rectangle(arr, (-100, 20), (0, 0), (255, 0, 0), 2)
The above snippet will work. But the following snippets will raise TypeError
:
_ = cv2.rectangle(arr, (-100, 20), (0, 0.0), (255, 0, 0), 2)
_ = cv2.rectangle(arr, (-100, 20), (0, 12345678900000000000000001), (255, 0, 0), 2)
Using int coordinates worked well for me.
(startX, startY, endX, endY) = rect
startX = int(startX * W)
startY = int(startY * H)
endX = int(endX * W)
endY = int(endY * H)
cv2.rectangle(frame, (startX, startY), (endX, endY), (155, 255, 0), 2)
above code worked well. In my case rect contained values from 0 to 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With