辞書を読む

辞書を読んでいくストイックなブログです。

スキャンした文字をデジタル文字に変換|Tesseract OCRを使う

持っている本をデジタル化したい、とは多くの蔵書家が思うことだと思います。特に自分用のノートを作る際には、デジタル化が簡単にできるととてもはかどります。

ここで私の悪戦苦闘記を書いて行きます。

Tesseract OCRのインストール

ダウンロードとインストール

Googleが提供しているTesseract OCRというフリーソフトがあります。それをインストールします。

UB-Menheim/tesseractのページから32bitか64bit、ご自身のPCにあったものをダウンロードしてインストールしてください。インストール途中でAdditional Script DataとAdditional Language Dataが追加できるので、日本語や自分が使う言語を選んでください。

以下のところが参考になると思います。

パスを通す

このまま、Windowsキー+rで「ファイル名を指定して実行」を起動し、cmdと入力してEnterを押すとコマンドプロンプトが起動します。このままtesseractと打つと以下のようになります。

C:\Users\***>tesseract
'tesseract' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。

「C:\Tesseract-OCR」のフォルダにインストールと仮定して、PATHを通します。

コントロール パネル\システムとセキュリティ\システムから「システムの詳細設定」をクリック。

環境変数の設定

システム環境のPathを選んで「編集」をクリックし、半角セミコロン(;)で区切ってから「C:\Tesseract-OCR」と入力し、保存します。

Pathを通す

もう一度コマンドプロンプトを起動して、「tesseract」と入力します。

C:\Users\***>tesseract
Usage:
  tesseract --help | --help-extra | --version
  tesseract --list-langs
  tesseract imagename outputbase [options...] [configfile...]

OCR options:
  -l LANG[+LANG]        Specify language(s) used for OCR.
NOTE: These options must occur before any configfile.

Single options:
  --help                Show this help message.
  --help-extra          Show extra help for advanced users.
  --version             Show version information.
  --list-langs          List available languages for tesseract engine.

それでは文字を読んでいきましょう。

たとえばOxford English Dictionary、通称OEDの初版の一部ページを読み込みます。

OED First Edition

出典:

public.oed.com

Tesseract OCRは「tesseract 画像ファイル名 出力ファイル名 -l 言語」と書いて動かします。具体的には以下の通り動かしました。

C:\Users\***\Desktop>tesseract oed.png oed -l eng
THE VOCABULARY.

Tue Vocabulary of a widely-diffused and highly-cultivated living language is not a fixed quantity circumscribed by
definite limits. That vast aggregate of words and phrases which constitutes the Vocabulary of English-speaking men
presents, to the mind that endeavours to grasp it as a definite whole, the aspect of one of those nebulous masses familiar to
the astronomer, in which a clear and unmistakable nucleus shades off on all sides, through zones of decreasing brightness,
to a dim marginal film that seems to end nowhere, but to lose itself imperceptibly in the surrounding darkness. In its
constitution it may be compared to one of those natural groups of the zoologist or botanist, wherein typical species,
forming the characteristic nucleus of the order, are linked on every side to other species, in which the typical character is
less and less distinctly apparent, till it fades away in an outer fringe of aberrant forms, which merge imperceptibly in
various surrounding orders, and whose own position is ambiguous and uncertain. For the convenience of classification,
the naturalist may draw the line, which bounds a class or order, outside or inside of a particular form; but Nature has
drawn it nowhere. So the English Vocabulary contains a nucleus or central mass of many thousand words whose
‘Anglicity’ is unquestioned ; some of them only literary, some of them only colloquial, the great majority at once literary
and colloquial,—they are the Common Words of the language. But they are linked on every side with other words which
are less and less entitled to this appellation, and which pertain ever more and more distinctly to the domain of local
dialect, of the slang and cant of ‘sets’ and classes, of the peculiar technicalities of trades and processes, of the scientific
terminology common to all civilized nations, of the actual languages of other lands and peoples. And there is absolutely
no defining line in any direction: the circle of the English language has a well-defined centre but no discernible

ほぼ成功、といえると思います。