LoginSignup
2
2

More than 3 years have passed since last update.

Tesseract OCR の使い方 (Python)

Posted at

次と同じことを Python3 で行いました。
Tesseract OCR の使い方

Arch Linux でのライブラリーのインストール

sudo pacman -S python-pyocr

プログラム

example01.py
#! /usr/bin/python
#
#   example01.py
#
#                       Jun/06/2019
# --------------------------------------------------------------------
from PIL import Image
import sys

import pyocr
import pyocr.builders

# --------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
tools = pyocr.get_available_tools()
if len(tools) == 0:
    print("No OCR tool found")
    sys.exit(1)
# The tools are returned in the recommended order of usage
tool = tools[0]
print("Will use tool '%s'" % (tool.get_name()))
#
txt = tool.image_to_string(
    Image.open('hensel_gretel.png'),
    lang="jpn",
    builder=pyocr.builders.TextBuilder()
)

print(txt)
#
sys.stderr.write("*** 終了 ***\n")
# --------------------------------------------------------------------

実行結果

$ ./example01.py 
*** 開始 ***
Will use tool 'Tesseract (sh)'
大 き な 思 の す ぐ 近 く に 、 本 と り か お か み さ ん と 侑
た ち と 一 細 に ほ ん で い ま し た 。 畑 の チ は ヘ ン ゼ ル で な
の 子 は ダ レ ー テ ル と い う 名 前 で し た 、 本 こ り に は ほ と
*** 終了 ***
2
2
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
2
2