OpenCV(4.2.0) 错误:(-215:Assertion failed) 函数 'cv::imshow' 中的 size.width>0 && size.height>0

关于

我一直收到这个错误。我已经从这个网站复制了代码并进行了更改,以便代码实际工作。代码:

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)
    [...]

完整的回溯:

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'

我已经看过herehere,但我不明白如何解决这个问题,我认为它也与我的问题没有太大关系。如果这很明显,我很抱歉。我是一个完全的新手。谢谢

Cătălina Sîrbu

基本上,这个错误告诉你你正在尝试显示一个空的/不存在的图像。请检查:

  • 路径:我认为问题来自cv2.imread(). 如果路径不正确,img变量将为空

您尝试读取图像的方式几乎是正确的:

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

它应该是这样的

  • 双反斜杠用于转义"\"在编程语言中具有特殊含义字符
  • 你需要进入图片(格式jpegpng等..)。
  • 您需要将此参数作为'string'"string"

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


本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在视频中显示裁剪的帧部分:函数cv :: imshow中错误(-215)size.width> 0 && size.height> 0

cv2.error: (-215) size.width>0 && size.height>0 in function imshow

cv2.error : OPENCV(4.4.0) ERROR(-215 断言失败) size.height>0 && size,width>0)

OpenCV错误:断言失败(size.width> 0 && size.height> 0)简单代码

OpenCV错误:断言失败(size.width> 0 && size.height> 0)python

复制图像后在imshow中断言失败(size.width> 0 && size.height> 0)

断言失败(size.width> 0 && size.height> 0)

DolphinDB中的size(SharedPartitionedTable)= 0

myvector.size() 在唯一的函数中返回 0

Emgu CV ArucoInvoke.InterpolateCornersCharuco 给出错误“Emgu.CV.Util.CvException: 'OpenCV: 0 <= i && i < (int)vv.size()'”

swift UIPrintPageRenderer printableRect.size.width 始终为零 (0)

向量返回的 size() 为 0

模型错误:ASSERT:条件(intersectAt.size()%2)== 0 false函数计算衰减,静脉/模块/障碍物/Obstacle.cc

当我使用 pytorch 时,出现错误:"" IndexError: index 4 is out of bounds for axis 0 with size 4 ""

适配器的 onBindView 给出错误:java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

c-*(void **)&(int [2]){0,PAGE_SIZE}; 含义?

'index 0 is out of bounds for axis 0 with size 0'是什么意思,我该如何解决这个错误?

shell“测试”命令中的“ -size +0”是什么意思

为什么单选按钮的size()在硒中显示为0?

如何在scala中跳过size = 0的$ EmptyMap的值

在本地响应中获取java.lang.IndexOutOfBoundsException:Index:0,Size:0

为什么`font-size:0`会以某种方式影响`line-height`

删除R中的空文件:if(!file.size(x)== 0){时错误:需要TRUE / FALSE的缺少值

C ++中的'grid.size()'和'grid [0] .size()'有什么区别

Qt QFile :: size()始终返回0

if(listStr.size == 0){与if(listStr.isEmpty()){

带有Set <String> size()== 0的NullPointerException

has_many.size大于0的Rails?

vector.size()始终返回0