Ccmmutty logo
Commutty IT
2
2 min read

主夫(主婦)支援アプリ~レシート認識アプリ編~①

https://cdn.magicode.io/media/notebox/e9ea8564-317f-4825-a957-fc25a81b6683.jpeg

1. Deep Layout Parsingについて

このチュートリアルでは、layoutparserAPIを使用します.
1.深層学習レイアウト検出モデルをロードし、紙の画像のレイアウトを予測します 2.座標系を使用して出力を解析します

2. Google Drive setting

from google.colab import drive
drive.mount('/content/drive')

3. 仮想環境の構築

!pip install --upgrade pip
!pip install layoutparser
!pip install Pillow
!pip install layoutparser torchvision && pip install "detectron2@git+https://github.com/facebookresearch/detectron2.git@v0.5#egg=detectron2"

4. Layout Models の実行

import layoutparser as lp
import cv2

import layoutparser as lp
model = lp.Detectron2LayoutModel(
            config_path ='lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config', # In model catalog
            label_map   ={0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"}, # In model`label_map`
            extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.8] # Optional
        )

4.1. 画像の読み込み

image = cv2.imread("/content/drive/MyDrive/PROJECT/201_HaMaruki/201.32_Layout_parser/layout-parser-main/datasets/IMG_20220705_192531.jpg")
image = image[..., ::-1] 
    # Convert the image from BGR (cv2 default loading style)
    # to RGB

4.2. レシートの認識

layout = model.detect(image)
    # Detect the layout of the input image

4.3. 認識結果の描画

lp.draw_box(image, layout, box_width=3)
    # Show the detected layout of the input image

Discussion

コメントにはログインが必要です。