layoutparser
APIを使用します.from google.colab import drive
drive.mount('/content/drive')
!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"
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
)
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
layout = model.detect(image)
# Detect the layout of the input image
lp.draw_box(image, layout, box_width=3)
# Show the detected layout of the input image