Configure detections-to-segments
The viam:vision:detections-to-segments vision service wraps an existing 2D detector and projects its bounding boxes into 3D point cloud objects using a depth camera’s intrinsic parameters. Each 2D detection produces a corresponding 3D segment that carries the original label and whose point cloud contains the projected pixels from inside the 2D box.
The camera you reference must provide both 2D images and point cloud data (for example, an Intel RealSense D400-series camera configured with the RealSense module). A plain 2D camera will not work.
This model previously shipped with core RDK as detector_3d_segmenter. It now ships as a module at viam-modules/detections-to-segments.
Prerequisites
- A configured 2D detector vision service (for example, an
mlmodelorcolor_detector). - A camera that returns both color images and a point cloud. See the RealSense and OAK-D modules in the registry.
Install the module
- In the Viam app, open your machine’s CONFIGURE tab.
- Click the + icon next to your machine part and select Configuration block.
- In the search field, type
detections-to-segmentsand select the matching result. - Click Add component, enter a name for the service, and click Add component again to confirm. The module is installed automatically.
The module downloads and starts automatically when you save the configuration.
Configure
"services": [
{
"name": "<segmenter_name>",
"api": "rdk:service:vision",
"model": "viam:vision:detections-to-segments",
"attributes": {
"detector_name": "<detector_name>",
"camera_name": "<camera-name>",
"mean_k": 5,
"sigma": 1.25,
"confidence_threshold_pct": 0.5
}
}
]
"services": [
{
"name": "my_segmenter",
"api": "rdk:service:vision",
"model": "viam:vision:detections-to-segments",
"attributes": {
"detector_name": "person_detector",
"camera_name": "realsense",
"mean_k": 5,
"sigma": 1.25,
"confidence_threshold_pct": 0.5
}
}
]
Attributes
| Attribute | Type | Required? | Description |
|---|---|---|---|
detector_name | string | Required | Name of a configured 2D detector vision service. Detections from this service are the input to the segmenter. |
camera_name | string | Required | Name of the depth-capable camera. Must support point clouds (supports_pcd in GetProperties). |
mean_k | int | Required | Point-cloud noise-filtering parameter (from the PCL statistical outlier removal subroutine). Set to roughly 5 to 10 percent of the minimum expected segment size. Set to 0 or less to disable filtering. |
sigma | float | Required | Point-cloud noise-filtering parameter. Typical values are 1.0 to 2.0; 1.25 is a good default. Lower values produce less noisy objects at the risk of losing points near edges. |
confidence_threshold_pct | float | Optional | Detections below this confidence are filtered out before 3D projection. Must be between 0.0 and 1.0.Default: 0.5 |
Test your segmenter
The segmenter exposes its output through the vision service’s GetObjectPointClouds method.
from viam.services.vision import VisionClient
robot = await connect()
my_segmenter = VisionClient.from_robot(robot, "my_segmenter")
objects = await my_segmenter.get_object_point_clouds("realsense")
for o in objects:
print(f"label: {o.geometries.geometries[0].label}")
await robot.close()
import (
"go.viam.com/rdk/services/vision"
)
mySegmenter, err := vision.FromProvider(machine, "my_segmenter")
if err != nil {
logger.Fatalf("cannot get vision service: %v", err)
}
segments, err := mySegmenter.GetObjectPointClouds(context.Background(), "realsense", nil)
if err != nil {
logger.Fatalf("could not get segments: %v", err)
}
if len(segments) > 0 {
logger.Info(segments[0])
}
Troubleshooting
Next steps
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!
