Skip to content

Using box_non_max_merge to Merge YOLO Boxes? #2021

Closed

Description

@DP1701

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

Activity

  1. DP1701 commented on Nov 26, 2025

    @DP1701
    Author

    Okay, I should have searched the Doc more thoroughly. Everything is easier with:

    detections = detections.with_nmm(threshold=0.2, overlap_metric=sv.OverlapMetric.IOU)

    If anyone ever faces the same challenge.

  2. changed the title [-]Using box_non_max_merge to Merge YOLO Boxes – Is This the Correct Approach?[/-] [+]Using `box_non_max_merge` to Merge YOLO Boxes – Is This the Correct Approach?[/+] on Jan 21, 2026
  3. changed the title [-]Using `box_non_max_merge` to Merge YOLO Boxes – Is This the Correct Approach?[/-] [+]Using `box_non_max_merge` to Merge YOLO Boxes?[/+] on Jan 21, 2026
  4. locked and limited conversation to collaborators on Jan 21, 2026
  5. converted this issue into a discussion #2089 on Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions