Skip to main content

Universal Slider Captcha Recognition Tool (通用的滑块验证码识别工具)

Project description

简体中文 | English

Captcha-Recognizer

Captcha-Recognizer是一个易用的通用滑块验证码识别库,通过深度学习训练通用的缺口检测模型,基于训练的结果,识别出验证码中的滑块缺口位置,并返回缺口的坐标与可信度。

支持的验证码类型

  • 单缺口验证码背景图
  • 多缺口验证码背景图
  • 验证码截图(包含滑块和背景图)

版本要求

  • Python >= 3.8.0

  • ultralytics >= 8.0.0

  • torch >= 1.8.0

  • onnxruntime

  • onnx

  • Works on Linux, Windows, macOS

安装

From pip

pip install captcha-recognizer

使用示例

单缺口/多缺口验证码识别

from captcha_recognizer.recognizer import Recognizer

# source传入图片路径, verbose=False表示关闭冗余输出
recognizer = Recognizer()
box, confidence = recognizer.identify_gap(source='your_example_image.png', verbose=False)

print(f'缺口坐标: {box}')
print(f'可信度: {confidence}')

"""
打印结果如下:
缺口方框坐标: [331.72052001953125, 55.96122741699219, 422.079345703125, 161.7498779296875]
可信度: 0.9513089656829834

坐标原点:图片左上角
缺口方框坐标为缺口方框左上角和右下角距离坐标原点的距离
"""

单缺口/多缺口验证码示例图片

包括且不限于以下类型、尺寸的滑块图片检测

示例图 1

尺寸 552*344

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/example1.png

识别效果示例图 1

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/predict1.png

示例图 2

尺寸 260*160

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/example2.png

识别效果示例图 2

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/predict2.png

示例图 3

尺寸 400*200

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/example1.png

识别效果示例图3

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/predict3.png

示例图 4

尺寸 672*390

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/example4.png

识别效果示例图4

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/predict4.png

示例图 5

尺寸 280*155

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/example5.png

识别效果示例图 5

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/predict5.png

示例图 6

尺寸 590*360

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/example6.png

识别效果示例图 6

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/predict6.png

示例图 7

尺寸 320*160

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/example7.png

识别效果示例图 7

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/predict7.png

验证码截图识别

from captcha_recognizer.recognizer import Recognizer

# source传入图片路径, verbose=False表示关闭冗余输出
recognizer = Recognizer()
box, confidence = recognizer.identify_gap(source='your_example_image.png', verbose=False)

print(f'缺口坐标: {box}')
print(f'可信度: {confidence}')

"""
打印结果如下:
缺口方框坐标: [331.72052001953125, 55.96122741699219, 422.079345703125, 161.7498779296875]
可信度: 0.9513089656829834

坐标原点:图片左上角
缺口方框坐标为缺口方框左上角和右下角距离坐标原点的距离
"""

验证码截图识别示例

包括且不限于以下类型、尺寸的滑块验证码截图

示例图 8

尺寸 305*156

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/example8.png

识别效果示例图 8

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/predict8.png

注意事项

偏移量

某些种类的滑块验证码,滑块初始位置存在一定偏移,以下面图中的滑块初始位置为例:

示例图 9

https://captcha-slider.oss-cn-beijing.aliyuncs.com/slider/offset2.png

如示例图9中:

  • 第一条黑线位置为滑块初始位置,距离图片边框有大概有8个像素的偏移量(offset为8)
  • 识别结果的缺口坐标为 [x1, y1, x2, y2] 对应缺口的左上角和右下角坐标(坐标原点为图片左上角)
  • 第二条黑线的X轴坐标值对应缺口识别结果左上角的X轴坐标值,此处值为154(x1为154)
  • 因此实际滑块的偏移量为 x1-offset (154-8=146)
  • 也就是说,实际的滑块偏移量为缺口的x1值减去滑块距离图片边框的偏移量(offset)

图片识别耗时

首次识别耗时较长(2s左右),后续单张图片的识别在60ms(60毫秒)左右 因为首次识别图片时需要将模型从磁盘加载到内存中,并进行一系列的初始化工作,如权重加载、内存分配等。这个过程相对耗时; 一旦模型加载完成并初始化好,后续的图片预测就可以直接利用已经加载好的模型和分配好的资源,从而避免了重复加载和初始化的开销。

遇到问题

  • Error loading “xxx\Lib\site-packages\torch\lib\fbgemm.dll” or one of its dependencies.
  • Model Unsupported model IR version: 9, max supported IR version: 8

项目维护

  • 本项目长期维护。
  • 如果您有任何问题,欢迎提issue
  • 如果您遇到本项目不能识别的滑块验证码,欢迎提issue,我会尽快解决。

更多联系方式

免责声明

本项目不针对任何一家验证码厂商,项目所有内容仅供学习交流使用,不用于其他任何目的,严禁用于非法用途。

许可证

MIT license

History

0.3.2 (2024-09-24)

  • 修复图片链接错误 (Fix image link)

0.3.1 (2024-09-24)

  • 添加一些注意事项 (Add some notes)

0.3.0 (2024-09-23)

  • 支持截图类型的验证码识别 (Screenshot support)

0.2.1 (2024-09-10)

  • Fix example image link

0.2.0 (2024-09-10)

  • Improve the captcha compatibility of the library

0.1.6 (2024-09-06)

  • Update README

0.1.5 (2024-09-06)

  • Compress sample picture

0.1.4 (2024-08-30)

  • Handle the case where the result is empty
  • Split workflow to two jobs

0.1.3 (2024-08-26)

  • Optimize example image css in README

0.1.2 (2024-08-26)

  • Update example image url in README

0.1.1 (2024-08-26)

  • Update README

0.1.0 (2024-08-23)

  • First release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

captcha_recognizer-0.3.2.tar.gz (37.7 MB view hashes)

Uploaded Source

Built Distribution

captcha_recognizer-0.3.2-py3-none-any.whl (37.7 MB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page