关于 ocr
使用 Tesseract 从本地图像或图像 URL 提取文字的 OCR Skill,支持多种语言、可选预处理,以及文本或带置信度分数的 JSON 输出。
主要功能
- 01识别常见图像格式
- 02支持 100 多种语言
- 03可选灰度与阈值预处理
- 04输出文本或带置信度分数的 JSON
适用场景
- 01从扫描图像提取文字
- 02识别图像 URL 中的文字
- 03将多语言 OCR 结果保存为文本或 JSON
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ trpc-group/ trpc-agent-go --skill ocr安装后在 Claude Code 中输入/ocr确认已加载。
附带文件scripts/ocr_url.pyscripts/ocr.py
详细介绍
OCR 图像文本提取工具
使用 Tesseract OCR 引擎从图像中提取文本。
功能
- 从图像文件中提取文本(PNG、JPG、JPEG、GIF、BMP、TIFF)
- 支持 100 多种语言
- 可选图像预处理,以提高准确度
- 输出为纯文本或 JSON 格式,并附带置信度分数
用法
基本 OCR
python3 scripts/ocr.py <image_file> <output_file>
使用选项
# Specify language (default: eng)
python3 scripts/ocr.py image.png text.txt --lang eng
# Chinese text
python3 scripts/ocr.py image.png text.txt --lang chi_sim
# Multiple languages
python3 scripts/ocr.py image.png text.txt --lang eng+chi_sim
# With image preprocessing (improves accuracy)
python3 scripts/ocr.py image.png text.txt --preprocess
# JSON output with confidence scores
python3 scripts/ocr.py image.png output.json --format json
从 URL 下载并进行 OCR
# OCR from remote image
python3 scripts/ocr_url.py <image_url> <output_file>
# With options
python3 scripts/ocr_url.py https://example.com/image.jpg text.txt --lang eng --preprocess
参数
image_file/image_url(必填):本地图像路径或图像 URLoutput_file(必填):输出文本/JSON 文件的路径--lang:语言代码(例如 eng、chi_sim、jpn、fra、deu)。默认值:eng--preprocess:应用图像预处理(灰度化、阈值处理),以提高准确度--format:输出格式(text/json,默认值:text)
常用语言
| 语言 | 代码 |
|---|---|
| 英语 | eng |
| 简体中文 | chi_sim |
| 繁体中文 | chi_tra |
| 日语 | jpn |
| 韩语 | kor |
| 法语 | fra |
| 德语 | deu |
| 西班牙语 | spa |
| 俄语 | rus |
| 阿拉伯语 | ara |
支持的图像格式
PNG、JPG、JPEG、GIF、BMP、TIFF、WEBP
依赖项
- Python 3.8+
- pytesseract
- Pillow(PIL)
- tesseract-ocr(系统软件包)
安装
# Python packages
pip install pytesseract Pillow
# Tesseract OCR engine
sudo apt-get install tesseract-ocr # Ubuntu/Debian
sudo yum install tesseract # CentOS/RHEL
brew install tesseract # macOS
评论
支持 Markdown