当前位置:网站首页>Python 图片识别 OCR
Python 图片识别 OCR
2020-11-07 20:56:00 【Coxhuang】
文章目录
- Python 图片识别 OCR
- #1 需求
- #2 环境
- #3 安装
- #3.1 macOS
- #3.2 Linux(CentOS)
- #4 使用
- #4.1 python安装pytesseract库
- #4.2 Python代码
- #5 在线案例
Python 图片识别 OCR
#1 需求
- 识别图片中的信息,如二维码
#2 环境
macOS / Linux Python3.7.6
#3 安装
#3.1 macOS
- 安装 tesseract
//只安装tesseract,不安装训练工具 brew install tesseract //安装tesseract的同时安装训练工具 brew install --with-training-tools tesseract //安装tesseract的同时安装所有语言,语言包比较大,如果安装的话时间较长,建议不安装,按需选择 brew install --all-languages tesseract //安装tesseract,并安装训练工具和语言 brew install --all-languages --with-training-tools tesseract
2. 下载语言包
地址 : https://github.com/tesseract-ocr/tessdata
我这里安装的是中文语言包
中文语言包 : https://github.com/tesseract-ocr/tessdata/blob/master/chi_sim.traineddata
然后将下载的中文语言包拷贝到如下路径 :
/usr/local/Cellar/tesseract/4.0.0_1/share/tessdata
3. 查看本地语言包
tesseract --list-langs
#3.2 Linux(CentOS)
- 安装依赖
yum install autoconf automake libtool libjpeg-devel libpng-devel libtiff-devel zlib-devel
2. 安装 leptonica
下载 : wget https://github.com/tesseract-ocr/tesseract/archive/4.1.0.tar.gz
解压安装
tar -xzvf leptonica-1.74.4.tar.gz cd leptonica-1.74.4.tar.gz ./configure --profix=/usr/local/leptonica make sudo make install
3. 安装 tesseract-ocr
wget https://github.com/tesseract-ocr/tesseract/archive/3.04.zip unzip 3.04.zip cd tesseract-3.04/ ./configure make && make install sudo ldconfig
我这里安装的是中文语言包
中文语言包 : https://github.com/tesseract-ocr/tessdata/blob/master/chi_sim.traineddata
然后将下载的中文语言包拷贝到如下路径 :
/usr/local/share/tessdata
#4 使用
#4.1 python安装pytesseract库
pip install pytesseract pip install Pillow
#4.2 Python代码
from PIL import Image import pytesseract # 指定图片路径和识别的语言 data = pytesseract.image_to_string(Image.open('/Users/Documents/1.png'), lang='chi_sim') print(data)
#5 在线案例
地址 :
本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。
版权声明
本文为[Coxhuang]所创,转载请带上原文链接,感谢
https://cloud.tencent.com/developer/article/1744581
边栏推荐
- How to deal with data leakage and deletion related to business life and death?
- 使用 Xunit.DependencyInjection 改造测试项目
- Let's talk about the locks in the database
- 想要忘记以前连接到Mac的WiFi网络,试试这个方法!
- 技术债务是对业务功能缺乏真正的理解 -daverupert.com
- Using thread communication to solve the problem of cache penetrating database avalanche
- GrowingIO 响应式编程探索和实践
- PHP security: the past and present of variables
- 全网最硬核讲解计算机启动流程
- Principles of websocket + probuf
猜你喜欢
随机推荐
Code Review最佳实践
sed之查找替换
AFO
快速上手Git
DOM node operation
Adobe Lightroom /Lr 2021软件安装包(附安装教程)
Reflection on a case of bus card being stolen and swiped
Technical debt is a lack of real understanding of business functions- daverupert.com
如何高效的学习技术
Using thread communication to solve the problem of cache penetrating database avalanche
Vscode configuration
How did I lose control of the team?
How to deal with data leakage and deletion related to business life and death?
计组-总线通信控制之异步串行通信的数据传输
高级并发编程系列九(Lock接口分析)
Practice of Xiaoxiong school development board: real equipment access of smart street lamp sandbox experiment
The JS solution cannot be executed after Ajax loads HTML
Git code submission operation, and git push prompt failed to push some refs'xxx '
bgfx编译教程
工作1-3年的程序员,应该具备怎么样的技术能力?该如何提升?