Как получить текст с изображения python в Ubuntu - PullRequest
0 голосов
/ 03 февраля 2020

Я хочу прочитать текст с изображения и использую pytesseract в Python. Когда я запускаю код:

`   


        # Recognize the text as string in image using pytesserct 
        text.append(str(pytesseract.image_to_string(Image.open(imagefilename), encoding='utf-8', errors="Error")))
         #Finally, write the processed text to the file. 
    f.write(" ".join(text)) 

    # Close the file after writing all the text. 
    f.close()
    break`

, это ошибка:

    File "/home/doc/desktop/lettura_pdf.py", line 87, in <module>
    text.append(str(pytesseract.image_to_string(Image.open(imagefilename), encoding='utf-8', errors="Error")))
TypeError: image_to_string() got an unexpected keyword argument 'encoding'

1 Ответ

0 голосов
/ 03 февраля 2020

Здесь:

   f = open(txtfile, "w") 
    text = []
    # Iterate from 1 to total number of pages 
    for i in range(1, filelimit + 1): 

        # Set filename to recognize text from 
        # Again, these files will be: 
        # page_1.jpg 
        # page_2.jpg 
        # .... 
        # page_n.jpg 
        imagefilename = folder+"/page_"+str(i)+".jpg"

        # Recognize the text as string in image using pytesserct 
        text.append(str(pytesseract.image_to_string(Image.open(imagefilename)),encoding='utf-8',errors="Error"))
         #Finally, write the processed text to the file. 
    f.write(" ".join(text)) 

    # Close the file after writing all the text. 
    f.close()
    break
...