Assertion failure : size.width>0 && size.height>0 in function imshow

前端 未结 10 1282
失恋的感觉
失恋的感觉 2020-11-30 12:19

i am using opencv2 and python on raspberry pi. and i am new with python and opencv. i tried to read a jpeg image and display image it shows the following error:

<         


        
10条回答
  •  野性不改
    2020-11-30 13:12

    In my case, I had forgotten to change the working directory of my terminal to that of my code+testImage. Hence, it failed to find the image there.

    Finally, this is what worked for me:

    I saved the image and Python file on Desktop. I changed my cmd directory to it,

    cd Desktop
    

    And then checked for my file:

    ls
    

    And this was my code that worked:

    import cv2
    import numpy as np
    
    im = cv2.imread('unnamed.jpg')
    #Display the image
    cv2.imshow('im',im)
    cv2.waitKey(2000) #Milliseconds
    

提交回复
热议问题