简体   繁体   English

OpenCV(4.2.0) 错误: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

[英]OpenCV(4.2.0) error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

I've been getting this error.我一直收到这个错误。 I have copied the code from This website and making changes so that the code actually works.我已经从这个网站复制了代码并进行了更改,以使代码真正起作用。 The code:编码:

ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", help="Image Path")
args = vars(ap.parse_args())
img_path = args['image']

#Reading image with opencv
img = cv2.imread(img_path)

#Reading csv file with pandas and giving names to each column
index=["color","color_name","hex","R","G","B"]

csv = pd.read_csv('colors.csv', names=index, header=None)
cv2.namedWindow('image')
cv2.setMouseCallback('image', draw_function)

while(1): 
    #This is error line
    cv2.imshow("image",img)
    [...]

The full Traceback:完整的追溯:

Traceback (most recent call last):
  File "C:\Users\someone\Documents\python\____The Useless Installer____\PY\color_detection.py", line 39, in <module>
    cv2.imshow("image",img)
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

I've looked here and here but I don't understand how to fix this and I don't think it relates to my question that much either.我看过这里这里,但我不明白如何解决这个问题,我认为它与我的问题也没有太大关系。 If this is obvious I am very sorry.如果这很明显,我很抱歉。 I'm a complete newbie at this.我在这方面完全是新手。 Thanks谢谢

Basically, this error tells you that you are trying to show an empty / non existent image.基本上,此错误告诉您您正在尝试显示/不存在的图像。 Please do check:请检查:

  • The path : I think the problem comes from cv2.imread() .路径:我认为问题来自cv2.imread() If the path is incorrect, the img variable will be empty .如果路径不正确,则img变量将为空

The way you tried to read the image is almost right:您尝试读取图像的方式几乎是正确的:

img = cv2.imread(C:\Users\someone\Documents\python\____The Useless Installer____\PY\colorpic)

The way it should be :它应该是这样的

  • double backslash for escaping the "\" character which has a special meaning in programming languages escaping 的双反斜杠,在编程语言中具有特殊含义的"\"字符
  • you do need to enter the format of the picture ( jpeg , png , etc..).您确实需要输入图片的格式( jpegpng等)。
  • you need to pass this argument as a 'string' or "string"您需要将此参数作为'string'"string"传递

Therefore try img = cv2.imread("C:\\Users\\someone\\Documents\\python\\____The Useless Installer____\\PY\\colorpic.jpg")因此尝试img = cv2.imread("C:\\Users\\someone\\Documents\\python\\____The Useless Installer____\\PY\\colorpic.jpg")


暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 opencv 错误:(-215:断言失败)size.width&gt;0 &amp;&amp; size.height&gt;0 in function 'cv::imshow' - opencv error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow' 相机流 - OpenCV 错误:(-215:断言失败)size.width>0 && size.height>0 in function 'cv::imshow' - Camera Streaming - OpenCV error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow' 错误:(-215:断言失败)函数 cv::imshow 中的 size.width&gt;0 &amp;&amp; size.height&gt;0 - error: (-215:Assertion failed) size.width>0 && size.height>0 in function cv::imshow OpenCV 错误:(-215:断言失败)size.width>0 && size.height>0 in function 'imshow' - OpenCV error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow' 错误:(-215:断言失败)函数“imshow”中的 size.width&gt;0 &amp;&amp; size.height&gt;0 - error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow' OpenCV错误:在cv :: imshow(Python)中断言失败(size.width&gt; 0 &amp;&amp; size.height&gt; 0) - OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow (Python) 错误:函数imshow中的(-215)size.width&gt; 0 &amp;&amp; size.height&gt; 0 - error: (-215) size.width>0 && size.height>0 in function imshow OpenCV 错误:(-215)size.width&gt;0 &amp;&amp; size.height&gt;0 in function imshow - OpenCV Error: (-215)size.width>0 && size.height>0 in function imshow OpenCV错误:在imshow中断言失败(size.width&gt; 0 &amp;&amp; size.height&gt; 0) - OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow 错误:.. \\ .. \\ .. \\ opencv-2.4.8 \\ modules \\ highgui \\ src \\ window.cpp:269:错误:(-215)size.width&gt; 0 &amp;&amp; size.height&gt; 0在函数cv中: :imshow - error: ..\..\..\opencv-2.4.8\modules\highgui\src\window.cpp:269: error: (-215) size.width>0 && size.height>0 in function cv::imshow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM