← 返回
未分类 Key 中文

free-ocr-zc

Extract text from images via OpenRouter API using Baidu Qianfan OCR model, supporting URLs and local files with customizable prompts.
通过 OpenRouter API 调用百度千帆 OCR 模型,从图片(支持 URL 与本地文件)中提取文字,并可自定义提示词。
openclawzhangchong
未分类 clawhub v1.0.3 1 版本 100000 Key: 需要
★ 0
Stars
📥 290
下载
💾 0
安装
1
版本
#latest

概述

OpenRouter OCR Skill

Overview

This skill provides OCR (Optical Character Recognition) functionality using models available via OpenRouter. It uses the OpenAI Python library to communicate with OpenRouter's API, specifically designed for models like Baidu's Qianfan OCR.

Quick Start

When you need to extract text from an image:

  1. Ensure prerequisites:
    • Python 3.x installed
    • Required packages: openai, requests (install via pip install openai requests)
    • Place your OpenRouter API key in the file: C:\Users\Administrator\.openclaw\secrets\openrouter.env

(format: OPENROUTER_API_KEY=your_key_here)

  1. Call the OCR script with an image URL or local file path:

```bash

python ocr.py [prompt]

```

  • image_input: Either a URL or a local file path to the image
  • prompt: Optional text prompt for the OCR (default: "OCR提取图片所有文字")
  1. Get result: The script prints the extracted text to stdout.

Usage Examples

Basic Usage with Default Prompt

python ocr.py "https://example.com/image.jpg"

Custom Prompt

python ocr.py "https://example.com/image.jpg" "请识别图片中的所有文字"

Local Image File

python ocr.py "C:\path\to\image.jpg"

How It Works

The skill uses the OpenAI client configured with:

  • Base URL: https://openrouter.ai/api/v1
  • Model: baidu/qianfan-ocr-fast:free (configurable via environment variable)
  • API Key: Read from OPENROUTER_API_KEY environment variable

It sends a multimodal request containing:

  1. A text prompt (default: "OCR提取图片所有文字")
  2. The image (encoded as base64 if local, or passed directly if URL)

The model returns the extracted text which is printed to console.

Environment Variables

  • OPENROUTER_API_KEY: Required - Your OpenRouter API key
  • OCR_MODEL: Optional - Model to use (default: baidu/qianfan-ocr-fast:free)
  • OCR_BASE_URL: Optional - OpenRouter base URL (default: https://openrouter.ai/api/v1)

Installation

  1. Create the skill directory: mkdir -p skills/openrouter-ocr
  2. Save the ocr.py script in this directory
  3. Install dependencies: pip install openai requests
  4. Set your OpenRouter API key:

```bash

setx OPENROUTER_API_KEY "your_api_key_here"

```

(Restart terminal after setting)

Notes

  • The skill works with both HTTP/HTTPS URLs and local file paths
  • For local files, the image is read and base64-encoded before sending
  • Error handling includes network issues, invalid API keys, and model errors
  • The default model is Baidu's Qianfan OCR fast version (free tier)
  • You can change the model by setting the OCR_MODEL environment variable
  • Response time depends on image size and model speed

Troubleshooting

  • API Key Error: Ensure OPENROUTER_API_KEY is set correctly
  • Module Not Found: Install required packages with pip install openai requests
  • Image Access: Verify the image URL is accessible or local path exists
  • Model Not Available: Check if the specified model is available on OpenRouter

Example Output

✅ OCR 识别结果:
------------------------------------------------------------
这是识别出的文本内容
...
------------------------------------------------------------

Security Note

Never commit your API key to version control. Keep it secure in environment variables.

版本历史

共 1 个版本

  • v1.0.3 当前
    2026-05-08 03:41 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

zc-douyin-xiazai-txt

openclawzhangchong
抖音无水印视频下载与文案提取工具,使用本地 ffmpeg 和 Whisper 完成下载、音频提取及文字转写,支持语义分段。
★ 1 📥 523

douyindownloadwhisper

openclawzhangchong
Windows平台下抖音视频无水印下载,配合本地Whisper语音转文字与自动语义分段文案提取。
★ 0 📥 600

qq-mail-read-send

openclawzhangchong
读取/发送QQ邮件,支持IMAP读取、SMTP发送和多编码解析。触发场景:查看、读取、筛选邮件或发送邮件。
★ 1 📥 376