5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

tesseractで文字認識

Last updated at Posted at 2019-07-20

##環境

.
Miniconda
python 3.7
windows

##tesseractの導入
バージョン4.0系からニューラルネットワークを採用し精度が向上しています。

ancondaにtesseractを入れる場合は、コマンドに以下を入力すればokです。
もし、anacondaを使っていて、できない場合はこちらを参考にしてください。

conda install -c conda-forge tesseract

anacondaを使ってない場合は、tesseractをインストールして、パスを通す。

ちゃんと使えるかは以下をコマンドに入力してください。
バージョンが返ってこればokです。

.command
tesseract -v
>>tesseract 4.1.0

##言語追加
以下をコマンドに入力して、jpnがでなければ[こちら]からjpn.traineddataをダウンロードしてください。
jpn.traineddataを

\Users***\Miniconda3\envs\my_env\Library\bin\tessdata
```に置いてください。



```.commnad
tesseract --list-langs
.
List of available languages (3):
eng
jpn
osd

↑のようになっていればokです。

日本語以外も追加可能です。

##PyOCRの導入

terminal.
pip install pyocr

##実行してみる

.py
from PIL import Image
import sys
import pyocr
import pyocr.builders

tools = pyocr.get_available_tools()
if len(tools) == 0:
    print("No OCR tool found")
    sys.exit(1)

tool = tools[0]

#言語、オプションの指定をする
txt = tool.image_to_string( 
    Image.open('IMG_5.png'),
    lang='jpn',
    builder=pyocr.builders.TextBuilder()
)
print(txt)
2019-11-09 (1).png
.
乃 木 坂 ④⑥・ 齋 藤 飛 鳥 の ①st 写 真 集 『 潮 騒 』 ( 幻 冬 舎 )
が 、 最 新 の ⑪/①① 付 オ リ コ ン 週 間 BOOK ラ ン キ ン グ ジ ャ
ン ル 別 ` 写 真 集 」 で ③④ 位 に ラ ン ク イ ン 。②0①⑦ 年 ① 月 の 発
売 か ら ② 年 ①0 ヶ 月 を 経 た 現 在 ち ラ ン キ ン グ 圏 内 を 推 移 。 好
調 な 乃 木 坂 ④⑥ メ ン バ ー の ソ ロ 写 真 集 の な か で も 数 少 な い
超 ロ ン グ ヒ ッ ト と な り 、 累 計 売 上 部 数 は ⑲.③ 万 部 を 超
え 、②0 万 部 目 前 ま で 迫 っ て い る 。

【 写 真 】 そ の 他 の 写 真 を 見 る

⑪/①① 付 の 同 ラ ン キ ン グ 内 を 見 る と 、 乃 木 坂 ④⑥ メ ン バ
ー の ソ ロ 写 真 集 の な か で 発 売 日 が ち っ と も 早 い の が 齋 膳
飛 鳥 の 『 潮 騒 』 と な り 、 次 い で ⑳①⑦ 年 ② 月 発 売 の 白 石 麻
衣 の 『 パ ス ポ ー ト 』 ( 講 談 社 ) 。 『 パ ス ポ ー ト 』 は 、 ジ
ヤ ン ル 別 ` 写 真 集 」 歴 代 ② 位 、 ソ ロ 写 真 集 と し て は 歴 代 ①
位 と な り 、 現 在 累 計 売 上 は ③③.⑥ 万 部 を 超 え て い る 。

数字の認識はいまいちですけど、他は高い確率で認識できていると思います。

##参考
Python3系でtesseractを使ってOCRをやってみる
【PyOCR】画像から日本語の文字データを抽出する

間違いがありましたら、編集リクエストをお願いします。

5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?