(-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

前端 未结 5 817
逝去的感伤
逝去的感伤 2020-12-19 00:54

I am trying to recognize text from an image to then have the text outputted; however, this error spits out:

Traceback (most recent call last):

相关标签:
5条回答
  • 2020-12-19 01:04

    if path and image name is verified and correct then just close the jupyter notebook (or whatever platform you are using) and restart it. It worked for me.

    0 讨论(0)
  • 2020-12-19 01:07

    This means you are passing a Uninitialized variable to

    > cv2.cvtColor()
    

    After this statement:

    # Read image with opencv
    img = cv2.imread(img_path)
    

    Can you try to print the img variable before passing to cv2.cvtColor() function

    > print(img) or print(img.shape)
    

    to make sure function call to read the image is successful

    0 讨论(0)
  • 2020-12-19 01:09

    This error occurs when the image is in one format and in the python program you specify other format.

    Example:

    File Path= /home/user/image.jpg
    

    but in the python program you read the image as jpeg

    img = cv.imread("image.jpeg")
    

    Then you will be facing this error

    0 讨论(0)
  • 2020-12-19 01:15

    I think your source path should be:

    src_path = "C:/Users/Benji's Beast/Desktop/"
    

    Because in here get_string(src_path + "cont.jpg") you've concatenated the image name.

    0 讨论(0)
  • 2020-12-19 01:19

    The problems are this one

    src_path = "C:/Users/Benji's Beast/Desktop/image.PNG"
    

    and this one

    print(get_string(src_path + "cont.jpg") )
    

    You are appending the image input file name from image.PNG to image.PNG.cont.jpg

    If your input image filename is cont.jpg and it is located on your Desktop, then try to replace your code with :

    src_path = "C:\Users\Benji's Beast\Desktop\"
    

    and

    print(get_string(src_path + "cont.jpg") )
    
    0 讨论(0)
提交回复
热议问题