Home why cv2.imshow() results in error in my python compiler?

# why cv2.imshow() results in error in my python compiler?

praveen
1#
praveen Published in 2014-04-03 06:10:03Z
 Hi friends i just now installed opencv and checking the basic code but it results in error. The code is import numpy as np import cv2 img=cv2.imread('C:\Users\Pravin\Desktop\a.jpeg',1) cv2.namedWindow('img',cv2.WINDOW_NORMAL) cv2.Waitkey(10000) cv2.imshow('cv2.WINDOW_NORMAL',img) cv2.destoryAllWindows()  The error for cv2.imshow() is Traceback (most recent call last): File "", line 1, in cv2.imshow('image',img) error: ..\..\..\src\opencv\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0  It was very helpful to me with your answer. Thanks in advance
Sergei Nosov
2#
Sergei Nosov Reply to 2014-04-03 06:34:28Z
 Most likely, the imread call didn't succeed. Make sure the image "C:\Users\Pravin\Desktop\a.jpeg" exists. (The extension .jpeg seems unusual, maybe it has to be .jpg?) Also, as Hyperboreus suggests, please, try using forward slashes in the filename "C:/Users/Pravin/Desktop/a.jpg", or escape backslashes "C:\\Users\\Pravin\\Desktop\\a.jpg" 
Pranav Totla
3#
Pranav Totla Reply to 2015-08-09 01:36:20Z
 The error says that the image you opened doesn't satisfy the condition height > 0 and width > 0. This may have several reasons. Most of the times, it is due to an inexistent image address given in imread. Sometimes it may be also because the complier failed to load the image. For example, if you write some random strings in notepad and save the file as a.jpg, the compiler may not be able to load it.
Vikas Gautam
4#
Vikas Gautam Reply to 2017-09-15 19:52:24Z
 For me it worked when i just changed jpeg to jpg Try this, may be it will work import numpy as np import cv2 img=cv2.imread('C:\Users\Pravin\Desktop\a.jpg',1) #changed image format to jpg cv2.namedWindow('img',cv2.WINDOW_NORMAL) cv2.Waitkey(10000) cv2.imshow('cv2.WINDOW_NORMAL',img) cv2.destoryAllWindows() 
M Sudhakar
5#
M Sudhakar Reply to 2017-05-17 04:39:33Z
 It is because, python compiler cannot find the image in the place. if you copy the image in the python working directory and do this. it worked for me. # keep image in the current working directory img=cv2.imread('roi.jpg',1) cv2.imshow('image',img)
Tonechas
6#
 Try this... import numpy as np import cv2 img = cv2.imread('E:/Images/ece/1.png',1) cv2.imshow('image',img) cv2.waitKey(0) cv2.destroyAllWindows()