首页 > 其他 > 详细

爬虫 - 用ocr来识别验证码

时间:2018-08-26 15:31:41      阅读:172      评论:0      收藏:0      [点我收藏+]

用OCR来识别
直接识别效果不好,因为验证码内的多余线条干扰了图片的识别。先转为灰度图像,再二值化。经实践证明,该方法不是100%正确。

# 获取图片
curl -X GET http://my.cnki.net/elibregister/CheckCode.aspx

import tesserocr
from PIL import Image

image = Image.open(‘1.png‘)
# 转为灰度图像
image = image.convert(‘L‘)

threshold = 127
table = []

# 二值化
for i in range(256):
    if i < threshold:
        table.append(0)
    else:
        table.append(1)
# mode=‘1‘默认的阀值为127
image = image.point(table, ‘1‘)
image.show()
result = tesserocr.image_to_text(image)
print(result)

爬虫 - 用ocr来识别验证码

原文:https://www.cnblogs.com/allen2333/p/9537471.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!