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

前端 未结 10 1130
失恋的感觉
失恋的感觉 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 12:51

    I solve it by using this code

        os.chdir(f"{folder_path}")
    
    0 讨论(0)
  • 2020-11-30 12:52

    This problem happened to me when i just failed to write the extension of the image.
    Please check if you forgot to write the extension or any other part of the full path to the image.

    Remember, extension is required whether you are printing image using OpenCV or Mathplotlib.

    0 讨论(0)
  • 2020-11-30 12:54

    While reading the image file, specifying the color option should solve this, for example:

    image=cv2.imread('img.jpg',cv2.IMREAD_COLOR)
    

    adding the cv2.IMREAD_COLOR should solve this

    0 讨论(0)
  • 2020-11-30 13:00

    While using Raspbian in Rpi 3 I had the same problem when trying to read qrcodes. The error is because cv2 was not able to read the image. If using png image install pypng module.

    sudo pip install pypng
    
    0 讨论(0)
  • 2020-11-30 13:04

    it's the path which is causing the problem, i had the same problem but when i gave the full path of the image it was working perfectly.

    0 讨论(0)
  • 2020-11-30 13:05

    Use r in the code where you specified the file address.
    For Example:

    import cv2
    img = cv2.imread(r'D:\Study\Git\OpenCV\resources\lena.png')
    cv2.imshow('output', img)
    cv2.waitKey(0)
    

    r stands for "raw" and will cause backslashes in the string to be interpreted as actual backslashes rather than special characters.

    0 讨论(0)
提交回复
热议问题