Fixing error when displaying an image using OpenCV – Error (-215) size.width>0 && size.height>0

error when displaying an image using OpenCV – Error (-215) size.width>0 && size.height>0 is an error which occurs when the image you are trying to work with is corrupted or empty.

Today I try to explain why this error takes place and how to solve it, I will also add other solutions that could solve the error if possible.

Exploring error when displaying an image using OpenCV – Error (-215) size.width>0 && size.height>0

This is an error which occurs when the image you are trying to work with is missing, corrupted or empty.

You should avoid mixing between different errors. The error message should look like the error message bellow.

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

Bellow I will present multiple solutions some have worked for me and others have worked for other developers.

Solution : Make sure to clear all the damage or mistakes made regarding the image

As I explained in the start of this blog post. When you get this error, this usually means the image you are trying to work with is either missing, empty or completely corrupted.

With the code bellow, if emma.jpg is corrupted, missing or empty we will get the same error we are discussing in this article.

                                                                       #
myimg = cv2.imread('emma.jpg', 0)
cv2.imshow('image', myimg)
                                                                       #

To get rid of the error, just make sure that the image lives in the same directory as the .py script, if you specified the exact path, then make sure the image is really located where you said it is.

Also another big possibility is that the name of the image is wrong. You need to make sure all these possible mistakes are repaired before you try importing and working with the image.

The solutions above should be enough to solve the problem, if you like our effort make sure to consider donating to our Kofi account, there is a red button that you can use if you are feeling generous.

Summing-up

I hope you found a solution in our article, keep creating and keep coding, cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/