M AI 员工技能商店
AI 员工平台 返回商城
返回技能商店

小紫 OCR 文字识别插件

v1.0.0 · 文档处理 · 官方

OCR 文字识别 扫描件 PDF 中文 小紫

简介

小紫 OCR 文字识别插件 v1.0,本地 OCR 提取图片与 PDF 扫描件中的文字:

  • recognize 单张图片或 PDF 扫描页 OCR
  • batch 批量识别多个文件或整个目录
  • info 检查 pip / Tesseract 环境是否就绪
  • 支持 Win / macOS / Linux,默认 中英文(chi_sim+eng)
  • 本地处理,不上传云端

与 pdf_tool 区别:

  • pdf_tool:PDF 里本身有可选文字层 → 直接 read
  • ocr_tool:扫描版 PDF、拍照、截图 → OCR 识图取字

安装两步:

  1. pip:pytesseract Pillow pymupdf
  2. 系统程序:Tesseract OCR(Windows 安装包 / Linux apt / macOS brew)

典型流程:info 检查环境 → recognize 识别单文件 → batch 批量导出 txt

操作说明

action功能
recognize单文件 OCR,支持图片和 PDF
batch批量 OCR,按目录或文件列表
info环境检测、语言列表、文件信息

支持格式: png/jpg/jpeg/bmp/tiff/webp/gif/pdf

recognize 参数:

  • filepath 必填
  • lang 默认 chi_sim+eng,可选 eng、chi_sim、jpn
  • pages PDF 页码如 1-3,5
  • dpi PDF 渲染精度,默认 200,识别差可试 300
  • max_chars 限制返回字数(AI 场景防超长)
  • output 导出 txt 路径
  • tesseract_cmd Windows 可指定 C:\Program Files\Tesseract-OCR\tesseract.exe

batch 参数:

  • filepaths JSON 数组,或 directory + pattern(如 *.png)
  • output_dir 批量导出 txt 目录

安装

  1. 解压到 D:\xiaozi-plugins\文档处理\OCR文字识别插件\
  2. 复制 python/ 到本目录
  3. 安装 pip 依赖:
   python\python.exe -m pip install pytesseract Pillow pymupdf
  1. 安装 Tesseract OCR:

- Windows:https://github.com/UB-Mannheim/tesseract/wiki(勾选 chi_sim)

- Linux:sudo apt install tesseract-ocr tesseract-ocr-chi-sim

- macOS:brew install tesseract tesseract-lang

  1. 测试:run.bat --action info
文件说明
ocr_plugin.py主程序
run.bat / run.sh启动脚本
OCR文字识别插件.md用户文档
config/ocr_config.example.json配置示例

命令行

run.bat --action info
run.bat --action recognize --filepath D:\scan\发票.jpg
run.bat --action recognize --filepath D:\scan\合同.pdf --pages 1-3 --output D:\scan\合同.txt
run.bat --action batch --directory D:\scan --pattern "*.jpg" --output_dir D:\scan\out
run.bat --action recognize --filepath D:\scan\doc.png --lang eng

注册技能 ocr_tool

名称: ocr_tool

描述: OCR v1.0:recognize/batch/info。图片和PDF扫描件OCR提取中英文。用户识别截图、扫描件、拍照文档时使用。需filepath。依赖Tesseract及pytesseract/Pillow/pymupdf。可选文字PDF请用pdf_tool。

脚本: D:\xiaozi-plugins\文档处理\OCR文字识别插件\run.bat

参数 JSON:

{
  "type": "object",
  "properties": {
    "action": {"type": "string", "enum": ["recognize", "batch", "info"], "description": "操作类型"},
    "filepath": {"type": "string", "description": "文件路径"},
    "filepaths": {"type": "string", "description": "batch JSON数组"},
    "directory": {"type": "string", "description": "batch目录"},
    "pattern": {"type": "string", "description": "batch匹配*.png"},
    "lang": {"type": "string", "description": "chi_sim+eng/eng"},
    "pages": {"type": "string", "description": "PDF页码"},
    "dpi": {"type": "string", "description": "PDF DPI默认200"},
    "max_chars": {"type": "string", "description": "最大字符数"},
    "output": {"type": "string", "description": "输出txt"},
    "output_dir": {"type": "string", "description": "batch输出目录"},
    "tesseract_cmd": {"type": "string", "description": "Tesseract路径"}
  },
  "required": ["action"]
}

对话示例

场景说法
识图识别 D:\scan\发票.jpg 里的文字
扫 PDF把 D:\scan\合同.pdf 前 3 页 OCR 成文字
批量批量识别 D:\scan 下所有 jpg,导出到 out 目录
查环境检查一下 OCR 是否可用
英文用英文识别这张 png

常见错误

现象处理
缺 pip 依赖pip install pytesseract Pillow pymupdf
未找到 Tesseract安装系统 Tesseract 或 tesseract_cmd 指定路径
无中文安装 chi_sim 语言包
PDF 效果差提高 dpi 300 或只 OCR 关键页
有文字层 PDF改用 pdf_tool read

能力边界

支持不支持
图片/PDF扫描 OCR手写高精度/表格结构化
中英文 batch云端 OCR API
本地隐私安全视频 OCR

与其他插件配合

  • pdf_tool:有文字层的 PDF 直接 read
  • file_convert:格式转换后再 OCR
  • word_tool:OCR 结果整理进 Word

详见包内 OCR文字识别插件.md。