滑块验证码识别
Project description
简体中文 | English
Captcha-Recognizer
Captcha-Recognizer是一个易用的通用滑块验证码识别库,通过深度学习训练通用的缺口检测模型,基于训练的结果,识别出验证码中的滑块缺口位置,并返回缺口的坐标与可信度。
支持的验证码类型
- 单缺口验证码背景图
多缺口验证码背景图 (1.0.0及之后版本移除)- 验证码全图(图片包含滑块和背景图)
在线演示
版本要求
-
Python>= 3.6.0 -
opencv-python -
shapely -
onnxruntime -
Works on Linux, Windows, MacOS
使用方式
- Pypi
- HTTP API
Pypi
从 Pypi 安装
pip install captcha-recognizer
HTTP API
请移步: captcha-api
使用示例
支持以下类型验证码的识别
- 单缺口验证码背景图(不含滑块的背景图)
- 单缺口、多缺口验证码全图(图片含滑块和背景图)
单缺口验证码背景图 识别示例
示例图 4
尺寸 672*390
识别效果示例图4
单缺口、多缺口验证码全图 识别示例
示例图 8
尺寸 305*156
识别效果示例图 8
代码示例
from captcha_recognizer.slider import Slider
# source传入待识别图片,支持数据类型为 Union[str, Path, bytes, np.ndarray]
# show为布尔值,默认值为False, 为True表示展示图片识别效果,线上环境请缺省,或设置为False
box, confidence = Slider().identify(source=f'images_example/example8.png', show=True)
print(f'缺口坐标: {box}')
print('置信度', confidence)
注意事项
偏移量
某些种类的滑块验证码,滑块初始位置存在一定偏移,以下面图中的滑块初始位置为例:
示例图 9
如示例图9中:
- 第一条黑线位置为滑块初始位置,距离图片边框有大概有8个像素的偏移量(offset为8)
- 识别结果的缺口坐标为 [x1, y1, x2, y2] 对应缺口的左上角和右下角坐标(坐标原点为图片左上角)
- 第二条黑线的X轴坐标值对应缺口识别结果左上角的X轴坐标值,此处值为154(x1为154)
- 因此实际滑块的距离为 x1-offset (154-8=146)
- 也就是说,实际的滑块距离为缺口的x1值减去滑块距离图片边框的偏移量(offset)
获取偏移量
通常某一类的滑块验证码,滑块偏移量是固定的,可直接通过截图工具或测量工具获取 如果是动态的偏移量,可通过 identify_offset 方法获取偏移量
from captcha_recognizer.slider import Slider
offset, confidence = Slider().identify_offset(source='example.png')
print(f'偏移量: {offset}')
print('置信度', confidence)
图片缩放
某些验证码,前端渲染时会对图片进行缩放,因此实际的滑块距离也要按照图片缩放比例进行计算。
示例图 10
opencv-python与numpy的兼容性问题
兼容版本1:
opencv-python==4.12.0.88
numpy==2.2.6
兼容版本2:
opencv-python==4.8.0.74
numpy==1.23.0
更多兼容的版本请自行尝试
了解更多
DeepWiki文档内可通过底部AI对话框进行交流,自由了解本项目。
版本历史:
项目维护
- 感谢 Star 支持;
- 项目长期维护;
- 有任何疑问或问题,欢迎提issue。
更多联系方式
- Gmail: chenwei.zhaozhao@gmail.com
- 163/网易: chenwei_nature@163.com
免责声明
本项目不针对任何一家验证码厂商,项目所有内容仅供学习交流使用,不用于其他任何目的,严禁用于非法用途。
许可证
MIT license
感谢你的支持
Stargazers
Forkers
Star History
版本历史
1.0.2 (2026-01-28)
- 支持传入base64编码的图片 (Support passing in base64 encoded images)
1.0.1 (2025-09-29)
- 提高默认的置信度阈值 (Improve default confidence threshold)
1.0.0 (2025-09-23)
- 提高模型泛化能力 (Improve model generalization)
- 优化识别逻辑 (Optimize recognition logic)
1.0.0-Beta1 (2025-09-15)
- 更新README (Update README)
1.0.0-Beta (2025-09-15)
- 移除V1版本 (V1 Removed)
0.10.0 (2025-08-19)
- 移除旧版模型 (Remove old model)
0.9.0 (2025-08-19)
- 新增V2增强版模型 (V2 Enhanced Model)
0.9.0-Beta (2025-08-06)
- 新增V2增强版模型 (V2 Enhanced Model)
0.8.0 (2025-07-16)
- 依赖最小化 (Dependency Minimization)
- 将ultralytics库替换为cv2
0.7.3 (2025-06-24)
- 修复README中示例错误 (Fix README example error)
0.7.2 (2025-05-30)
- 优化单缺口图片的识别逻辑 (Optimize the logic of single-gap image recognition)
0.7.1 (2025-03-24)
- 提交兼容性 (Compatibility)
0.7.0 (2025-02-12)
- 优化滑块截图的识别逻辑 (Optimize the logic of sliding block screenshot recognition)
0.6.0 (2024-11-13)
- 增强模型泛化能力 (Enhance model generalization)
0.5.0 (2024-11-06)
- 新增功能:基于验证码截图识别滑块距离 (Added support for recognizing the distance of the sliding block in screenshot)
0.4.0 (2024-10-10)
- 增强模型泛化能力 (Enhance model generalization)
0.3.3 (2024-09-29)
- 添加HTTP API文档链接 (Add HTTP API docs link)
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file captcha_recognizer-1.0.2.tar.gz.
File metadata
- Download URL: captcha_recognizer-1.0.2.tar.gz
- Upload date:
- Size: 34.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b521fa1601a450fc712c919836b31d5fba852b6a109cc78fa25ac67b40e2e175
|
|
| MD5 |
1837c18c09ed6a12da028986a01012cf
|
|
| BLAKE2b-256 |
6cee8144f7bcca54da8eb424c3355d317e2c3c220efbed91e0fcfdc6339b78fb
|
Provenance
The following attestation bundles were made for captcha_recognizer-1.0.2.tar.gz:
Publisher:
publish_to_pypi.yml on chenwei-zhao/captcha-recognizer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
captcha_recognizer-1.0.2.tar.gz -
Subject digest:
b521fa1601a450fc712c919836b31d5fba852b6a109cc78fa25ac67b40e2e175 - Sigstore transparency entry: 868524930
- Sigstore integration time:
-
Permalink:
chenwei-zhao/captcha-recognizer@a9a961757199bed2035188f60ceb206cf043294a -
Branch / Tag:
refs/tags/1.0.2 - Owner: https://github.com/chenwei-zhao
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_to_pypi.yml@a9a961757199bed2035188f60ceb206cf043294a -
Trigger Event:
push
-
Statement type:
File details
Details for the file captcha_recognizer-1.0.2-py3-none-any.whl.
File metadata
- Download URL: captcha_recognizer-1.0.2-py3-none-any.whl
- Upload date:
- Size: 34.7 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
975515aa8f03313fed81f1fa6c37e33a4aa8e5b5ed8b4a064f56b0389948c81a
|
|
| MD5 |
d3f47d063f10354ec1899d012801b779
|
|
| BLAKE2b-256 |
748656f4ec86a3b2ef39baf12f957496a799f812a649b233569b4c3fa117bc9a
|
Provenance
The following attestation bundles were made for captcha_recognizer-1.0.2-py3-none-any.whl:
Publisher:
publish_to_pypi.yml on chenwei-zhao/captcha-recognizer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
captcha_recognizer-1.0.2-py3-none-any.whl -
Subject digest:
975515aa8f03313fed81f1fa6c37e33a4aa8e5b5ed8b4a064f56b0389948c81a - Sigstore transparency entry: 868524950
- Sigstore integration time:
-
Permalink:
chenwei-zhao/captcha-recognizer@a9a961757199bed2035188f60ceb206cf043294a -
Branch / Tag:
refs/tags/1.0.2 - Owner: https://github.com/chenwei-zhao
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_to_pypi.yml@a9a961757199bed2035188f60ceb206cf043294a -
Trigger Event:
push
-
Statement type: