pyocrcaptcha
基于 YOLO 的图片验证码 OCR Python 包。安装后既可以作为对象调用,也可以直接使用命令行识别图片。
安装
pip install pyocrcaptcha
pip 会根据包元数据自动安装运行依赖:
ultralytics>=8.3.0Pillow>=10.0.0- Ultralytics 的传递依赖,包括 PyTorch、TorchVision、NumPy、OpenCV 等
因此不需要再手动安装 requirements.txt。如果需要确认依赖解析结果,可以执行:
python -m pip show pyocrcaptcha
python -m pip check
发布到 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 位验证码(支持宽度不是 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%。整串完全正确率会低于单字符准确率。
- 仅供学习与研究使用,请遵守验证码来源网站的服务条款和适用法律法规。
Metadata
Release files for pyocrcaptcha 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyocrcaptcha-1.0.1.tar.gz | 3.0 MB | With provenance | Details for pyocrcaptcha-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyocrcaptcha-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for pyocrcaptcha-1.0.1-py3-none-any.whl |
Total release size: 6.0 MB
Release files / pyocrcaptcha-1.0.1.tar.gz
| Download URL | pyocrcaptcha-1.0.1.tar.gz |
|---|---|
| Size | 3.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3e7af8aac8bfc19bf5e3292966911a17e7c03ba190e20a99450153e0b152797e
|
|
BLAKE2b-256 checksum How to use checksums |
08c61c2e75d49c09d02de00f28fe25bff1e4ebbaab2df455d942248471cc18a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency logRelease files / pyocrcaptcha-1.0.1-py3-none-any.whl
| Download URL | pyocrcaptcha-1.0.1-py3-none-any.whl |
|---|---|
| Size | 3.0 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1f1d0b28ed844a72976de4e41bee9f722b6f348260bbb48f82fdb7029fa97737
|
|
BLAKE2b-256 checksum How to use checksums |
bdf33d856cee5c89631f97c671317926f9df88fe2da4d295560b5c2e7f54cd0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency logSecurity for pyocrcaptcha 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for pyocrcaptcha-1.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.