编程语言
首页 > 编程语言> > python数字识别

python数字识别

作者:互联网

首先:安装依赖包PIL

pip install pillow

pip3 install pillow

接着:安装tesseract

pip install tesseract

pip3 install tesseract

或者:安装pytesseract

pip install pytesseract

pip3 install pytesseract

最后:安装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

结果没有问题

 

标签:tesseract,数字,python,image,pytesseract,code,install,pip,识别
来源: https://www.cnblogs.com/guochaoxxl/p/15519132.html