opencv python 错误:断言失败(size.width>0&&size.height>0) [英] opencv python error: Assertion failed (size.width>0 && size.height>0)

查看:97
本文介绍了opencv python 错误:断言失败(size.width>0&&size.height>0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行以下代码时遇到错误.

I am getting an error while running the following code.

import cv2
import numpy as np
img = cv2.imread('messi.jpg',0)
img = cv2.line(img,(0,0),(50,50),(255,0,0),5)
cv2.imshow("image",img)
cv2.waitKey(0)
cv2.destroyAllWindows()

错误说:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in unknown function, file ......\src\opencv\modules\highgui\src\window.cpp,第 261 行

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in unknown function, file ......\src\opencv\modules\highgui\src\window.cpp, line 261

回溯(最近一次调用最后一次):

Traceback (most recent call last):

文件F:\Computer Programming\scripts\OpenCv\1.py",第 6 行,在cv2.imshow("图片",img)cv2.error: ......\src\opencv\modules\highgui\src\window.cpp:261: 错误: (-215) size.width>0 &&尺寸.高度>0

File "F:\Computer programming\scripts\OpenCv\1.py", line 6, in cv2.imshow("image",img) cv2.error: ......\src\opencv\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0

如果我删除该行:

img = cv2.line(img,(0,0),(50,50),(255,0,0),5)

脚本有效.

推荐答案

这是因为 cv2.line 返回 None 而您将其分配给您的 img 变量.所以当你到下一行并尝试显示图像时,没有图像可以显示.

Its because cv2.line returns None and you are assigning that to your img variable. So when you get to the next line and try to show the image, there is no image to be shown.

cv2.line(img) 替换 img = cv2.line(img,(0,0),(50,50),(255,0,0),5),(0,0),(50,50),(255,0,0),5)

Replace img = cv2.line(img,(0,0),(50,50),(255,0,0),5) with cv2.line(img,(0,0),(50,50),(255,0,0),5)

在此处阅读有关 cv2.circle 的更多信息.

这篇关于opencv python 错误:断言失败(size.width>0&&size.height>0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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