当前位置:网站首页>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
边栏推荐
- laravel8更新之维护模式改进
- Web安全(二)---跨域资源共享
- Let's talk about the locks in the database
- Kylin on kubernetes' practice on eBay
- 盘点那些争议最大的编程观点,你是什么看法呢?
- Dynamic programming -- state compression DP of set represented by binary
- 使用“1”个参数调用“DownloadString”时发生异常:“操作超时”
- 洞察——风格注意力网络(SANet)在任意风格迁移中的应用
- 聊聊Go代码覆盖率技术与最佳实践
- [C + + learning notes] how about the simple use of the C + + standard library STD:: thread?
猜你喜欢
Using pipe() to improve code readability in pandas
The samesite problem of cross domain cookie of Chrome browser results in abnormal access to iframe embedded pages
统计文本中字母的频次(不区分大小写)
Vscode configuration
不懂数据库索引的底层原理?那是因为你心里没点b树
The JS solution cannot be executed after Ajax loads HTML
Code Review Best Practices
What should be considered in the promotion plan outside the station?
一万四千字分布式事务原理解析,全部掌握你还怕面试被问?
阿里terway源码分析
随机推荐
Kubernetes服务类型浅析:从概念到实践
京淘项目day09
使用 Xunit.DependencyInjection 改造测试项目
graph generation model
The CPU does this without the memory
Recommend suicide, openai warns: gpt-3 is too risky for medical purposes
30岁后,你还剩下什么?
Don't treat exceptions as business logic, which you can't afford
大数据算法——布隆过滤器
Git code submission operation, and git push prompt failed to push some refs'xxx '
CPU瞒着内存竟干出这种事
AFO
聊聊Go代码覆盖率技术与最佳实践
一次公交卡被“盜刷”事件帶來的思考
关于update操作并发问题
低代码 vs 模型驱动,它们之间到底是什么关系?
想要忘记以前连接到Mac的WiFi网络,试试这个方法!
Ac86u KX Online
Web安全(一)---浏览器同源策略
What is the relationship between low code vs model driven?