Skip to main content

pyocrcaptcha

基于 YOLO 的图片验证码 OCR Python 包。安装后既可以作为对象调用,也可以直接使用命令行识别图片。

安装

pip install pyocrcaptcha

pip 会根据包元数据自动安装运行依赖:

  • ultralytics>=8.3.0
  • Pillow>=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%。整串完全正确率会低于单字符准确率。
  • 仅供学习与研究使用,请遵守验证码来源网站的服务条款和适用法律法规。

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.1.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.1-py3-none-any.whl (3.0 MB view details)

Uploaded Python 3

File details

Details for the file pyocrcaptcha-1.0.1.tar.gz.

File metadata

  • Download URL: pyocrcaptcha-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 3e7af8aac8bfc19bf5e3292966911a17e7c03ba190e20a99450153e0b152797e
MD5 ee7e675f1dcde8a965612ce6c3d689c9
BLAKE2b-256 08c61c2e75d49c09d02de00f28fe25bff1e4ebbaab2df455d942248471cc18a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyocrcaptcha-1.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: pyocrcaptcha-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f1d0b28ed844a72976de4e41bee9f722b6f348260bbb48f82fdb7029fa97737
MD5 cd32551c26d3dc780c42c928434ef6ab
BLAKE2b-256 bdf33d856cee5c89631f97c671317926f9df88fe2da4d295560b5c2e7f54cd0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyocrcaptcha-1.0.1-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

This release

1.0.1 This release

2 files

1.0.0

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