Skip to main content

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

pyocrcaptcha-1.0.0.tar.gz (3.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyocrcaptcha-1.0.0-py3-none-any.whl (3.0 MB view details)

Uploaded Python 3

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

Hashes for pyocrcaptcha-1.0.0.tar.gz
Algorithm Hash digest
SHA256 eb3c9c745464c563b153be66dded98ed323bc65d0978cbaaaf4e9edf50065182
MD5 e71f3e78a237d147fff3dab919fc054d
BLAKE2b-256 1362a2f07403e0efbd2aeb33a3e2e5128ddd0808a93c8f0e92ba0c1d95050c79

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyocrcaptcha-1.0.0.tar.gz:

Publisher: workflow.yml on Moxin1044/pyocrcaptcha

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pyocrcaptcha-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f17b67e051df6fb9fd67f5f1c468ccaf8cda8fee1aa373829cefaf982543c46b
MD5 253a7f06dd44a3de69bd0d11ecdba1d8
BLAKE2b-256 ca1138c8005be44364f0b868290c7b99264bd9705fa058e904a678fe9b7c5401

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyocrcaptcha-1.0.0-py3-none-any.whl:

Publisher: workflow.yml on Moxin1044/pyocrcaptcha

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.0.1

2 files

This release

1.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page