Token导航 LogoToken导航TokenDH.com
开发需要联网clawhub未标认证来源可访问clear审计通过

online-ocr-skill在线 ocr 技能

Agent Skill

online-ocr-skill 用于处理图像、截图、视觉识别或图片素材相关工作,适合在 OpenClaw 中需要让 Agent 分析图片、整理视觉素材或辅助图像流程时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

2,514

周安装

108

GitHub Stars

公开资料未说明

下载量

881
OpenClaw

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

MIT-0

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:online-ocr-skill(在线 ocr 技能)
来源仓库:https://github.com/wangzhi-collab/online-ocr-skill
安装命令:
openclaw skills install online-ocr-skill
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 OpenClaw 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

ClawHubOpenClaw
openclaw skills install online-ocr-skill

简介

在线OCR图片识别技能,使用免费的OCR.space API,无需安装Tesseract

SKILL.md

name
online-ocr
description
在线OCR图片识别技能,使用免费的OCR.space API,无需安装Tesseract
metadata
{"clawdbot":{"emoji":"🌐","requires":{"bins":["python"]}}}

Online OCR Skill

在线OCR图片识别技能,使用免费的OCR.space API,无需安装Tesseract OCR引擎。

特点

  • 无需安装Tesseract - 使用在线API
  • 支持多种语言 - 包括中文、英文等
  • 免费使用 - OCR.space免费API(每月1000次请求)
  • 简单易用 - 只需Python和requests库
  • 支持多种图片格式 - PNG, JPG, JPEG, PDF等

安装依赖

pip install requests pillow

使用方法

Python脚本

import requests
import base64
from PIL import Image
import io

class OnlineOCR:
    def __init__(self, api_key='helloworld'):  # 免费API密钥
        self.api_key = api_key
        self.api_url = 'https://api.ocr.space/parse/image'
    
    def ocr_from_file(self, image_path, language='chs'):
        """
        从图片文件识别文字
        
        参数:
        - image_path: 图片文件路径
        - language: 语言代码
            chs - 中文简体
            eng - 英文
            jpn - 日文
            kor - 韩文
            etc.
        
        返回: 识别结果文本
        """
        with open(image_path, 'rb') as f:
            img_data = f.read()
        
        return self.ocr_from_bytes(img_data, language)
    
    def ocr_from_bytes(self, image_bytes, language='chs'):
        """从字节数据识别文字"""
        # 将图片转换为base64
        img_base64 = base64.b64encode(image_bytes).decode('utf-8')
        
        # 准备请求数据
        payload = {
            'base64Image': f'data:image/png;base64,{img_base64}',
            'language': language,
            'isOverlayRequired': False,
            'apikey': self.api_key,
            'OCREngine': 2  # 使用引擎2(更准确)
        }
        
        # 发送请求
        response = requests.post(self.api_url, data=payload)
        
        if response.status_code == 200:
            result = response.json()
            if result['IsErroredOnProcessing']:
                raise Exception(f"OCR处理错误: {result['ErrorMessage']}")
            
            # 提取文本
            parsed_results = result.get('ParsedResults', [])
            if parsed_results:
                return parsed_results[0].get('ParsedText', '')
            return ''
        else:
            raise Exception(f"API请求失败: {response.status_code}")
    
    def ocr_from_url(self, image_url, language='chs'):
        """从URL识别图片文字"""
        payload = {
            'url': image_url,
            'language': language,
            'isOverlayRequired': False,
            'apikey': self.api_key,
            'OCREngine': 2
        }
        
        response = requests.post(self.api_url, data=payload)
        
        if response.status_code == 200:
            result = response.json()
            if result['IsErroredOnProcessing']:
                raise Exception(f"OCR处理错误: {result['ErrorMessage']}")
            
            parsed_results = result.get('ParsedResults', [])
            if parsed_results:
                return parsed_results[0].get('ParsedText', '')
            return ''
        else:
            raise Exception(f"API请求失败: {response.status_code}")

# 使用示例
if __name__ == "__main__":
    ocr = OnlineOCR()
    
    # 从文件识别
    text = ocr.ocr_from_file('test.png', language='chs')
    print(text)
    
    # 从URL识别
    # text = ocr.ocr_from_url('https://example.com/image.png', language='eng')

命令行工具

创建 online_ocr_cli.py

#!/usr/bin/env python3
import argparse
import os
import sys
from online_ocr import OnlineOCR

def main():
    parser = argparse.ArgumentParser(description='在线OCR图片识别工具')
    parser.add_argument('image', help='图片文件路径或URL')
    parser.add_argument('-l', '--lang', default='chs', 
                       help='语言代码 (默认: chs)')
    parser.add_argument('-o', '--output', help='输出文件路径')
    parser.add_argument('--api-key', default='helloworld',
                       help='OCR.space API密钥 (默认: helloworld)')
    
    args = parser.parse_args()
    
    # 创建OCR实例
    ocr = OnlineOCR(api_key=args.api_key)
    
    try:
        # 判断输入是文件还是URL
        if args.image.startswith('http://') or args.image.startswith('https://'):
            text = ocr.ocr_from_url(args.image, args.lang)
        else:
            if not os.path.exists(args.image):
                print(f"错误: 文件不存在 - {args.image}")
                return
            
            text = ocr.ocr_from_file(args.image, args.lang)
        
        # 输出结果
        if args.output:
            with open(args.output, 'w', encoding='utf-8') as f:
                f.write(text)
            print(f"结果已保存到: {args.output}")
        else:
            print("\
=== 识别结果 ===")
            print(text)
            
    except Exception as e:
        print(f"错误: {str(e)}")
        sys.exit(1)

if __name__ == "__main__":
    main()

支持的语言

OCR.space支持多种语言,常用语言代码:

  • chs - 中文简体
  • cht - 中文繁体
  • eng - 英文
  • jpn - 日文
  • kor - 韩文
  • fre - 法文
  • ger - 德文
  • spa - 西班牙文
  • rus - 俄文
  • ita - 意大利文

完整列表参考:https://ocr.space/ocrapi

API密钥

默认使用免费API密钥 helloworld,限制:

  • 每月1000次请求
  • 文件大小限制:1MB
  • 不支持PDF文件

如需更多功能,可注册获取自己的API密钥:

  1. 访问 https://ocr.space/ocrapi
  2. 注册账号
  3. 获取免费API密钥

示例

示例1:识别中文图片

from online_ocr import OnlineOCR

ocr = OnlineOCR()
text = ocr.ocr_from_file('chinese_text.png', language='chs')
print(text)

示例2:识别英文图片

text = ocr.ocr_from_file('english_text.png', language='eng')
print(text)

示例3:批量处理

import os
from online_ocr import OnlineOCR

ocr = OnlineOCR()

def batch_ocr(image_folder, output_folder, lang='chs'):
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)
    
    for filename in os.listdir(image_folder):
        if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
            image_path = os.path.join(image_folder, filename)
            output_path = os.path.join(output_folder, f"{os.path.splitext(filename)[0]}.txt")
            
            try:
                text = ocr.ocr_from_file(image_path, lang)
                
                with open(output_path, 'w', encoding='utf-8') as f:
                    f.write(text)
                
                print(f"已处理: {filename}")
            except Exception as e:
                print(f"处理失败 {filename}: {str(e)}")

集成到OpenClaw

作为工具使用

# 在OpenClaw技能中集成在线OCR功能
def online_ocr_tool(image_path, language='chs'):
    """在线OCR工具函数"""
    try:
        from online_ocr import OnlineOCR
        
        ocr = OnlineOCR()
        text = ocr.ocr_from_file(image_path, language)
        
        return {
            "success": True,
            "text": text,
            "language": language,
            "source": "OCR.space API"
        }
    except Exception as e:
        return {
            "success": False,
            "error": str(e),
            "source": "OCR.space API"
        }

故障排除

常见问题

  1. API请求限制
   错误: 超过API限制

解决方案:等待下个月或注册获取自己的API密钥

  1. 图片太大
   错误: 文件大小超过限制

解决方案:压缩图片或减小尺寸

  1. 网络问题
   错误: 连接超时

解决方案:检查网络连接,或使用代理

性能优化

  1. 图片预处理
   from PIL import Image
   
   def preprocess_image(image_path, max_size=800):
       """预处理图片以优化OCR"""
       img = Image.open(image_path)
       
       # 调整大小
       if max(img.size) > max_size:
           ratio = max_size / max(img.size)
           new_size = tuple(int(dim * ratio) for dim in img.size)
           img = img.resize(new_size, Image.Resampling.LANCZOS)
       
       # 转换为RGB(如果不是)
       if img.mode != 'RGB':
           img = img.convert('RGB')
       
       # 保存临时文件
       temp_path = 'temp_processed.jpg'
       img.save(temp_path, 'JPEG', quality=85)
       
       return temp_path
  1. 使用本地缓存
   import hashlib
   import json
   import os
   
   class CachedOCR(OnlineOCR):
       def __init__(self, cache_dir='.ocr_cache', **kwargs):
           super().__init__(**kwargs)
           self.cache_dir = cache_dir
           if not os.path.exists(cache_dir):
               os.makedirs(cache_dir)
       
       def ocr_from_file(self, image_path, language='chs'):
           # 生成缓存键
           with open(image_path, 'rb') as f:
               file_hash = hashlib.md5(f.read()).hexdigest()
           
           cache_key = f"{file_hash}_{language}"
           cache_file = os.path.join(self.cache_dir, f"{cache_key}.json")
           
           # 检查缓存
           if os.path.exists(cache_file):
               with open(cache_file, 'r', encoding='utf-8') as f:
                   return json.load(f)['text']
           
           # 调用API
           text = super().ocr_from_file(image_path, language)
           
           # 保存缓存
           with open(cache_file, 'w', encoding='utf-8') as f:
               json.dump({'text': text, 'language': language}, f)
           
           return text

许可证

MIT License

支持

  • OCR.space API文档:https://ocr.space/ocrapi
  • 问题反馈:创建GitHub Issue
  • 功能建议:欢迎贡献代码

适合场景

01

OpenClaw 用户查找和安装 Skill 时

02

用户想查找某类 Agent Skill 时

03

需要根据任务场景推荐可安装能力包时

04

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

OpenClaw

81.84%
按下载量换算721

安全审计

VirusTotal

通过

ClawScan

通过

Static analysis

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills