Python3使用 pytesseract 进行图片识别

首先:安装依赖包PIL

pip install pillow

pip3 install pillow

接着:安装tesseract

pip install tesseract

pip3 install tesseract

或者:安装pytesseract

pip install pytesseract

pip3 install pytesseract

最后:安装tesseract-data,  sudo pacman -S tesseract-data 

配置:环境变量

vim ~/.bash_profile

添加如下环境变量,TESSDATA_PREFIX的值根据tesseract的安装路径做调整

export TESSDATA_PREFIX="/usr/share/tessdata"
export PATH=$PATH:$TESSDATA_PREFIX
1
2
使环境变量生效

source ~/.bash_profile
例程:

1 import pytesseract
2 #tesseract_cmd = '/usr/bin/tesseract'
3 pytesseract.pytesseract.tesseract_cmd = '/usr/bin/tesseract'
4 from PIL import Image
5  
6 image = Image.open("/home/nication/python/code.jpg")
7 code = pytesseract.image_to_string(image)
8 print(code)

python testp.py  
6067

结果没有问题

这篇:https://www.jianshu.com/p/eea94034e3be?from=groupmessage 

posted @ 2021-11-07 09:53  叕叒双又  阅读(253)  评论(0编辑  收藏  举报