错误(-215)size.width> 0&&尝试使用OpenCV显示图像时发生size.height> 0 [英] Error (-215) size.width>0 && size.height>0 occurred when attempting to display an image using OpenCV

查看:150
本文介绍了错误(-215)size.width> 0&&尝试使用OpenCV显示图像时发生size.height> 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个简单的程序,该程序从OpenCV读取图像.但是,我收到此错误:

I am trying to run a simple program that reads an image from OpenCV. However, I am getting this error:

error: ......\modules\highgui\src\window.cpp:281: error: (-215) size.width>0 && size.height>0 in function cv::imshow

知道这个错误是什么意思吗?

Any idea what this error means?

这是我的代码:

from matplotlib import pyplot as plt
import numpy as np
import cv2

img = cv2.imread('C:\\Utilisateurs\\Zeineb\\Bureau\\image.jpg',0)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

推荐答案

错误:(-215)"表示断言失败.在这种情况下,cv :: imshow断言给定的图像是非空的:

"error: (-215)" means that an assertion failed. In this case, cv::imshow asserts that the given image is non-empty: https://github.com/opencv/opencv/blob/b0209ad7f742ecc22de2944cd12c2c9fed036f2f/modules/highgui/src/window.cpp#L281

图片入门 OpenCV Python教程,如果该文件不存在,则cv2.imread()将返回None;它不会引发异常.

As noted in the Getting Started with Images OpenCV Python tutorial, if the file does not exist, then cv2.imread() will return None; it does not raise an exception.

因此,以下代码也导致(-215)size.width> 0&& size.height> 0"错误:

Thus, the following code also results in the "(-215) size.width>0 && size.height>0" error:

img = cv2.imread('no-such-file.jpg', 0)
cv2.imshow('image', img)

检查以确保文件实际存在于指定路径中.如果是这样,则可能是该图像已损坏,或者是空图像.

Check to make sure that the file actually exists at the specified path. If it does, it might be that the image is corrupted, or is an empty image.

这篇关于错误(-215)size.width> 0&&尝试使用OpenCV显示图像时发生size.height> 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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