鱼C论坛

 找回密码
 立即注册
查看: 1524|回复: 0

[作品展示] 爬虫验证码验证tessercor识别库

[复制链接]
发表于 2019-4-14 04:12:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 Stubborn 于 2019-4-14 04:14 编辑

安装说明的走百度吧。这个可以收藏,嗯嗯,据说本来识别不出的验证,经过设置识别率可以提高75%
  1. # -*- coding: utf-8 -*-
  2. # @Time    : 2019-04-10 02:32
  3. # @Author  : Ein
  4. # @File    : tessercor-图片识别.py
  5. # @Software: PyCharm
  6. import locale
  7. locale.setlocale(locale.LC_ALL,'C')
  8. #为 MAC而设置,不是可以无视
  9. import pytesseract,os
  10. from PIL import Image,ImageEnhance

  11. def yzm_file_path():
  12.     currrent_path = os.path.realpath(__file__)  # 文件绝对路径
  13.     current_dir = os.path.split(currrent_path)[0]
  14.     return current_dir + r"/png/ZD26.jpg"
  15. #图片路径
  16. path = yzm_file_path()
  17. #打开图片
  18. image = Image.open(path)
  19. image = image.convert('RGB')
  20. enhancer = ImageEnhance.Color(image)
  21. enhancer = enhancer.enhance(0)
  22. enhancer = ImageEnhance.Brightness(enhancer)
  23. enhancer = enhancer.enhance(2)
  24. enhancer = ImageEnhance.Contrast(enhancer)
  25. enhancer = enhancer.enhance(8)
  26. enhancer = ImageEnhance.Sharpness(enhancer)
  27. image = enhancer.enhance(20)


  28. #转化灰度图片
  29. image = image.convert('L')
  30. #展示
  31. #image.show()


  32. #二值化处理
  33. threshold = 140
  34. table = []
  35. for i in range(256):
  36.     if i < threshold:
  37.         table.append(0)
  38.     else:
  39.         table.append(1)
  40. out = image.point(table,"1")
  41. #展示
  42. #out.show()

  43. #识别图片
  44. print(pytesseract.image_to_string(image))
复制代码

本帖被以下淘专辑推荐:

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-26 07:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表