Commit c38060d5 authored by myhloli's avatar myhloli
Browse files

fix(boxbase): handle cases where bounding box area is zero

- Add a check to return 0 when either bbox1_area or bbox2_area is zero
- This prevents division by zero errors when calculating IoU
parent 1d08865f
...@@ -185,10 +185,13 @@ def calculate_iou(bbox1, bbox2): ...@@ -185,10 +185,13 @@ def calculate_iou(bbox1, bbox2):
bbox1_area = (bbox1[2] - bbox1[0]) * (bbox1[3] - bbox1[1]) bbox1_area = (bbox1[2] - bbox1[0]) * (bbox1[3] - bbox1[1])
bbox2_area = (bbox2[2] - bbox2[0]) * (bbox2[3] - bbox2[1]) bbox2_area = (bbox2[2] - bbox2[0]) * (bbox2[3] - bbox2[1])
if any([bbox1_area == 0, bbox2_area == 0]):
return 0
# Compute the intersection over union by taking the intersection area # Compute the intersection over union by taking the intersection area
# and dividing it by the sum of both areas minus the intersection area # and dividing it by the sum of both areas minus the intersection area
iou = intersection_area / float(bbox1_area + bbox2_area - iou = intersection_area / float(bbox1_area + bbox2_area - intersection_area)
intersection_area)
return iou return iou
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment