我正在编写一个 python 脚本来使用 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'
您能否指出我在这里所做的错误。