Error (-215) size.width>0 && size.height>0 occurred when attempting to display an image using OpenCV

后端 未结 11 2591
渐次进展
渐次进展 2020-11-28 15:37

I am trying to run a simple program that reads an image from OpenCV. However, I am getting this error:

error: ......\\modules\\highgui\\src\\window.cpp:281:          


        
11条回答
  •  囚心锁ツ
    2020-11-28 16:18

    "error: (-215)" means that an assertion failed. In this case, cv::imshow asserts that the given image is non-empty: https://github.com/opencv/opencv/blob/b0209ad7f742ecc22de2944cd12c2c9fed036f2f/modules/highgui/src/window.cpp#L281

    As noted in the Getting Started with Images OpenCV Python tutorial, if the file does not exist, then cv2.imread() will return None; it does not raise an exception.

    Thus, the following code also results in the "(-215) size.width>0 && size.height>0" error:

    img = cv2.imread('no-such-file.jpg', 0)
    cv2.imshow('image', img)
    

    Check to make sure that the file actually exists at the specified path. If it does, it might be that the image is corrupted, or is an empty image.

提交回复
热议问题