我正在尝试使用Opencv练习绘图形状。
import numpy as np
import cv2 as cv
img = np.zeros((512,512,3), np.uint8)
#draw a red line
img = cv.line(img, (100,100), (300,300), (0,0,255),4)
#img = cv.circle(img,(447,63), 63, (0,0,255), -1)
cv.imshow('image',img)
cv.waitKey(0)
cv2.destroyAllWindows()
我跑步时遇到错误
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /build/buildd/opencv-2.4.8+dfsg1/modules/highgui/src/window.cpp, line 269
Traceback (most recent call last):
File "shapes.py", line 10, in <module>
cv.imshow('image',img)
cv2.error: /build/buildd/opencv-2.4.8+dfsg1/modules/highgui/src/window.cpp:269: error: (-215) size.width>0 && size.height>0 in function imshow
我搜索了各种Google链接,但都找不到形状。感谢您的帮助。
答案 0 :(得分:1)
错误消息表明您正在传递不正确的变量作为输入图像。首先,请确保您的numpy数组创建成功,然后不要尝试使用line函数的返回值,而应更改为:
img = cv.line(img, (100,100), (300,300), (0,0,255),4)
至:
cv.line(img, (100,100), (300,300), (0,0,255),4)