TypeError: Argument given by name (‘thickness’) and position (4)
cv2.rectangle(image, (left,top), (right , bottom), (255, 0, 0), thickness=2)
错误的原因有一下两个:
- 左上角坐标以及右下角的坐标为小数导致的类型报错,使用int()整数化
- cv2.rectangle 函数要求image的形状应该为(通道,长,宽),如果使用其他读入方式,比如gdal读入影像,此时的image形状为(长、宽、通道),如果使用cv2操作需要转换,如下:
image = np.rollaxis(image,2,0)
cv2.rectangle(image, (left,top), (right , bottom), (255, 0, 0), thickness=2)
本文解决了在使用cv2.rectangle函数时出现的TypeError问题,详细分析了错误原因,包括坐标类型的错误和图像维度不匹配,并提供了相应的解决方案。
657

被折叠的 条评论
为什么被折叠?



