我正在尝试将边界框可视化到图像的顶部。
我的代码:
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)我得到了TypeError: Argument given by name ('thickness') and position (4),即使我在位置上传递了厚度,我也得到了不同的回溯:
cv2.rectangle(img, (x_min, y_min), (x_max, y_max), color, thickness)提升TypeError: expected a tuple.
发布于 2019-05-07 02:55:39
您需要确保您的边界坐标是整数。
x_min, y_min, x_max, y_max = map(int, bbox)
cv2.rectangle(img, (x_min, y_min), (x_max, y_max), color, thickness)cv2.rectangle的任何一种调用都将起作用。
发布于 2020-09-07 07:12:53
当我将坐标点作为如下列表传递时,我得到了这个错误:
start_point = [0, 0]
end_point = [10, 10]
cv2.rectangle(image, start_point, end_point, color, thickness=1)将它们作为元组传递解决了问题:
cv2.rectangle(image, tuple(start_point), tuple(end_point), color, thickness=1)发布于 2021-04-28 11:14:36
不需要声明厚度,您可以直接给出数字,例如
cv2.rectangle(img, (0, 0), (250, 250), 3)这里3表示粗细,img名称也不需要冒号。
https://stackoverflow.com/questions/56010872
复制相似问题