LoginSignup
6
7

More than 3 years have passed since last update.

pytesseract 概要と使い方 メモ

Posted at
  • pytesseractの概要と使用方法についてメモする。

pytesseract 概要

  • OCRツールTesseractのPythonラッパー。

  • PillowNumPyなどの形式で解析対象データを受け取ることが可能。

  • コマンド呼び出しで実行。

インストール

  • pipコマンドを使用し、インストールする。
pip install pytesseract

※必要に応じて解析データの読み込み用途でPillowなどもインストールする。

tesseract本体も必要。Linux環境などではapt-get -y install tesseract-ocr tesseract-ocr-jpnでインストールしておく。

使用方法

  • Pythonコード
from pytesseract import pytesseract
from PIL import Image

# 読み込み対象ファイルの指定
img = Image.open("./test.png, "r")
# tesseractコマンドのインストールパス
pytesseract.tesseract_cmd = "/usr/bin/tesseract"
# 文字列として出力できる。
ocr_result = pytesseract.image_to_string(img, lang="eng+jpn")

参考情報

6
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
6
7