Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
927 views
in Technique[技术] by (71.8m points)

python - Error (-215) size.width>0 && size.height>0 occurred when attempting to display an image using OpenCV

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

error: ......moduleshighguisrcwindow.cpp:281: error: (-215) size.width>0 && size.height>0 in function cv::imshow

Any idea what this error means?

Here is my code:

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()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

"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

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...