当前位置:网站首页>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 learn technology efficiently
- MongoDB下,启动服务时,出现“服务没有响应控制功能”解决方法
- 如何应对事关业务生死的数据泄露和删改?
- 一次公交卡被“盜刷”事件帶來的思考
- 模型预测准确率高达94%!利用机器学习完美解决2000亿美元库存难题
- Analysis of kubernetes service types: from concept to practice
- Summary of the resumption of a 618 promotion project
- 计组-总线通信控制之异步串行通信的数据传输
- Reflection on a case of bus card being stolen and swiped
- 一次公交卡被“盗刷”事件带来的思考
猜你喜欢
laravel8更新之维护模式改进
Kubernetes服务类型浅析:从概念到实践
大数据算法——布隆过滤器
我们为什么需要软件工程——从一个简单的项目进行观察
C language I blog assignment 03
统计文本中字母的频次(不区分大小写)
技术总监7年自述——如何选择一家好公司
构造请求日志分析系统
Annual salary of 900000 programmers is not as good as 3800 civil servants a month? How to choose between stability and high income?
Web API系列(三)统一异常处理
随机推荐
是时候结束 BERTology了
If you want to forget the WiFi network you used to connect to your Mac, try this!
C语言Ⅰ博客作业03
How to think in the way of computer
bgfx编译教程
What magic things can a line of Python code do?
统计文本中字母的频次(不区分大小写)
全网最硬核讲解计算机启动流程
如何高效的学习技术
The JS solution cannot be executed after Ajax loads HTML
Big data algorithm - bloon filter
Huawei HCIA notes
DOM节点操作
不懂数据库索引的底层原理?那是因为你心里没点b树
京淘项目day09
Reflection on a case of bus card being stolen and swiped
How did I lose control of the team?
Awk implements SQL like join operation
C language I blog assignment 03
洞察——风格注意力网络(SANet)在任意风格迁移中的应用