Assertion error: size.width> 0 && size.height> 0 in imshow function
I am using opencv2 and python on raspberry pi. and i am new to python and opencv. i tried to read a jpeg image and display an image which 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:
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()
source to share
Image is not loading (possibly because you forgot the presenter /
on the way). imread
then returns None. Passing None
in imshow
forces to try to create a window of size 0x0, which fails.
The poor error handling in this cv
is probably due to its rather thin wrapping layer in the C ++ implementation (where returning NULL on error is common practice).
source to share
import cv2 def main (): print (cv2. version ) imgpath = "H: / photos and datasets for computer vision purposes /00000000.png" # by default it gets 1 for the color image value and does balck and white for zero, -1 for alpha transparency mode #img = cv2.imread (imgpath) img1 = cv2.imread (imgpath, 1) img = cv2.imread (imgpath, 0) # cv2.resizeWindow ('lena', 100, 20) # cv2.namedWindow ('lena', cv2.WINDOW_AUTOSIZE) cv2.imshow ('lena', img) cv2.imshow ('kajal', img1) cv2.resizeWindow ('lena', 1000, 2000) # cv2.namedWindow (' lena ', WINDOW_NORMAL)
cv2.waitKey(0)
#cv2.destroyAllWindows()
cv2.destroyWindow('lena')
main()
source to share
One of the reasons for this error is the absence of a file at the specified path. Therefore, it is good practice to check the path like this (if you are on a Linux machine):
ls <path-provided-in-imread-function>
You will receive an error message if the path is incorrect or the file is missing.
source to share