← 返回 Skills 市场
moxin1044

captcha-recognition

作者 末心 · GitHub ↗ · v1.0.1 · MIT-0
cross-platform ✓ 安全检测通过
254
总下载
1
收藏
0
当前安装
2
版本数
在 OpenClaw 中安装
/install captcha-recognition
功能描述
Recognizes CAPTCHA images using ddddocr library. Invoke when user needs to recognize/decode CAPTCHA images or mentions captcha verification.
使用说明 (SKILL.md)

CAPTCHA Recognition Skill

基于 ddddocr 的验证码识别技能,提供简单易用的验证码识别功能。

When to Use This Skill

当用户有以下请求时,应该激活此技能:

  • 识别验证码图片

    • "帮我识别这个验证码"
    • "这个验证码是什么"
    • "帮我破解这个验证码图片"
    • "识别这张图片中的验证码"
  • 网络验证码识别

    • "识别这个 URL 的验证码:http://example.com/captcha.png"
    • "帮我识别网页上的验证码图片"
    • 用户提供了 HTTP/HTTPS 链接的验证码图片
  • OCR 相关请求

    • "OCR 识别这个图片"
    • "提取图片中的文字"
    • "图片文字识别"
  • 验证码验证场景

    • 用户发送了验证码图片并询问内容
    • 需要自动识别网页/应用中的验证码

依赖安装

pip install ddddocr opencv-python numpy Pillow requests

支持的图片输入格式

本技能支持多种验证码图片输入方式:

格式 示例 说明
本地文件路径 captcha.jpg 本地存储的验证码图片
HTTP/HTTPS URL http://example.com/captcha.png 网络上的验证码图片
Blob URL blob:https://example.com/... 浏览器 Blob URL(需特殊处理)
字节数据 bytes 图片的二进制数据
PIL Image PIL.Image.Image PIL Image 对象

关于 Blob URL

Blob URL(如 blob:https://example.com/xxx)是浏览器内部创建的临时 URL,无法从服务器端直接访问。如果用户提供 Blob URL,需要:

  1. 在浏览器中右键保存图片到本地
  2. 或者使用浏览器开发者工具获取实际的图片 URL
  3. 或者将图片下载后提供本地路径

命令行使用

python scripts/captcha.py \x3Cimage_path_or_url> [--preprocess]

参数说明:

  • image_path_or_url: 验证码图片路径或网络 URL(必需)
  • --preprocess: 可选,启用图像预处理(灰度化、二值化)

示例:

# 本地文件
python scripts/captcha.py captcha.jpg
python scripts/captcha.py captcha.jpg --preprocess

# 网络 URL
python scripts/captcha.py http://example.com/captcha.png
python scripts/captcha.py https://example.com/captcha.jpg --preprocess

Python API 使用

(注意:如果想要更快速和节省Token,你应该优先使用命令行的方式!)

快速开始

from scripts.captcha import recognize_captcha

# 方法1: 从文件路径识别(最常用)
result = recognize_captcha("path/to/captcha.jpg")
print(f"验证码内容: {result}")

# 方法2: 从网络 URL 识别
result = recognize_captcha("http://example.com/captcha.png")
print(f"验证码内容: {result}")

result = recognize_captcha("https://example.com/captcha.jpg")
print(f"验证码内容: {result}")

# 方法3: 从字节数据识别
with open("captcha.jpg", "rb") as f:
    image_bytes = f.read()
result = recognize_captcha(image_bytes)

# 方法4: 从 PIL Image 对象识别
from PIL import Image
pil_image = Image.open("captcha.jpg")
result = recognize_captcha(pil_image)

启用图像预处理

对于质量较差或有干扰线的验证码,可以启用预处理:

# preprocess=True 会进行灰度化和二值化处理
result = recognize_captcha("captcha.jpg", preprocess=True)

API Reference

recognize_captcha(image, preprocess=False, show_ad=False, timeout=10)

主要识别函数,支持多种输入格式。

参数:

参数 类型 必需 说明
image str / bytes / PIL.Image.Image 验证码图片,可以是文件路径、网络 URL、字节数据或 PIL Image 对象
preprocess bool 是否启用图像预处理(灰度化、二值化),默认 False
show_ad bool 是否显示 ddddocr 广告,默认 False
timeout int 网络 URL 请求超时时间(秒),默认 10

返回值:

  • str: 识别出的验证码文本

异常:

  • FileNotFoundError: 图片文件不存在
  • ValueError: 不支持的 URL 格式(如 Blob URL)
  • RuntimeError: 网络请求失败或图像处理失败
  • TypeError: 不支持的图片类型
  • ImportError: 缺少必要的依赖库

CaptchaRecognizer

如需更细粒度的控制,可以直接使用类:

from scripts.captcha import CaptchaRecognizer

recognizer = CaptchaRecognizer(show_ad=False)

# 从文件识别
result = recognizer.recognize_from_file("captcha.jpg", preprocess=False)

# 从网络 URL 识别
result = recognizer.recognize_from_url("http://example.com/captcha.png", preprocess=False)

# 从字节识别
with open("captcha.jpg", "rb") as f:
    result = recognizer.recognize_from_bytes(f.read())

# 从 PIL Image 识别
from PIL import Image
img = Image.open("captcha.jpg")
result = recognizer.recognize_from_pil(img)

最佳实践

  1. 优先使用文件路径:如果图片已保存为文件,直接传递路径字符串最简单
  2. 网络 URL 识别:支持 HTTP/HTTPS URL,会自动下载并识别验证码
  3. 预处理建议:对于背景复杂、有干扰线或颜色较多的验证码,尝试 preprocess=True
  4. 错误处理:建议捕获 FileNotFoundErrorValueErrorTypeError 提供友好的错误提示
  5. 性能优化recognize_captcha() 使用单例模式,重复调用不会重复加载 OCR 模型
  6. 超时设置:对于网络 URL,可以通过 timeout 参数调整请求超时时间

完整示例

from scripts.captcha import recognize_captcha

def solve_captcha(image_source):
    """识别验证码并处理可能的错误"""
    try:
        # 先尝试不预处理
        result = recognize_captcha(image_source)
        
        # 如果结果为空或不合理,尝试预处理
        if not result or len(result) \x3C 2:
            result = recognize_captcha(image_source, preprocess=True)
        
        return result
        
    except FileNotFoundError:
        return "错误:找不到图片文件"
    except ValueError as e:
        return f"错误:{e}"
    except ImportError as e:
        return f"错误:缺少依赖库 - {e}"
    except Exception as e:
        return f"错误:识别失败 - {e}"

# 使用本地文件
result = solve_captcha("captcha.jpg")
print(f"识别结果: {result}")

# 使用网络 URL
result = solve_captcha("http://example.com/captcha.png")
print(f"识别结果: {result}")
安全使用建议
This skill appears internally consistent with a CAPTCHA OCR tool. Before installing: 1) be aware it will ask you to pip-install ddddocr, OpenCV and other Python packages (OpenCV may require system build deps). 2) The skill downloads images only from URLs you provide—do not supply private or sensitive image URLs if you don't want the agent to fetch them. 3) ddddocr is a third‑party package; verify the package source/version you install and review its licensing and security posture. 4) Using CAPTCHA bypassing code can have legal or terms-of-service implications—ensure your use is lawful and ethical. 5) No hidden network endpoints or secret-exfiltration behaviors were found in the included script.
功能分析
Type: OpenClaw Skill Name: captcha-recognition Version: 1.0.1 The captcha-recognition skill provides legitimate OCR functionality using the ddddocr and opencv-python libraries. The code in scripts/captcha.py implements standard image processing and fetching logic via requests, with appropriate error handling for invalid URLs and missing dependencies. No evidence of malicious intent, data exfiltration, or prompt injection attacks was found.
能力评估
Purpose & Capability
Name/description (captcha OCR) match the included script and README. Declared dependencies (ddddocr, OpenCV, numpy, Pillow, requests) align with imports in scripts/captcha.py. No unrelated binaries, env vars, or config paths are requested.
Instruction Scope
SKILL.md and the script limit actions to reading local files, fetching user-supplied HTTP/HTTPS image URLs, and performing image preprocessing + OCR. The README explicitly rejects blob: URLs for server-side use. There are no instructions to read unrelated files, environment variables, or to transmit data to unknown endpoints.
Install Mechanism
This is an instruction-only skill (no install spec). The README advises installing standard PyPI packages (pip install ddddocr opencv-python numpy Pillow requests). That is expected and not an unusual or high-risk install mechanism.
Credentials
No environment variables, credentials, or config paths are required. The script only uses network access to fetch user-provided image URLs, which is proportional to its purpose.
Persistence & Privilege
Skill does not request always: true and does not alter other skills or system-wide settings. Autonomous invocation is allowed by default (platform normal), but there are no elevated privileges requested by the skill itself.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install captcha-recognition
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /captcha-recognition 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.1
- Added support for recognizing CAPTCHA images directly from HTTP/HTTPS URLs. - Updated documentation to describe handling of browser Blob URLs and expanded input format options. - Required dependencies now include the requests library for network image retrieval. - API and command-line tool now accept both local file paths and image URLs as input. - Improved error handling and parameter documentation for various input scenarios.
v1.0.0
Initial release of captcha-recognition skill. - Provides CAPTCHA recognition via the ddddocr library. - Supports usage through both command-line and Python API. - Handles image input as file path, bytes, or PIL Image. - Includes optional image preprocessing for challenging CAPTCHAs. - Designed for scenarios involving CAPTCHA verification and OCR requests. - Offers clear error messages and best practice recommendations.
元数据
Slug captcha-recognition
版本 1.0.1
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 2
常见问题

captcha-recognition 是什么?

Recognizes CAPTCHA images using ddddocr library. Invoke when user needs to recognize/decode CAPTCHA images or mentions captcha verification. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 254 次。

如何安装 captcha-recognition?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install captcha-recognition」即可一键安装,无需额外配置。

captcha-recognition 是免费的吗?

是的,captcha-recognition 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

captcha-recognition 支持哪些平台?

captcha-recognition 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 captcha-recognition?

由 末心(@moxin1044)开发并维护,当前版本 v1.0.1。

💬 留言讨论