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

后端 未结 11 2580
渐次进展
渐次进展 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条回答
  •  Happy的楠姐
    2020-11-28 16:00

    I got the same error on Windows. However, none of answers helps me. I realised that the issue is single backslash (\) instead of double backslashes (\\) on image path. For the difference, see the link.

    Problematic scenario:

    import cv2
    mypath = "D:\temp\temp.png"
    img = cv2.imread(mypath, 1)
    cv2.imshow('test', img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    
    Traceback (most recent call last):
      File "", line 1, in 
    cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-2b5g8ysb\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
    

    Fixed scenario:

    import cv2
    mypath = "D:\\temp\\temp.png"
    img = cv2.imread(mypath, 1)
    cv2.imshow('test', img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    

    I hope it helps others who have similar experiences.

提交回复
热议问题