2014-09-18

【高精度】オープンソースで文字認識!『tesseract』

no_image.jpg

[ PR ]


文字認識(OCR)は、誰もが一度は使ったことがありますよね。

そんなOCRがオープンソースであったら…、なんて思いませんか?

実は、Googleが開発した、『tesseract』というツールがあるんです。

使い方

(1) まずはインストール。簡単ですね。

brew install tesseract

(2) 認識させる画像を準備します。

> helloworld-ocr.png:

helloworld-ocr2.png

(3) 早速認識させてみます。

tesseract helloworld-ocr.png -psm 7 hello-report
cat hello-report.txt

# Hello, World

きちんと認識できたようですね。

(4) パラメータの意味

先程のコマンドの意味は、

tesseract [image file] (-psm [mode]) (-lang [lang]) [output text]

という書式で、例えば -psm [mode] の種類は以下のようになっています。

0 = Orientation and script detection (OSD) only.
    (向きと手書き文字(?)のみ認識《OSD》)

1 = Automatic page segmentation with OSD.
    (《OSD》+自動でページの切り替えを判断)

2 = Automatic page segmentation, but no OSD, or OCR
    (《OCR》+自動でページの切り替えを判断)

3 = Fully automatic page segmentation, but no OSD. (Default)
    (完全自動でページの切り替えを判断(非OSD、デフォルト))

4 = Assume a single column of text of variable sizes.
    (可変サイズの1つの行として認識)

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.
    (1行の文字列として認識)

8 = Treat the image as a single word.
    (1単語として認識)

9 = Treat the image as a single word in a circle
    (円の中に入った1単語として認識)

10 = Treat the image as a single character.
    (1文字として認識)

認識ができないケース

  • 文字色が薄い
  • 背景が濃い
  • 手書き文字の一部
  • 特殊なフォント
  • 色付き文字
  • 変形文字
  • ASCII文字以外

まとめ

是非活用して下さい。私はユニットテストに使っています。

コメントはTwitterアカウントにお願いします。

RECENT POSTS


[ PR ]

.