2
0

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 1 year has passed since last update.

コードが書かれた画像や服に書いてあるコードを読み込むアプリを作ってみた草

Posted at

「プログラミング フリー画像」で検索するとヒットする画像。こんなの↓
フリー素材.jpeg

や、Amazonにあるこんな服
clothes3.jpeg

に書いてあるコードを読み取りテキスト化するアプリを作成してみました。
30分程でざっと作成したので精度は粗いです。
勇者は精度を高めるようなコントリビュートをお願いします。
敬具

構成

言語:Python3.11.3
仮想環境:venv

ディレクトリ構成は下記の通り

text_reading_app/
├ image
│ └ clothes.py
app.py
pyvenv.cfg
README.md

・app.py
メインのアプリケーション。
画像を読み取り、テキストを抽出する。
OpenCVで画像を読み取り、Tesseract OCRで画像からテキストを抽出する。

・image/
画像のディレクトリ

環境構築

仮想環境を作成します

python -m venv .

仮想環境を有効化します

source bin/activate

必要なライブラリをインストールします

pip install opencv-python tesseract

コード

app.py
import cv2
import pytesseract

def reading_image(image_path):
    # 画像を読み込む
    image = cv2.imread(image_path)

    # 画像をグレースケールに変換する
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    # ノイズを軽減するために画像をぼかす
    blurred = cv2.GaussianBlur(gray, (3, 3), 0)

    # 画像からテキストを抽出する
    text = pytesseract.image_to_string(blurred, lang='eng')

    return text

# 画像からテキストを抽出する
image_path = 'image/clothes.jpeg'
text = reading_image(image_path)

print(text)

GitHubに挙げています

2
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?