MCPcopy Create free account
hub / github.com/BIT-DataLab/Edit-Banana / calculate_iou

Function calculate_iou

modules/basic_shape_processor.py:163–181  ·  view source on GitHub ↗

计算两个矩形框的 IoU

(box1: list, box2: list)

Source from the content-addressed store, hash-verified

161
162# ======================== IoU计算 ========================
163def calculate_iou(box1: list, box2: list) -> float:
164 """计算两个矩形框的 IoU"""
165 x_left = max(box1[0], box2[0])
166 y_top = max(box1[1], box2[1])
167 x_right = min(box1[2], box2[2])
168 y_bottom = min(box1[3], box2[3])
169
170 if x_right < x_left or y_bottom < y_top:
171 return 0.0
172
173 intersection_area = (x_right - x_left) * (y_bottom - y_top)
174 box1_area = (box1[2] - box1[0]) * (box1[3] - box1[1])
175 box2_area = (box2[2] - box2[0]) * (box2[3] - box2[1])
176 union_area = box1_area + box2_area - intersection_area
177
178 if union_area <= 0:
179 return 0.0
180
181 return intersection_area / union_area
182
183
184# ======================== 边框宽度检测 ========================

Callers 1

detect_rectangles_robustFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected