pyocrcaptcha
基于 YOLO 的图片验证码 OCR Python 包。安装后既可以作为对象调用,也可以直接使用命令行识别图片。
安装
pip install pyocrcaptcha
发布到 PyPI
仓库通过 .github/workflows/workflow.yml 使用 PyPI Trusted Publishing 发布,不需要保存 API Token。工作流会在发布 GitHub Release 时自动运行,也可以在 GitHub Actions 页面手动运行。
首次发布前,需要在 PyPI 的 Trusted Publisher 设置中填写:
PyPI project name: pyocrcaptcha
Owner: Moxin1044
Repository: pyocrcaptcha
Workflow: workflow.yml
Environment: pypi
工作流会拉取 Git LFS 模型、构建 wheel 和 sdist,并确认 wheel 内包含完整模型后再上传。
从源码安装:
git clone https://github.com/Moxin1044/pyocrcaptcha.git
cd pyocrcaptcha
pip install .
模型也可从 V1.0.0 Release 单独下载:
下载 captcha-character-classifier-yolo11n-100e.pt
命令行
自动判断 4 位或 5 位验证码:
pyocrcaptcha xxx.png
强制指定位数并显示置信度:
pyocrcaptcha xxx.png --positions 4 --details
Python API
from pyocrcaptcha import CaptchaOCR
ocr = CaptchaOCR()
text = ocr("xxx.png")
print(text)
获取置信度和逐字符结果:
result = ocr.recognize("xxx.png")
print(result.text)
print(result.confidence)
print(result.character_confidences)
print(result.positions)
也可以传入自定义模型、设备或固定长度:
ocr = CaptchaOCR(model="best.pt", positions=4, device="cpu")
print(ocr("four_digit.png"))
说明
- 默认模型随包发布,支持数字
0-9和大写字母A-Z。 - 图片字符必须是等宽排列;自动模式会分别尝试 4 位和 5 位并选择平均置信度较高的结果。
- 当前模型验证集单字符 Top-1 为 83.23%,Top-5 为 94.59%。整串完全正确率会低于单字符准确率。
- 仅供学习与研究使用,请遵守验证码来源网站的服务条款和适用法律法规。
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 pyocrcaptcha-1.0.0.tar.gz.
File metadata
- Download URL: pyocrcaptcha-1.0.0.tar.gz
- Upload date:
- Size: 3.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb3c9c745464c563b153be66dded98ed323bc65d0978cbaaaf4e9edf50065182
|
|
| MD5 |
e71f3e78a237d147fff3dab919fc054d
|
|
| BLAKE2b-256 |
1362a2f07403e0efbd2aeb33a3e2e5128ddd0808a93c8f0e92ba0c1d95050c79
|
Provenance
The following attestation bundles were made for pyocrcaptcha-1.0.0.tar.gz:
Publisher:
workflow.yml on Moxin1044/pyocrcaptcha
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyocrcaptcha-1.0.0.tar.gz -
Subject digest:
eb3c9c745464c563b153be66dded98ed323bc65d0978cbaaaf4e9edf50065182 - Sigstore transparency entry: 2749167544
- Sigstore integration time:
-
Permalink:
Moxin1044/pyocrcaptcha@2a171c956a6152a9926450409e7b7b31641e3af3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Moxin1044
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@2a171c956a6152a9926450409e7b7b31641e3af3 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file pyocrcaptcha-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pyocrcaptcha-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f17b67e051df6fb9fd67f5f1c468ccaf8cda8fee1aa373829cefaf982543c46b
|
|
| MD5 |
253a7f06dd44a3de69bd0d11ecdba1d8
|
|
| BLAKE2b-256 |
ca1138c8005be44364f0b868290c7b99264bd9705fa058e904a678fe9b7c5401
|
Provenance
The following attestation bundles were made for pyocrcaptcha-1.0.0-py3-none-any.whl:
Publisher:
workflow.yml on Moxin1044/pyocrcaptcha
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyocrcaptcha-1.0.0-py3-none-any.whl -
Subject digest:
f17b67e051df6fb9fd67f5f1c468ccaf8cda8fee1aa373829cefaf982543c46b - Sigstore transparency entry: 2749167632
- Sigstore integration time:
-
Permalink:
Moxin1044/pyocrcaptcha@2a171c956a6152a9926450409e7b7b31641e3af3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Moxin1044
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@2a171c956a6152a9926450409e7b7b31641e3af3 -
Trigger Event:
workflow_dispatch
-
Statement type: