コマンドラインの使い方
Tesseractのマニュアルページ
コマンドラインの詳細や構文については、マニュアルページをご覧ください。
よくある質問
詳細な例やヒントについては、よくある質問をご覧ください。
Tesseract 5で利用可能なOCRエンジン
LSTM/ニューラルネットワークには--oem 1
を、レガシTesseractには--oem 0
を使用します。
レガシTesseractモデルは、tessdataリポジトリから取得したトレーニングデータファイルにのみ含まれています。
tesseract input.tiff output --oem 1 -l eng
画像のOCRを実行するために最も簡単な呼び出し
tesseract imagename outputbase
これは、英語をデフォルトの言語として、ページセグメンテーションモードを3として使用します。デフォルトの出力形式はテキストです。
方向とセグメンテーションのためのosd.traineddata、および英語のためのeng.traineddataやその他の言語データファイルは、「tessdata」ディレクトリになければなりません。TESSDATA_PREFIX環境変数は、「tessdata」ディレクトリの親ディレクトリに設定する必要があります。
eng.traineddataファイルとosd.traineddataファイルが/usr/share/tessdataディレクトリにある場合、次のコマンドは上記と同じ結果になります。
tesseract --tessdata-dir /usr/share imagename outputbase -l eng --psm 3
次の例は、複数の言語でテキストが含まれているこの画像を使用します。
1つの言語を使用する
コマンドに「-l LANG」を追加します。LANGは、サポートされている言語のリストにある3文字の言語コードです。指定しない場合は、デフォルトで英語の言語が使用されます。
tesseract images/eurotext.png - -l eng
出力
The (quick) [brown] {fox} jumps!
Over the $43,456.78 <lazy> #90 dog
& duck/goose, as 12.5% of E-mail
from aspammer@website.com is spam.
Der ,schnelle” braune Fuchs springt
iiber den faulen Hund. Le renard brun
«rapide» saute par-dessus le chien
paresseux. La volpe marrone rapida
salta sopra il cane pigro. El zorro
marrén rapido salta sobre el perro
perezoso. A raposa marrom ripida
salta sobre o cdo preguigoso.
複数の言語を使用する
認識のために複数の言語を一緒に使用するには、-l LANG[+LANG]
をコマンドラインに追加します。
tesseract images/eurotext.png - -l eng+deu
出力
The (quick) [brown] {fox} jumps!
Over the $43,456.78 <lazy> #90 dog
& duck/goose, as 12.5% of E-mail
from aspammer@website.com is spam.
Der „schnelle” braune Fuchs springt
über den faulen Hund. Le renard brun
«rapide» saute par-dessus le chien
paresseux. La volpe marrone rapida
salta sopra il cane pigro. El zorro
marrén rapido salta sobre el perro
perezoso. A raposa marrom räpida
salta sobre o cdo preguigoso.
複数の言語の順序
OCRにかかる時間と出力は、言語の順序によって異なる場合があります。
次の例は、ヒンディー語と英語でテキストが含まれているこの画像を使用します。
一次言語として英語、次にヒンディー語を使用する
time tesseract images/bilingual.png - -l eng+hin
Estimating resolution as 638
हिंदी से अंग्रेजी
HINDI TO
ENGLISH
real 0m0.442s
user 0m0.622s
sys 0m0.062s
一次言語としてヒンディー語、次に英語を使用する
time tesseract images/bilingual.png - -l hin+eng
Estimating resolution as 638
हिंदी से अंग्रेजी
HINDI TO
ENGLISH
real 0m0.429s
user 0m0.550s
sys 0m0.074s
一次言語としてスクリプト/デーヴァナーガリーを使用する(デーヴァナーガリー文字と英語のすべての言語をサポート
time tesseract images/bilingual.png - -l script/Devanagari
Estimating resolution as 638
हिंदी से अंग्रेजी
HINDI TO
ENGLISH
real 0m0.391s
user 0m0.459s
sys 0m0.093s
メッセージを抑制するにはquiet
コンフィギュレーションを使用する
上記の最後のコマンドの後ろにquiet
を使用すると、画像の分解に関するメッセージが表示されなくなります。
time tesseract images/bilingual.png - -l script/Devanagari quiet
हिंदी से अंग्रेजी
HINDI TO
ENGLISH
real 0m0.416s
user 0m0.494s
sys 0m0.091s
検索可能なpdf出力
tesseract testing/eurotext.png testing/eurotext-eng -l eng pdf
これにより、画像と認識されたテキストを含む別の検索可能なテキストレイヤーを含むpdfが作成されます。
HOCR出力
コマンドの最後にhocrを追加して「hocr」コンフィギュレーションファイルを使用すると、HOCR出力が得られます。
tesseract images/eurotext.png - -l eng hocr
部分出力
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name='ocr-system' content='tesseract 5.0.1-64-g3c22' />
<meta name='ocr-capabilities' content='ocr_page ocr_carea ocr_par ocr_line ocrx_word ocrp_wconf'/>
</head>
<body>
<div class='ocr_page' id='page_1' title='image "images/eurotext.png"; bbox 0 0 640 500; ppageno 0; scan_res 300 300'>
<div class='ocr_carea' id='block_1_1' title="bbox 61 41 574 413">
<p class='ocr_par' id='par_1_1' lang='eng' title="bbox 61 41 574 413">
<span class='ocr_line' id='line_1_1' title="bbox 65 41 515 71; baseline 0.013 -11; x_size 25; x_descenders 5; x_ascenders 6">
<span class='ocrx_word' id='word_1_1' title='bbox 65 41 111 61; x_wconf 96'>The</span>
<span class='ocrx_word' id='word_1_2' title='bbox 128 42 217 66; x_wconf 95'>(quick)</span>
<span class='ocrx_word' id='word_1_3' title='bbox 235 43 330 68; x_wconf 95'>[brown]</span>
<span class='ocrx_word' id='word_1_4' title='bbox 349 44 415 69; x_wconf 94'>{fox}</span>
<span class='ocrx_word' id='word_1_5' title='bbox 429 45 515 71; x_wconf 96'>jumps!</span>
</span>
...
<span class='ocr_line' id='line_1_12' title="bbox 61 385 444 413; baseline 0.013 -9; x_size 24; x_descenders 4; x_ascenders 5">
<span class='ocrx_word' id='word_1_62' title='bbox 61 385 119 405; x_wconf 92'>salta</span>
<span class='ocrx_word' id='word_1_63' title='bbox 135 385 200 406; x_wconf 92'>sobre</span>
<span class='ocrx_word' id='word_1_64' title='bbox 216 392 229 406; x_wconf 83'>o</span>
<span class='ocrx_word' id='word_1_65' title='bbox 244 388 285 407; x_wconf 80'>cdo</span>
<span class='ocrx_word' id='word_1_66' title='bbox 300 388 444 413; x_wconf 92'>preguigoso.</span>
</span>
</p>
</div>
</div>
</body>
</html>
TSV出力
コマンドの最後にtsvを追加して「tsv」コンフィギュレーションファイルを使用すると、TSV出力が得られます。
tesseract images/eurotext.png - -l eng tsv
部分出力
level page_num block_num par_num line_num word_num left top width height conf text
1 1 0 0 0 0 0 0 640 500 -1
2 1 1 0 0 0 61 41 513 372 -1
3 1 1 1 0 0 61 41 513 372 -1
4 1 1 1 1 0 65 41 450 30 -1
5 1 1 1 1 1 65 41 46 20 96.063751 The
5 1 1 1 1 2 128 42 89 24 95.965691 (quick)
5 1 1 1 1 3 235 43 95 25 95.835831 [brown]
5 1 1 1 1 4 349 44 66 25 94.899742 {fox}
5 1 1 1 1 5 429 45 86 26 96.683357 jumps!
4 1 1 1 2 0 65 72 490 31 -1
5 1 1 1 2 1 65 72 60 20 96.912064 Over
5 1 1 1 2 2 140 73 37 20 96.887390 the
5 1 1 1 2 3 194 73 139 24 93.263031 $43,456.78
5 1 1 1 2 4 350 76 85 25 90.893219 <lazy>
5 1 1 1 2 5 451 77 44 19 96.820717 #90
5 1 1 1 2 6 511 78 44 25 96.538940 dog
4 1 1 1 3 0 64 103 458 26 -1
別のページセグメンテーションモードを使用する
–psm 3 - 完全自動ページセグメンテーション、ただしOSDはありません。(既定値)
次の例は、複数の列にテキストが含まれているこの画像を使用します。
tesseract images/2col.png - --psm 3
Cautionary Statement
ON FORWARD-LOOKING STATEMENTS: This presentation includes
information, statements, beliefs and opinions which are forward-looking, and
which reflect current estimates, expectations and projections about future
events, referred to herein as “forward-looking statements” within the meaning
of the U.S> Private Securities Litigation Reform Act of 1995 or “forward-looking
information” under applicable securities laws. Statements containing the words
“believe”, “expect”, “continue”, “could, “potential”, “predict”, “would”,
“intend”, “should”, “seek”, “anticipate”, ‘will’, “opportunity,” “positioned”,
“poised,” “project”, “risk”, “plan”, “may”, “estimate” or, in each case, their
Historical Information: Historical statements contained in this document
regarding past trends or activities should not be taken as a representation that
such trends or activities will continue in the future. In this regard, certain
financial information contained herein has been extracted from, or based upon,
information available in the public domain and/or provided by the Company. In
particular, historical results should not be taken as a representation that such
trends will be replicated in the future. No statement in this document is
intended to be nor may be construed as a profit forecast.
–psm 6 - 単一の均一なテキストブロックがあると想定します。
次の例は、目次があるこの画像を使用します。
tesseract images/toc.png - --psm 6
Contents
Introduction to the Tenth Anniversary Edition page xvii
Afterword to the Tenth Anniversary Edition xix
Preface xxi
Acknowledgements xxvii
Nomenclature and notation xxix
Part I Fundamental concepts 1
1 Introduction and overview 1
1.1 Global perspectives 1
1.11 History of quantum computation and quantum
information 2
1.1.2 Future directions 12
1.2 Quantum bits 13
1.2.1 Multiple qubits 16
1.3 Quantum computation 17
1.3.1 Single qubit gates 17
1.3.2 Multiple qubit gates 20
1.3.3 Measurements in bases other than the computational basis 2
1.34 Quantum circuits 2
1.3.5 Qubit copying circuit? 24
スペースを維持するには-c preserve_interword_spaces=1を使用します
tesseract images/toc.png - --psm 6 -c preserve_interword_spaces=1
Contents
Introduction to the Tenth Anniversary Edition page xvii
Afterword to the Tenth Anniversary Edition xix
Preface xxi
Acknowledgements xxvii
Nomenclature and notation xxix
Part I Fundamental concepts 1
1 Introduction and overview 1
1.1 Global perspectives 1
1.11 History of quantum computation and quantum
information 2
1.1.2 Future directions 12
1.2 Quantum bits 13
1.2.1 Multiple qubits 16
1.3 Quantum computation 17
1.3.1 Single qubit gates 17
1.3.2 Multiple qubit gates 20
1.3.3 Measurements in bases other than the computational basis 2
1.34 Quantum circuits 2
1.3.5 Qubit copying circuit? 24
テキスト出力のレイアウトを維持するにはpdftotextを使用する
tesseract images/toc.png images/toc -l eng –psm 11 pdf
pdftotext -layout images/toc.pdf -
Contents
Introduction to the Tenth Anniversary Edition page xvii
Afterword to the Tenth Anniversary Edition xix
Preface xxi
Acknowledgements xx
Nomenclature and notation xxix
Part I Fundamental concepts
1 Introduction and overview
1.1 Global perspectives
1.11 History of quantum computation and quantum
information
1.1.2 Future directions 12
12 Quantum bits 13
1.2.1 Multiple qubits 16
1.3 Quantum computation 17
Single qubit gates
2 Multiple qubit gates 20
Measurements in bases other than the computational basis 2
4 Quantum circu 2
5 Qubit copying circuit? 24