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

后端 未结 11 2573
渐次进展
渐次进展 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:03
    import numpy as np
    import cv2
    
    cap = cv2.VideoCapture(0)
    while(True):
        # Capture frame-by-frame
        ret,frame = cap.read()
        cv2.rectangle(frame, (100, 100), (200, 200), [255, 0, 0], 2)
        # Display the resulting frame
        cv2.imshow('frame',frame)
        if cv2.waitKey(25) & 0xFF == ord('q'):
            break
    
    # When everything done, release the capture
    cap.release()
    cv2.destroyAllWindows() 
    

    **If the camera access for devices is OFF, this code gives an error ;kind of this: cv2.imshow('frame',frame) cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:350: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

    So You should turn ON it**
    
    0 讨论(0)
  • 2020-11-28 16:10

    Try Reinstalling the IDE that you use, with the proper python PATH settings.

    0 讨论(0)
  • 2020-11-28 16:14
        img=cv2.imread('testpaper01-01.png')
        cv2.imshow('image',img)
        cv2.waitKey(0)
        cv2.destroyAllWindows()
    

    You have to mention the same format of your image file in the code(eg:-.jpg/.png/.jpeg/.tif etc.) and the directory of the image file must be same as the source code, I also got the same error but I rectified this way

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-28 16:18

    I think it depends on the IDE + path of the image location issues

    1. In python IDLE you can directly run file from same folder where picture is there
    example 
    img = cv2.imread("kang34.jpg", 0)  # direct use 
    
    1. In IntelliJ IDEA you have to give full path of the image where picture is located
    example 
    img = cv2.imread("C:\\Users\\DEBASISH\\AppData\\Local\\Programs\\Python\\Python36\\Projects\\kang34.jpg", 0)  # use proper syntax and full path of image location
    
    0 讨论(0)
提交回复
热议问题