1.安装相应库
pip install pytesseract
pip install pillow

2.下载并安装tesseract-ocr
链接:https://pan.baidu.com/s/113o5fIAe94_7autPI4ANiA
提取码:27uh
安装时下拉选择 Chinese(simple),以便对中文支持

3.安装完成后将tesseract-ocr目录(C:\Tesseract-OCR)设置到环境变量中
4.修改pytesseract.py文件中字段
将tesseract_cmd='tesseract'改成
tesseract_cmd = r'C:\Tesseract-OCR\tesseract.exe'

5.在pycharm中输入下面代码,查看结果吧
import pytesseract
from PIL import Image,ImageEnhance

image = Image.open(r"C:\Users\Administrator\Desktop\hello2.JPG")
enhancer = ImageEnhance.Contrast(image)
image2 = enhancer.enhance(4)
code = pytesseract.image_to_string(image2,lang="chi_sim+eng")
print(code)