错误(-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.