I am trying to visualize bounding boxes on top of an image.
My Code:
color = (255, 255, 0)
thickness = 4
x_min, y_min, x_max, y_max = bbox
cv2.rectangle(img, (x_min, y_min), (x_max, y_max), color, thickness=thickness)
and I get
TypeError: Argument given by name ('thickness') and position (4)
Even if I pass thickness positionally, I get a different traceback:
cv2.rectangle(img, (x_min, y_min), (x_max, y_max), color, thickness)
raises TypeError: expected a tuple.
I got this error when passing the coordinate points as lists like:
start_point = [0, 0]
end_point = [10, 10]
cv2.rectangle(image, start_point, end_point, color, thickness=1)
Passing them as tuples solved the problem:
cv2.rectangle(image, tuple(start_point), tuple(end_point), color, thickness=1)
You need to make sure your bounding coordinates are integers.
x_min, y_min, x_max, y_max = map(int, bbox)
cv2.rectangle(img, (x_min, y_min), (x_max, y_max), color, thickness)
Either invocation of cv2.rectangle
will work.
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