ocr について
Tesseract を使い、ローカル画像や画像 URL から文字を抽出する OCR スキルです。複数言語に対応し、前処理や信頼度スコア付きのテキスト・JSON 出力を選べます。
主な機能
- 01一般的な画像形式の OCR
- 02100 以上の言語に対応
- 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 対応