python - 在python中使用在其上绘制矩形的图像

标签 python opencv computer-vision draw

我在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/

相关文章:

opencv - 如何根据 hog 特征去除相似图像?

c++ - 深度图像上的表面法线

python - 无返回值

python - Tensorflowcompute_gradients 和 apply_gradients 内存不足

python - 如何同时遍历两个文件中的行?

python - 来自 os.listdir() 的非字母数字列表顺序

.net - 使用 OpenCV 的感兴趣区域

c# - 通过 .NET 访问 MPEG 传输数据包

python - Opencv VideoCapture速度较慢,人们无法检测

c++ - OpenCV HoughLinesP