zinon
zinon

Reputation: 4664

Python openCV: Cannot show an image

I'm using python opencv and I'm trying to import an image and show it but I get the following error:

import numpy as np
import cv2
img = cv2.imread('messi5.jpg',0)
cv2.imshow('image',img)
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, fi
le C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\highgui\src\
window.cpp, line 271
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cv2.error: C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\high
gui\src\window.cpp:271: error: (-215) size.width>0 && size.height>0 in function

enter image description here

Upvotes: 0

Views: 7084

Answers (2)

S Nagendra
S Nagendra

Reputation: 49

please make sure your image file paths and img_names(existed) should be corrects as well as imread() object results shouldn't be nonetype and then

cv2.imshow('image', img)  
cv2.waitkey(0)

then your image can display

Upvotes: 0

Rahul K P
Rahul K P

Reputation: 16081

In [1]: a = None
In [2]: type(a)
Out[2]: NoneType
In [3]: import cv2
In [4]: img = cv2.imread('messi.jpg',0)
In [5]: type(img)
Out[5]: numpy.ndarray
In [6]: img = cv2.imread('messii.jpg',0)
In [7]: type(img)
Out[7]: NoneType

Here your type of img is NoneType. So,It's problem with the miss spell or not existing of the image. Please check the spelling or existing of file.

Upvotes: 3

Related Questions