Reputation: 31
import cv2
import numpy as np
#load color of an image in grayscale
img1 = cv2.imread('Tarun.jpg',0)
cv2.imshow('Hey its me Tarun yellogi',img1)
error: C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:331: error: (-215) size.width>0 && size.height>0 in function cv::imshow
Upvotes: 3
Views: 12150
Reputation: 1
If the image is not in the current directory then you have to mention the absolute path to the image.
Use os
module to make the path work in any other machine instead of hard-coding the absolute path.
But this error message means that imshow()
is not getting the right image to display.
I would check the shape and the values of the image to make sure that the image is not corrupt.
Upvotes: 0
Reputation: 1
I think you can try this in reading the pictures in a loop to prevent the pause by Nonetype error! It helps me in my case(Some jpg files is Nonetype in my case)
if img is None:
continue
Upvotes: 0
Reputation: 3310
os
module to make the path work in any other machine instead of hard-coding the absolute pathimshow()
is not getting the right image to display None
: print(img1.shape)
and print(img1)
cv2.imread()
returns None
Upvotes: 1
Reputation: 910
img1 = cv2.imread('Tarun.jpg',0)
As you know, imread
reads in the specified image. With just the filename, as here, python tries to read the image from the current working directory. If the file does not exist, no error is reported and img1
will have a value of None
.
That this line:
cv2.imshow('Hey its me Tarun yellogi',img1)
returns an error of:
error: C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:331: error: (-215) size.width>0 && size.height>0 in function cv::imshow
means that the image specified in the imshow
command (i.e. img1
) has a width and/or a height of 0. What the error message is saying is that the image in function imshow
must have a size where the width is greater than zero and the height is greater than zero.
You can check the image size with img1.shape
. In this case you will probably get an error message AttributeError: 'NoneType' object has no attribute 'shape'
. You can further check if img1
is None
with img1 == None
. If you get a response of True
then you will know that img1
does not contain image data.
TL;DR
The file 'Tarun.jpg' was not found thus img1 == None
.
Upvotes: 3