Python编程实现的图片识别功能示例


Posted in Python onAugust 03, 2017

本文实例讲述了Python编程实现的图片识别功能。分享给大家供大家参考,具体如下:

1. 安装PIL,官方没有WIN64位,Pillow替代

pip install Pillow-2.7.0-cp27-none-win_amd64.whl

2. 安装Pytesser

下载pytesser_v0.0.1.zip,解压后复制进Python27\Lib\site-packges\pytesser路径下,无pytesser则新建

在Python27\Lib\site-packges\pytesser中新建一pytesser.pth文件,内容为pytesser

在pytesser内,修改三点

① pytesser.py修改成__init.py__

② 修改pytesser.py

import Image

 改为

from PIL import Image

tesseract_exe_name = 'tesseract' 改为tesseract_exe_name = 'Python27\\Lib\\site-packges\\pytesser\\tesseract' 注意\转义

③ 安装Tesseract

下载Tesseract OCR engine:http://code.google.com/p/tesseract-ocr/ ,

下载后解压,找到tessdata文件夹,用其替换掉pytesser解压后的tessdata文件夹即可。

不过除了测试用验证码之外,其余的系统验证码的识别率很低。

附测试代码

from pytesser import *
from PIL import Image, ImageEnhance
im = Image.open('D:\Python27\Lib\site-packages\pytesser\phototest.tif')
im2 = Image.open(r'D:\Python27\Lib\site-packages\pytesser\fnord.tif','r')
im3 = Image.open(r'F:\PROJECT\python\code\Study_1\src\20170424\cp.jpg','r') #文件读写模式以防报错
#图片处理1::黑白处理
enhancer = ImageEnhance.Contrast(im3)
image2 = enhancer.enhance(5)
image2.show()
print image_to_string(image2)
#图片处理2: 降噪处理
imgry = im3.convert('L')  #灰度处理
#灰度处理基础上二值化处理
threshold = 140
table = []
for i in range(256):
  if i < threshold:
    table.append(0)
  else:
    table.append(1)
out = imgry.point(table, '1')
out.show()
text = image_to_string(out)
if text.isspace() :
  print "FAILE"
else:
  print text
#print text

希望本文所述对大家Python程序设计有所帮助。

Python 相关文章推荐
学习python (2)
Oct 31 Python
python标准日志模块logging的使用方法
Nov 01 Python
python输出当前目录下index.html文件路径的方法
Apr 28 Python
tensorflow学习笔记之简单的神经网络训练和测试
Apr 15 Python
解读python logging模块的使用方法
Apr 17 Python
Python中交换两个元素的实现方法
Jun 29 Python
python算法题 链表反转详解
Jul 02 Python
python实现日志按天分割
Jul 22 Python
python代码实现逻辑回归logistic原理
Aug 07 Python
Cython编译python为so 代码加密示例
Dec 23 Python
mac在matplotlib中显示中文的操作方法
Mar 06 Python
asyncio异步编程之Task对象详解
Mar 13 Python
详解python实现读取邮件数据并下载附件的实例
Aug 03 #Python
详解 Python中LEGB和闭包及装饰器
Aug 03 #Python
Python 爬虫之超链接 url中含有中文出错及解决办法
Aug 03 #Python
python中MethodType方法介绍与使用示例
Aug 03 #Python
初学python的操作难点总结(新手必看篇)
Aug 03 #Python
python 禁止函数修改列表的实现方法
Aug 03 #Python
详解Python函数可变参数定义及其参数传递方式
Aug 02 #Python
You might like
php 表单验证实现代码
2009/03/10 PHP
PHP Parse Error: syntax error, unexpected $end 错误的解决办法
2012/06/05 PHP
PHP中的Memcache详解
2014/04/05 PHP
PHP常用的排序和查找算法
2015/08/06 PHP
php实现登陆模块功能示例
2016/10/20 PHP
PHPstorm激活码2020年5月13日亲测有效
2020/09/17 PHP
javascript拖拽上传类库DropzoneJS使用方法
2013/12/05 Javascript
JQuery EasyUI 日期控件如何控制日期选择区间
2014/05/05 Javascript
JS案例分享之金额小写转大写
2014/05/15 Javascript
jquery单选框radio绑定click事件实现方法
2015/01/14 Javascript
jQuery实现渐变弹出层和弹出菜单的方法
2015/02/20 Javascript
ECMAScript5(ES5)中bind方法使用小结
2015/05/07 Javascript
js带点自动图片轮播幻灯片特效代码分享
2015/09/07 Javascript
JS组件Bootstrap实现下拉菜单效果代码
2016/04/26 Javascript
基于input动态模糊查询的实现方法
2017/12/12 Javascript
vue中阻止click事件冒泡,防止触发另一个事件的方法
2018/02/08 Javascript
vue渲染方式render和template的区别
2020/06/05 Javascript
浅谈Tensorflow由于版本问题出现的几种错误及解决方法
2018/06/13 Python
在pycharm上mongodb配置及可视化设置方法
2018/11/30 Python
基于python的Paxos算法实现
2019/07/03 Python
django 配置阿里云OSS存储media文件的例子
2019/08/20 Python
Numpy 多维数据数组的实现
2020/06/18 Python
Python如何读写字节数据
2020/08/05 Python
浅谈对python中if、elif、else的误解
2020/08/20 Python
英国天然保健品网站:Simply Supplements
2017/03/22 全球购物
欧洲领先的电子和电信零售商和服务提供商:Currys PC World Business
2017/12/05 全球购物
标记环网Toke Ring IEEE802.5
2014/05/26 面试题
程序员经常用到的UNIX命令
2015/04/13 面试题
大学军训通讯稿
2014/01/13 职场文书
学党史心得体会
2014/09/05 职场文书
大学生敬老院活动总结
2015/05/07 职场文书
2015年电厂工作总结范文
2015/05/13 职场文书
土木工程毕业答辩开场白
2015/05/29 职场文书
职业生涯规划书之大学四年
2019/08/07 职场文书
2019下半年英语教师的教学工作计划(3篇)
2019/09/25 职场文书
Anaconda安装pytorch和paddle的方法步骤
2022/04/03 Python