Dynamic Object Detection and Segmentation with YOLOv9+SAM
Let the detector supply the prompt
A bounding box gives a useful first answer to where an object is, but it also encloses background. In this experiment, YOLOv9 detects objects in images from the RF100 construction-safety dataset. Each box then becomes a spatial prompt for the Segment Anything Model, which predicts a mask for the object inside it.
Keep the two predictions connected
The detector supplies a class label, confidence score, and box coordinates. The segmentation step takes the image and the box in the correct coordinate system. Keeping the label alongside the returned mask lets you draw both a named detection and its estimated outline on the original image.
Read the intermediate images
The project saves the detection outputs, masks, and combined visualizations. Looking at them in sequence helps explain an error. A missing detection gives the second stage no box to work with. When the box is well placed but the mask includes background, the segmentation output is the next place to inspect.