python二维码识别tesseract

window安装tesseract

下载路径:
https://digi.bib.uni-mannheim.de/tesseract/
选择

双击安装在D:\sore\teeseract-OCR后:
python二维码识别tesseract_第1张图片

配置环境变量

配置环境变量Path:D:\sore\teeseract-OCR
配置语言包的环境变量TESSDATA_PREFIX: D:\sore\teeseract-OCR\tessdata
tess4j.jar启动会去该目录下加载语言包
验证是否安装成功,重新打开cmd:

tesseract.exe -v
# 识别英文
tesseract image.png stdout -l eng
# 识别中文
tesseract image.png stdout -l chi_sim

安装tesserocr和pytesseract包

pip install C:\Users\EDY\Downloads\tesserocr-2.6.0-cp311-cp311-win_amd64.whl
pip install -i https://mirrors.aliyun.com/pypi/simple/ pytesseract

import pytesseract
from PIL import Image
# 
pytesseract.pytesseract.tesseract_cmd=r'D:\\sore\\teeseract-OCR\\tesseract.exe'
image=Image.open('E:\\note\\python-project\\python-project-git\\lianxi\\static\\aa.png')#所要识别的图片的位置
#默认是英文,如果是英文就不需更改
text=pytesseract.image_to_string(image)
#默认是英文,如果是中文,要将语言改成中文。
# text=pytesseract.image_to_string(image,lang='chi_sim')
print(text)

你可能感兴趣的:(python,python,开发语言)