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

后端 未结 11 2582
渐次进展
渐次进展 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 15:57

    This error occurs when you are trying to show an empty image. The image was probably not loaded correctly and could be due to a non-existent image, incorrect file path, or incorrect file extension when using cv2.imread(). You can check if the image was loaded properly by printing out its shape

    image = cv2.imread('picture.png')
    print(image.shape)
    

    You will get something like this which returns a tuple of the number of rows, columns, and channels

    (400, 391, 3)

    If OpenCV was unable to load the image, it will throw this error when trying to print the shape

    AttributeError: 'NoneType' object has no attribute 'shape'

提交回复
热议问题