diff --git a/supervision/detection/core.py b/supervision/detection/core.py index ea1a7e31..8269571a 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -650,12 +650,33 @@ class Detections: Example: ```python - >>> from supervision import Detections + import numpy as np + import supervision as sv - >>> detections_1 = Detections(...) - >>> detections_2 = Detections(...) + >>> detections_1 = sv.Detections( + ... xyxy=np.array([[15, 15, 100, 100], [200, 200, 300, 300]]), + ... class_id=np.array([1, 2]), + ... data={'feature_vector': np.array([0.1, 0.2)])} + ... ) + + >>> detections_2 = sv.Detections( + ... xyxy=np.array([[30, 30, 120, 120]]), + ... class_id=np.array([1]), + ... data={'feature_vector': [np.array([0.3])]} + ... ) >>> merged_detections = Detections.merge([detections_1, detections_2]) + + >>> merged_detections.xyxy + array([[ 15, 15, 100, 100], + [200, 200, 300, 300], + [ 30, 30, 120, 120]]) + + >>> merged_detections.class_id + array([1, 2, 1]) + + >>> merged_detections.data['feature_vector'] + array([0.1, 0.2, 0.3]) ``` """ if len(detections_list) == 0: diff --git a/test/detection/test_core.py b/test/detection/test_core.py index e71cdbb7..40ab22a6 100644 --- a/test/detection/test_core.py +++ b/test/detection/test_core.py @@ -181,6 +181,16 @@ def test_getitem( mock_detections(xyxy=[[10, 10, 20, 20], [20, 20, 30, 30]], class_id=[0, 1]), DoesNotRaise(), ), # two detections with xyxy, class_id fields + ( + [ + mock_detections(xyxy=[[10, 10, 20, 20]], data={"test": [1]}), + mock_detections(xyxy=[[20, 20, 30, 30]], data={"test": [2]}), + ], + mock_detections( + xyxy=[[10, 10, 20, 20], [20, 20, 30, 30]], data={"test": [1, 2]} + ), + DoesNotRaise(), + ), # two detections with xyxy, data fields ], ) def test_merge(