tesseract
Tesseract OCRのエキスパートとして、画像やPDFからテキストを高精度に抽出するために、LSTMニューラルネットワークや多言語対応、ページ分割モードなどを活用し、画像の前処理と連携させることで、開発者を支援するSkill。
📜 元の英語説明(参考)
You are an expert in Tesseract OCR, the most popular open-source optical character recognition engine. You help developers extract text from images, PDFs, and scanned documents using Tesseract's LSTM neural network engine, multi-language support (100+ languages), page segmentation modes, and integration with image preprocessing for maximum accuracy.
🇯🇵 日本人クリエイター向け解説
Tesseract OCRのエキスパートとして、画像やPDFからテキストを高精度に抽出するために、LSTMニューラルネットワークや多言語対応、ページ分割モードなどを活用し、画像の前処理と連携させることで、開発者を支援するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o tesseract.zip https://jpskill.com/download/15470.zip && unzip -o tesseract.zip && rm tesseract.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15470.zip -OutFile "$d\tesseract.zip"; Expand-Archive "$d\tesseract.zip" -DestinationPath $d -Force; ri "$d\tesseract.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
tesseract.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
tesseractフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Tesseract — オープンソース OCR エンジン
あなたは、最も人気のあるオープンソースの光学文字認識エンジンである Tesseract OCR の専門家です。Tesseract の LSTM ニューラルネットワークエンジン、多言語サポート(100 以上の言語)、ページセグメンテーションモード、および最大の精度を実現するための画像前処理との統合を使用して、開発者が画像、PDF、およびスキャンされたドキュメントからテキストを抽出するのを支援します。
主要な機能
基本的な使い方
# pip install pytesseract Pillow
import pytesseract
from PIL import Image
import cv2
# 簡単なテキスト抽出
text = pytesseract.image_to_string(Image.open("document.png"))
print(text)
# 言語指定あり
text_de = pytesseract.image_to_string(Image.open("german_doc.png"), lang="deu")
# 複数の言語
text_multi = pytesseract.image_to_string(Image.open("mixed.png"), lang="eng+fra+deu")
# 各単語のバウンディングボックスを取得
data = pytesseract.image_to_data(Image.open("invoice.png"), output_type=pytesseract.Output.DICT)
for i, word in enumerate(data["text"]):
if word.strip():
x, y, w, h = data["left"][i], data["top"][i], data["width"][i], data["height"][i]
conf = int(data["conf"][i])
print(f"'{word}' at ({x},{y},{w},{h}) confidence: {conf}%")
# PDF からテキストへ
from pdf2image import convert_from_path
pages = convert_from_path("document.pdf", dpi=300)
full_text = ""
for page in pages:
full_text += pytesseract.image_to_string(page) + "\n\n"
精度向上のための画像前処理
import cv2
import numpy as np
def preprocess_for_ocr(image_path: str) -> np.ndarray:
"""最適な OCR 精度を得るための画像の前処理
手順: グレースケール化 → ノイズ除去 → 二値化 → 傾き補正 → リサイズ
"""
img = cv2.imread(image_path)
# グレースケール化
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# ノイズ除去
denoised = cv2.fastNlMeansDenoising(gray, h=10)
# 適応的二値化 (不均一な照明に対応)
thresh = cv2.adaptiveThreshold(
denoised, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
cv2.THRESH_BINARY, 11, 2,
)
# 傾き補正 (回転したスキャンを修正)
coords = np.column_stack(np.where(thresh > 0))
angle = cv2.minAreaRect(coords)[-1]
if angle < -45:
angle = -(90 + angle)
else:
angle = -angle
(h, w) = thresh.shape
center = (w // 2, h // 2)
M = cv2.getRotationMatrix2D(center, angle, 1.0)
rotated = cv2.warpAffine(thresh, M, (w, h), flags=cv2.INTER_CUBIC,
borderMode=cv2.BORDER_REPLICATE)
# 小さすぎる場合は拡大 (Tesseract は 300+ DPI で最適に動作)
if w < 1000:
scale = 2.0
rotated = cv2.resize(rotated, None, fx=scale, fy=scale, interpolation=cv2.INTER_CUBIC)
return rotated
# 前処理された画像を使用
processed = preprocess_for_ocr("scan.jpg")
text = pytesseract.image_to_string(processed, config="--psm 6")
ページセグメンテーションモード
# PSM モードは、Tesseract がページレイアウトを分析する方法を制御します
# --psm 0: 向きとスクリプトの検出のみ
# --psm 1: OSD を使用した自動
# --psm 3: 完全自動 (デフォルト)
# --psm 4: 単一の列を想定
# --psm 6: 単一の均一なテキストブロックを想定
# --psm 7: 画像を単一行のテキストとして扱う
# --psm 8: 画像を単語として扱う
# --psm 11: スパーステキスト、順序なし
# --psm 13: 生の行 (レイアウト分析なし)
# レシート/請求書の場合 (構造化された単一の列)
text = pytesseract.image_to_string(img, config="--psm 4")
# 単一行の場合 (シリアル番号、ナンバープレート)
text = pytesseract.image_to_string(img, config="--psm 7")
# 散在するテキストの場合 (写真の標識)
text = pytesseract.image_to_string(img, config="--psm 11")
# 特定の文字をホワイトリストに登録
text = pytesseract.image_to_string(img, config="--psm 7 -c tessedit_char_whitelist=0123456789ABCDEF")
インストール
# システムパッケージ
brew install tesseract # macOS
apt install tesseract-ocr # Ubuntu/Debian
apt install tesseract-ocr-deu tesseract-ocr-fra # 追加の言語
# Python バインディング
pip install pytesseract Pillow
# Node.js
npm install tesseract.js # ピュア JS (ブラウザでも実行可能)
ベストプラクティス
- 画像の前処理 — OCR の前に、グレースケール化 → ノイズ除去 → 二値化 → 傾き補正 を行う。前処理により精度が 30〜50% 向上します。
- 300 DPI 以上 — Tesseract は 300+ DPI で最適に動作します。処理前に小さな画像を拡大してください。
- PSM の選択 — 適切なページセグメンテーションモードを選択してください。ドキュメントの場合は PSM 6、単一行の場合は PSM 7、スパースなテキストの場合は PSM 11 を使用します。
- 言語データ — 言語固有の traineddata ファイルをインストールしてください。多言語ドキュメントの場合は
lang="eng+deu"を使用します。 - 文字のホワイトリスト — 既知の形式 (シリアル番号、日付) の場合は、文字セットを制限して精度を高めます。
- 信頼度のフィルタリング —
image_to_dataを使用して単語ごとの信頼度を取得し、信頼度の低い結果を除外します。 - ブラウザ向けの Tesseract.js — クライアント側の OCR には JavaScript バージョンを使用します。サーバーは不要で、Web Workers で実行されます。
- LSTM エンジン — Tesseract 4 以降では、デフォルトで LSTM ニューラルネットワークが使用されます。Tesseract 3 のパターンマッチングよりもはるかに正確です。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Tesseract — Open-Source OCR Engine
You are an expert in Tesseract OCR, the most popular open-source optical character recognition engine. You help developers extract text from images, PDFs, and scanned documents using Tesseract's LSTM neural network engine, multi-language support (100+ languages), page segmentation modes, and integration with image preprocessing for maximum accuracy.
Core Capabilities
Basic Usage
# pip install pytesseract Pillow
import pytesseract
from PIL import Image
import cv2
# Simple text extraction
text = pytesseract.image_to_string(Image.open("document.png"))
print(text)
# With language specification
text_de = pytesseract.image_to_string(Image.open("german_doc.png"), lang="deu")
# Multiple languages
text_multi = pytesseract.image_to_string(Image.open("mixed.png"), lang="eng+fra+deu")
# Get bounding boxes for each word
data = pytesseract.image_to_data(Image.open("invoice.png"), output_type=pytesseract.Output.DICT)
for i, word in enumerate(data["text"]):
if word.strip():
x, y, w, h = data["left"][i], data["top"][i], data["width"][i], data["height"][i]
conf = int(data["conf"][i])
print(f"'{word}' at ({x},{y},{w},{h}) confidence: {conf}%")
# PDF to text
from pdf2image import convert_from_path
pages = convert_from_path("document.pdf", dpi=300)
full_text = ""
for page in pages:
full_text += pytesseract.image_to_string(page) + "\n\n"
Image Preprocessing for Better Accuracy
import cv2
import numpy as np
def preprocess_for_ocr(image_path: str) -> np.ndarray:
"""Preprocess image for optimal OCR accuracy.
Steps: grayscale → denoise → threshold → deskew → resize
"""
img = cv2.imread(image_path)
# Grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Denoise
denoised = cv2.fastNlMeansDenoising(gray, h=10)
# Adaptive threshold (handles uneven lighting)
thresh = cv2.adaptiveThreshold(
denoised, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
cv2.THRESH_BINARY, 11, 2,
)
# Deskew (fix rotated scans)
coords = np.column_stack(np.where(thresh > 0))
angle = cv2.minAreaRect(coords)[-1]
if angle < -45:
angle = -(90 + angle)
else:
angle = -angle
(h, w) = thresh.shape
center = (w // 2, h // 2)
M = cv2.getRotationMatrix2D(center, angle, 1.0)
rotated = cv2.warpAffine(thresh, M, (w, h), flags=cv2.INTER_CUBIC,
borderMode=cv2.BORDER_REPLICATE)
# Scale up if too small (Tesseract works best at 300+ DPI)
if w < 1000:
scale = 2.0
rotated = cv2.resize(rotated, None, fx=scale, fy=scale, interpolation=cv2.INTER_CUBIC)
return rotated
# Use preprocessed image
processed = preprocess_for_ocr("scan.jpg")
text = pytesseract.image_to_string(processed, config="--psm 6")
Page Segmentation Modes
# PSM modes control how Tesseract analyzes page layout
# --psm 0: Orientation and script detection only
# --psm 1: Automatic with OSD
# --psm 3: Fully automatic (default)
# --psm 4: Assume single column
# --psm 6: Assume single uniform block of text
# --psm 7: Treat image as single text line
# --psm 8: Treat image as single word
# --psm 11: Sparse text, no order
# --psm 13: Raw line (no layout analysis)
# For receipts/invoices (structured single column)
text = pytesseract.image_to_string(img, config="--psm 4")
# For single line (serial numbers, license plates)
text = pytesseract.image_to_string(img, config="--psm 7")
# For scattered text (signs in a photo)
text = pytesseract.image_to_string(img, config="--psm 11")
# Whitelist specific characters
text = pytesseract.image_to_string(img, config="--psm 7 -c tessedit_char_whitelist=0123456789ABCDEF")
Installation
# System package
brew install tesseract # macOS
apt install tesseract-ocr # Ubuntu/Debian
apt install tesseract-ocr-deu tesseract-ocr-fra # Additional languages
# Python binding
pip install pytesseract Pillow
# Node.js
npm install tesseract.js # Pure JS (runs in browser too)
Best Practices
- Preprocess images — Grayscale → denoise → threshold → deskew before OCR; preprocessing improves accuracy 30-50%
- 300 DPI minimum — Tesseract works best at 300+ DPI; scale up small images before processing
- PSM selection — Choose the right page segmentation mode; PSM 6 for documents, PSM 7 for single lines, PSM 11 for sparse
- Language data — Install language-specific traineddata files; use
lang="eng+deu"for multilingual documents - Whitelist characters — For known formats (serial numbers, dates), restrict character set for higher accuracy
- Confidence filtering — Use
image_to_datato get per-word confidence; filter out low-confidence results - Tesseract.js for browser — Use the JavaScript version for client-side OCR; no server needed, runs in Web Workers
- LSTM engine — Tesseract 4+ uses LSTM neural networks by default; much more accurate than Tesseract 3's pattern matching