5-3. 로직 구현 코드
V1.
# V1.
""" overlap_threshold : 객체 검출 Bbox와 바다영역 분할 Mask가 상호 겹치는 정도 (단위 %) """
def check_overlap(bbox: List[float], mask_polygon: Polygon, overlap_threshold: float = 0.2) -> bool:
'''Check if bbox and mask polygon overlap significantly.'''
bbox_polygon = box(bbox[0], bbox[1], bbox[0] + bbox[2], bbox[1] + bbox[3])
intersection_area = bbox_polygon.intersection(mask_polygon).area
return (intersection_area / bbox_polygon.area > overlap_threshold or
intersection_area / mask_polygon.area > overlap_threshold)V2.
# V2.
""" overlap_threshold : 객체 검출 Bbox와 바다영역 분할 Mask가 상호 겹치는 정도 (단위 %) """
def check_overlap_or_touch(bbox: List[float], mask_polygon: Polygon, overlap_threshold: float = 0.0) -> bool:
bbox_polygon = box(bbox[0], bbox[1], bbox[0] + bbox[2], bbox[1] + bbox[3])
intersection_area = bbox_polygon.intersection(mask_polygon).area
bbox_area = bbox_polygon.area
mask_area = mask_polygon.area
return (intersection_area / bbox_area > overlap_threshold or
intersection_area / mask_area > overlap_threshold or
bbox_polygon.touches(mask_polygon))V3.
V4.
GitHub
[참고] 로직별 Threshold 설정
Last updated