我在python中使用cv2.rectangle
在图像上绘制一个框。image1
已经正确加载。
然后我使用以下代码:
cv2.rectangle(image1, (10, 10), (100, 100), (255,0,0), 2)
cv2.imshow('img', image1)
但是我得到这个错误:
TypeError: Layout of the output array img is incompatible with cv::Mat (step[ndims-1] != elemsize or step[1] != elemsize*nchannels)
无论使用
cv2.rectangle
后对图像做什么,都会出现错误。如何获取或使用在其上绘制矩形的图像?编辑
更正,我在使用cv2.rectangle时收到此错误,而不是在此之后。
最佳答案
嘿,为原始海报提供帮助晚了几年,但是我自己碰到了这个问题,并且无法控制图像源(因此cv2.imread
对我来说不是一个很好的解决方案-我必须编写镜像首先返回磁盘)。
我能够继续进行image = image.copy()
。
不知道根本原因是什么-相等检查显示数组的每个值都相等,并且数组是正确的类型。 ¯\_(ツ)_/¯
关于python - 在python中使用在其上绘制矩形的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23723369/