OBB
Axis-Aligned Bounding Box
- 일반적인 물체 탐지에서 사용하는 직사각형 박스. 항상 이미지 축에 평행
- 회전된 객체: 객체가 기울어져 있으면 AABB가 필요 이상으로 커짐
- 주변 객체와 과도하게 겹침
- 객체들이 서로 바싹 붙어 있거나 겹쳐 있을 때, 여러 객체가 하나의 상자 안에 포함될 수 있음
- 객체별 정확한 분리 어려움
- 정확한 위치 파악 어려움: 객체의 실제 방향성 정보 손실
Oriented Bounding Box
- 객체의 방향에 맞춰 회전 가능한 직사각형 박스.
- 일반적으로 중심점, 너비, 높이, 회전 각도로 표현.
- OBB의 필요성:
- 항공 사진의 건물, 차량, 선박 등 회전된 객체 탐지.
- 제조 공정에서 부품의 정확한 위치 및 방향 파악.
- 문서 이미지에서 텍스트 블록 탐지.
- 장점:
- 정확한 객체 영역 표현: 불필요한 배경 포함 감소.
- 겹치는 객체 분리 용이: 박스 간 IoU를 더 정확히 계산.
- 객체 방향 정보 제공: 후속 처리(예: 로봇 팔 제어)에 유용.
OBB 탐지
from ultralytics import YOLO
model = YOLO('yolo11n-obb.pt')
import cv2 as cv
img = cv.imread('boats.jpg')
results = model(img)
- 미세조정을 할 때는 Label Studio에서 내보내기 할 때 YOLOv8 OBB with Images 로
탐지 결과 시각화
from PIL import Image, ImageDraw, ImageFont
try:
font = ImageFont.truetype("NanumGothic.ttf", 20)
except IOError:
font = ImageFont.load_default()
import math
img_bbox = Image.fromarray(cv.cvtColor(img, cv.COLOR_BGR2RGB))
draw = ImageDraw.Draw(img_bbox)
result = results[0]
positions = result.obb.xyxyxyxy.cpu().numpy()
boxes = result.obb.xywhr.cpu().numpy()
clss = result.obb.cls.int().cpu().numpy()
confs = result.obb.conf.cpu().numpy()
for pos, box, cls, conf in zip(positions, boxes, clss, confs):
draw.polygon([tuple(p) for p in pos], outline="#00FF00", width=3)
name = result.names[cls]
label = f"{name}({conf:.2f})"
x, y, w, h, r_rad = box
arrow_length = w / 2.0
end_x = x + arrow_length * math.cos(r_rad)
end_y = y + arrow_length * math.sin(r_rad)
center_radius = 4
draw.ellipse(
(x - center_radius, y - center_radius, x + center_radius, y + center_radius),
fill="#FF0000"
)
draw.line(
[(x, y), (end_x, end_y)],
fill="#FF0000",
width=3)
text_position = tuple(pos[0])
draw.text(text_position, label, fill="#00FF00", font=font)
img_bbox