Statistical Programming

文字認識らいぶらり。。。tesseract!!

小説の画像を文字認識できんかなと思いぐぐってみたらGoogle先生が文字認識ライブラリをオープンソースで提供なさっているので試してみました。インストールはいつものごとくhomebrewを利用しました。コマンドラインを開き、

brew install tesseract

インストールが終了したら早速起動してみたいと思います。とりあえずtesseract と打ち込むと

Usage:tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfile...]

 

pagesegmode values are:

0 = Orientation and script detection (OSD) only.

1 = Automatic page segmentation with OSD.

2 = Automatic page segmentation, but no OSD, or OCR

3 = Fully automatic page segmentation, but no OSD. (Default)

4 = Assume a single column of text of variable sizes.

5 = Assume a single uniform block of vertically aligned text.

6 = Assume a single uniform block of text.

7 = Treat the image as a single text line.

8 = Treat the image as a single word.

9 = Treat the image as a single word in a circle.

10 = Treat the image as a single character.

-l lang and/or -psm pagesegmode must occur before anyconfigfile.

 

Single options:

  -v --version: version info

 

  --list-langs: list available languages for tesseract engine

などとおっしゃっているのでどんな感じでうてばいいのかなーとか見てみると、どうやら

tessseract + 画像ファイル名 + アウトプットファイル名 + 言語指定 + その他必要なら

例えば。。。

tesseract input.jpg output -l jpn

結果output.txtというファイルが同ディレクトリに作成されるというわけです。 

※精度は正直微妙です。僕の場合小説の1ページから全ての文字を抽出したいなと思ってこのライブラリへたどり着いたわけですがまあ読めるものではなかったです…