问题:
使用Python + Opencv 对图像进行矩形框标注时
cv2.rectangle(img, (box[0], box[1]), (box[2], box[3]), (0, 255, 0) ,2)
报错:
TypeError: Layout of the output array rectList is incompatible with cv::Mat (step[ndims-1] != elemsize or step[1] != elemsize*nchannels)
原因:
img数组在内存中不是连续存储的
解决方法:
在绘制矩形框前,执行以下代码
img = np.ascontiguousarray(img, dtype=np.uint8)