Python实现识别图片内容的方法分析
作者:CyborgLin 时间:2022-01-04 21:10:51
本文实例讲述了Python实现识别图片内容的方法。分享给大家供大家参考,具体如下:
python识别图片内容。
这里我的环境为windows64位,python2.7.14
需要用到PIL模块和tesseract模块。
首先需要安装pip包管理,安装方法可参考附录windows下安装python包管理器pip
安装PIL模块:
pip install Pillow
tesseract模块安装:
pip install pytesseract
安装识别引擎和中文语言包,点击此处本站下载。
下载完成解压:
1.双击tesseract-ocr-setup-3.02.02.exe安装,安装完成后,需要指定tesseract模块识别引擎的程序路径,打开python安装路径的模块路径,我的路径为:E:\wamp\python\Lib\site-packages\,进入pytesseract,编辑pytesseract.py文件,修改 tesseract_cmd = 'tesseract'
的内容:
# tesseract_cmd = 'tesseract' # 修改为安装Tesseract-OCR的真实路径
tesseract_cmd = 'E:/wamp/python modules/Tesseract-OCR/tesseract.exe'
2.进入解压包中的中文语言包,复制chi_sim.traineddata到Tesseract-OCR安装目录下tessdata文件夹下,我的路径:E:\wamp\python modules\Tesseract-OCR\tessdata\chi_sim.traineddata
环境配置完成。
python代码:
# -*- coding: UTF-8 -*-
from PIL import Image
import pytesseract
# 识别中文
text = pytesseract.image_to_string(Image.open('chinese.png'),lang='chi_sim')
print text
# 识别英文
text = pytesseract.image_to_string(Image.open('english.png'))
print text
附:windows下安装python包管理器pip
windows下安装python包管理器pip。
pip下载地址:https://pypi.python.org/pypi/pip#downloads
选择 pip-9.0.1.tar.gz (md5, pgp)
下载完成解压,这里我解压到D:\python\pip-9.0.1,命令行进入D:\python\pip-9.0.1
cd D:\python\pip-9.0.1
安装pip
python setup.py install
安装完成,输入pip list
查看是否成功
pip list
显示下面信息代表安装成功:
pip (9.0.1)
setuptools (28.8.0)
pip安装模块命令:
pip install xxx
希望本文所述对大家Python程序设计有所帮助。
来源:https://blog.csdn.net/mxdzchallpp/article/details/79113262
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python 请求服务器的实现代码(http请求和https请求)
opera img onload重复执行
Python装饰器用法与知识点小结
Python面向对象之接口、抽象类与多态详解
Zend Studio去除编辑器的语法警告设置方法
![](https://img.aspxhome.com/file/2023/2/55702_0s.png)
Python socket编程实例详解
Jsp+Servlet实现文件上传下载 删除上传文件(三)
![](https://img.aspxhome.com/file/2023/0/96050_0s.png)
PHP图像处理技术实例总结【绘图、水印、验证码、图像压缩】
![](https://img.aspxhome.com/file/2023/9/55489_0s.png)
Python中DataFrame判断两列数据是否相等的方法
python使用装饰器作日志处理的方法
Python改变对象的字符串显示的方法
javascript创建数组的最简代码
浅谈Python魔法方法
![](https://img.aspxhome.com/file/2023/8/130768_0s.png)
机器学习经典算法-logistic回归代码详解
![](https://img.aspxhome.com/file/2023/4/117914_0s.jpg)
python实现Decorator模式实例代码
python替换字符串中的子串图文步骤
![](https://img.aspxhome.com/file/2023/6/69006_0s.jpg)
Python算法练习之二分查找算法的实现
![](https://img.aspxhome.com/file/2023/8/104388_0s.jpg)
Python 详解通过Scrapy框架实现爬取百度新冠疫情数据流程
![](https://img.aspxhome.com/file/2023/7/77897_0s.png)
windows下python安装pip方法详解
![](https://img.aspxhome.com/file/2023/8/72918_0s.png)
Python数据分析之 Pandas Dataframe应用自定义
![](https://img.aspxhome.com/file/2023/1/97241_0s.png)