环境:MacOS 10.14.6 python3.10。上一篇已经安装了python3.10。
本篇目标是从图片中提取文字:建立文件convertp2t.py。
from PIL import Image
import pytesseract
import os
import pdb
image_address = input(r'请输入图片地址:')
if not os.path.exists(r'{}'.format(image_address)):
print(r'{} no exist'.format(image_address))
print(r'file name:{}'.format(image_address));
image = Image.open(r'{}'.format(image_address), 'r') #打开图片
#pdb.set_trace()
text = pytesseract.image_to_string(image, lang='chi_sim') #图片转文字
print(text) #打印结果
开始调试之路。
先后报错:
tesseract is not installed or it's not in your path
pytesseract.pytesseract.TesseractError: (2, 'Usage: pytesseract [-l lang] in
需要安装tesseract,用pip3 install tesseract,还不行。
修改/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytesseract/pytesseract.py,