Problem in loading the image.. [closed]

asked 2017-12-16 07:22:15 -0600

KRK gravatar image

updated 2017-12-16 07:25:18 -0600

berak gravatar image

import numpy as np import cv2

img = cv2.imread("mud.jpeg",cv2.IMREAD_COLOR)

cv2.imshow("bhatnagar",img) cv2.waitKey(5)

This is the error I am getting: I have even tried by giving the path of the image which could also be done if in case the file is not in the working directory.

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp, line 325

cv2.imshow("bhatnagar",img) cv2.error: C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:325: error: (-215) size.width>0 && size.height>0 in function cv::imshow

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by berak
close date 2017-12-18 02:23:16.526499

Comments

it did not find the image, or it is not a jpg, but a mislabelled gif.

anyway, you have to check if image!=None: before proceeding with imshow() or the like.

berak gravatar imageberak ( 2017-12-16 07:28:14 -0600 )edit

Thanks a lot..done...

KRK gravatar imageKRK ( 2017-12-16 07:36:10 -0600 )edit

what if i am reading from the webcam?

lucifer97 gravatar imagelucifer97 ( 2019-02-03 13:31:33 -0600 )edit

@lucifer97, the problem is simply, that python ppl NEVER check the outcome of imread() or cap.read() so, if something goes wrong there, it errors in the NEXT line, because of an invalid image.

so, same for the webcam: CHECK !

berak gravatar imageberak ( 2019-02-03 14:02:32 -0600 )edit