使用在Python上绘制的矩形图像 [英] Using image with rectangle drawn over it in python

查看:6619
本文介绍了使用在Python上绘制的矩形图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python中使用 cv2.rectangle 在我的图片上绘制一个框。
image1 已正确加载。
然后我使用这个代码:

I'm using cv2.rectangle in python to draw a box on my image. image1 has already been loaded correctly. Then I use this code:

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 后的图像做什么,我都会遇到错误。如何检索或使用我绘制矩形的图片?

I get errors no matter what I do with the image after using cv2.rectangle. How can I retrieve or use the image on which I drew the rectangle?

推荐答案

这个问题似乎是由于使用cv2.rectangle由numpy的版本。版本1.6.2似乎引起这个错误,但这个问题不存在于1.9.2,只是升级它:

This issue appears to be caused by the version of numpy. Version 1.6.2 seems to cause this bug, but this issue is not present in 1.9.2, just upgrade it:

pip install numpy --upgrade

在Debian 7.8(kern 3.2)和Debian 8.0 OpenCV 2.4.9

Tested on Debian 7.8 (kern 3.2) and Debian 8.0 (kern 4.2) for OpenCV 2.4.9

这篇关于使用在Python上绘制的矩形图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆