安装依赖
sudo apt-get install g++ autoconf automake libtool autoconf-archive pkg-config libpng-dev libjpeg8-dev libtiff5-dev zlib1g-dev
————————————————
版权声明:本文为CSDN博主「huanghuangyuni」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/huanghuangyuni/article/details/78766508
安装Leptonica
sudo apt-get install libleptonica-dev
安装tesseract
sudo apt-get install tesseract-ocr
安装pytesseract
pip install pytesseract
启动python,新建文件夹输入以下代码
#!/usr/bin/env python
from PIL import Image
import pytesseract
text=Image.open('/home/pi/Downloads/test.png')
#print(text)
print(pytesseract.image_to_string(text))
————————————————
版权声明:本文为CSDN博主「huanghuangyuni」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/huanghuangyuni/article/details/78766508
保存并运行
保存测试图片 /home/pi/Downloads/test.png
ocr-en.png运行
l@l:~/src/wx-play/ocr$ vim ocr-test.py
l@l:~/src/wx-play/ocr$ python3 ocr-test.py
This is a lot of 12 point text to test the
ocr code and see if it works on all types
of file format.
The quick brown dog jumped over the
lazy fox. The quick brown dog jumped
over the lazy fox. The quick brown dog
jumped over the lazy fox. The quick
brown dog jumped over the lazy fox.
中文识别
要识别中文,需要先下载中文语言包chi_sim.traineddata放到树莓派的:/usr/share/tesseract-ocr/tessdata文件夹下,
之后我们将
words = image_to_string(pil_im,"eng").strip()
替换为:
words = image_to_string(pil_im,"chi_sim").strip()
网友评论