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)