0
我正在編寫一個python腳本以使用pytesseract從文件中提取圖像。但是當我運行腳本時,我得到了下面的錯誤。無法使用pytesseract從圖像中提取文本
from PIL import Image
from pytesseract import image_to_string
import os
tessdata_dir_config = '--tessdata-dir "C:\\Ranit\\Personal\\PycharmProjects\\modlog\\pdfs\\"'
tgtfile = "C:\Ranit\Personal\PycharmProjects\modlog\pdfs\IMG_20170331_194534.jpg"
if os.path.isfile(tgtfile):
imgtxt = image_to_string(image='IMG_20170331_194534.jpg',config=tessdata_dir_config)
print(imgtxt)
else:
print('File not found')
錯誤接收:
C:\Python36\python.exe C:/Ranit/Personal/PycharmProjects/modlog/extracttext.py
Traceback (most recent call last):
File "C:/Ranit/Personal/PycharmProjects/modlog/extracttext.py", line 10, in <module>
imgtxt = image_to_string(image='IMG_20170331_194534.jpg',config=tessdata_dir_config)
File "C:\Python36\lib\site-packages\pytesseract\pytesseract.py", line 117, in image_to_string
image.save(input_file_name)
AttributeError: 'str' object has no attribute 'save'
可否請你指出我,我在這裏做了錯誤。