[Python] python pytesseract.image_to_string can't read text in image

Discussão em 'Python' iniciado por Stack, Julho 15, 2025.

  1. Stack

    Stack Membro Participativo

    I am using python3.7 and Tesseract-OCR version 5 on my Windows 10 box. I have pictures containing the numbers. However, despite that it is super clear to the human eyes, the Tesseract can't extract them correctly. Some give me a couple of correct readings. Some don't return anything at all. The attached one is the extreme case that nothing is returned...

    text = pytesseract.image_to_string(n)
    print(text) -> returns nothing


    I read that I must change the DPI to 300 for Tesseract to read it correctly. Could you show me the best way to do it? I googled but I couldn't find a straight forward way to do it. Thanks!

    Input image

    [​IMG]


    Hi Nathancy, here is the "unsupported image object" error I got when I run the pytesseract command

    >>> data = pytesseract.image_to_string(thresh, lang='eng', config='--psm 6')
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:\Python37\lib\site-packages\pytesseract\pytesseract.py", line 309, in image_to_string
    }[output_type]()
    File "C:\Python37\lib\site-packages\pytesseract\pytesseract.py", line 308, in <lambda>
    Output.STRING: lambda: run_and_get_output(*args),
    File "C:\Python37\lib\site-packages\pytesseract\pytesseract.py", line 208, in run_and_get_output
    temp_name, input_filename = save_image(image)
    File "C:\Python37\lib\site-packages\pytesseract\pytesseract.py", line 121, in save_image
    image = prepare(image)
    File "C:\Python37\lib\site-packages\pytesseract\pytesseract.py", line 113, in prepare
    raise TypeError('Unsupported image object')
    TypeError: Unsupported image object

    Continue reading...

Compartilhe esta Página