Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assertion failure : size.width>0 && size.height>0 in function imshow

i am using opencv2 and python on raspberry pi. and i am new with python and opencv. i tried to read a jpeg image and display image it shows the following error:

/home/pi/opencv-2.4.9/modules/highgui/src/window.cpp:269: \
  error: (-215) size.width>0 &&  size.height>0 in function imshow.

and the code is:

import cv2
# windows to display image
cv2.namedWindow("Image")
# read image
image = cv2.imread('home/pi/bibek/book/test_set/bbb.jpeg')
# show image
cv2.imshow("Image", image)
# exit at closing of window
cv2.waitKey(0)
cv2.destroyAllWindows()
like image 326
Bibek Ghimire Avatar asked Jul 23 '15 11:07

Bibek Ghimire


2 Answers

The image fails to load (probably because you forgot the leading / in the path). imread then returns None. Passing None to imshow causes it to try to create a window of size 0x0, which fails.

The poor error handling in cv probably owes to its quite thin wrapper layer on the C++ implementation (where returning NULL on error is a common practice).

like image 178
Krumelur Avatar answered Sep 22 '22 13:09

Krumelur


it's the path which is causing the problem, i had the same problem but when i gave the full path of the image it was working perfectly.

like image 26
malware_656 Avatar answered Sep 22 '22 13:09

malware_656