当前位置:网站首页>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
边栏推荐
- It's time to end bertology
- Adobe Lightroom /Lr 2021软件安装包(附安装教程)
- graph generation model
- The most hard core of the whole network explains the computer startup process
- Principles of websocket + probuf
- Reflection on a case of bus card being stolen and swiped
- Huawei HCIA notes
- PHP security: the past and present of variables
- 技术总监7年自述——如何选择一家好公司
- 工作1-3年的程序员,应该具备怎么样的技术能力?该如何提升?
猜你喜欢

编程界大佬教你:一行Python代码能做出哪些神奇的事情?

一万四千字分布式事务原理解析,全部掌握你还怕面试被问?

Summary of the resumption of a 618 promotion project

盘点那些争议最大的编程观点,你是什么看法呢?

A detailed explanation of microservice architecture

Count the frequency of letters in text (case insensitive)

如何高效的学习技术

How to choose a good company

看一遍就理解,图解单链表反转

浅谈HiZ-buffer
随机推荐
Exception calling 'downloadstring' with '1' arguments: 'operation timed out'
Deep into web workers (1)
编程界大佬教你:一行Python代码能做出哪些神奇的事情?
Advanced concurrent programming series 9 (lock interface analysis)
Don't treat exceptions as business logic, which you can't afford
Dynamic programming -- state compression DP of set represented by binary
微服务的出现和意义的探索
关于update操作并发问题
使用“1”个参数调用“DownloadString”时发生异常:“操作超时”
Git code submission operation, and git push prompt failed to push some refs'xxx '
Thinkphp6中where条件中字段与字段比较条件的写法
AFO记
在pandas中使用pipe()提升代码可读性
[C + + learning notes] how about the simple use of the C + + standard library STD:: thread?
Business Facade 与 Business Rule
利用线程通信、解决缓存穿透数据库雪崩
Huawei HCIA notes
Analysis of kubernetes service types: from concept to practice
Vscode configuration
【C++学习笔记】C++ 标准库 std::thread 的简单使用,一文搞定还不简单?