-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Search before asking
- I have searched the Supervision issues and found no similar feature requests.
Question
Hello everyone,
maybe someone can help me out. I’m facing the following challenge: In my scene, a truck drives into an area and moves toward an unloading zone (always exactly one truck). However, YOLO returns multiple detection boxes for the same truck — for example parts of the trailer, the cab, or parts of the cargo. In principle the detection works, but I’d like to merge these boxes into a single one since they all overlap anyway.
In Supervision, I found the function box_non_max_merge(), which I think could solve this problem. However, the function doesn’t expect a Detections object but rather a 2D array of object detection predictions.
My current approach looks like this:
import supervision as sv
from supervision.detection.core import merge_inner_detections_objects_without_iou
preds = np.hstack((detections.xyxy, detections.confidence.reshape(-1, 1), detections.class_id.reshape(-1, 1) ))
merge_groups = sv.box_non_max_merge( predictions=preds, iou_threshold=0.2, overlap_metric=sv.OverlapMetric.IOU)
merged_detections = []
for group in merge_groups:
per_detection = [detections[i] for i in group]
merged_detections.append(merge_inner_detections_objects_without_iou(per_detection))
detections = (
sv.Detections.merge(merged_detections)
if merged_detections
else sv.Detections.empty()
)Is this the intended way to use the function, or are there better methods to merge all overlapping boxes into a single truck bounding box?
Additional
No response