• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Python实现图片识别功能的示例分享

python 搞代码 4年前 (2022-01-09) 32次浏览 已收录 0个评论

这篇文章主要介绍了Python编程实现的图片识别功能,涉及Python PIL模块的安装与使用技巧,需要的朋友可以参考下

本文实例讲述了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

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

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

附测试代码

from pytesser import *from PIL import Image, ImageEnhanceim = 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\201704<span>本文来源gaodai#ma#com搞*!代#%^码$网*</span>24\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 = 140table = []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实现图片识别功能的示例分享的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Python实现图片识别功能的示例分享

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址