Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounding Box 확인하기 #6

Open
YJ0522771 opened this issue Mar 22, 2022 · 3 comments
Open

Bounding Box 확인하기 #6

YJ0522771 opened this issue Mar 22, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@YJ0522771
Copy link
Contributor

이미지에 bounding box를 그려서 예측 결과를 눈으로 확인해 볼 수 있도록 만들어 보았습니다.

코드

import numpy as np
import pandas as pd
import cv2
import os
import random
import matplotlib.pyplot as plt

# class 별 bbox 색
colors = [
    (255, 0, 0), 
    (0, 255, 0),
    (0, 0, 255),
    (127, 127, 0),
    (127, 0, 127),
    (0, 127, 127),
    (200, 200, 200),
    (50, 150, 200),
    (200, 155, 50),
    (130, 198, 20),
]
labels = {0: 'General trash', 1: 'Paper', 2: 'Paper pack', 3: 'Metal', 4: 'Glass', 5: 'Plastic', 6: 'Styrofoam', 7: 'Plastic bag', 8: 'Battery', 9: 'Clothing'}

# 이미지 경로
img_dir = './detection/dataset'
# output 파일 경로
output_dir = './detection/baseline/faster_rcnn/faster_rcnn_torchvision_epochs_30.csv'

test_result = pd.read_csv(output_dir)

file_names = test_result['image_id'].values.tolist()
bboxes = test_result['PredictionString'].values.tolist()

idx = random.choice(range(len(file_names)))
file_name = file_names[idx]
bbox = bboxes[idx].split()

image = cv2.imread(os.path.join(img_dir, file_name)).astype(np.uint8)
for i in range(0, len(bbox), 6):
    label = int(bbox[i])
    x_min = int(bbox[i + 2].split('.')[0])
    y_min = int(bbox[i + 3].split('.')[0])
    x_max = int(bbox[i + 4].split('.')[0])
    y_max = int(bbox[i + 5].split('.')[0])
    
    # bounding box 그리기
    image = cv2.rectangle(image, pt1=(x_min, y_min), pt2=(x_max, y_max), color=colors[label], thickness=5)
    # label text 넣기
    cv2.putText(image, labels[label], (x_min, y_min - 20), cv2.FONT_HERSHEY_SIMPLEX, 1, colors[label], 3)

plt.figure(figsize=(10,10))
plt.imshow(image)

예시

image

@YJ0522771 YJ0522771 added the enhancement New feature or request label Mar 22, 2022
@ed-kyu
Copy link
Contributor

ed-kyu commented Mar 22, 2022

감사합니다!

@kimkihoon0515
Copy link
Contributor

EDA에 좋은 자료네요 감사합니다.

@ysw2946
Copy link
Contributor

ysw2946 commented Mar 23, 2022

감사합니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants