From 30a1a51b8a4188b2fa0e64938c80d994d368b8f9 Mon Sep 17 00:00:00 2001 From: Lukas Ostendorf Date: Fri, 13 Nov 2026 14:15:26 +0100 Subject: [PATCH 1/6] Add perception output capabilities for road users, traffic lights, and traffic signs --- .github/workflows/docker-ros.yml | 1 + .repos | 4 + deployment/compose/docker-compose.yml | 6 + deployment/helm/values.yaml | 6 + docs/IMPLEMENTATION.md | 30 +++- image_instance_segmentation/CMakeLists.txt | 5 + image_instance_segmentation/README.md | 19 ++- image_instance_segmentation/config/params.yml | 7 + .../ImageInstanceSegmentation.hpp | 27 ++++ .../image_instance_segmentation.launch.py | 9 ++ image_instance_segmentation/package.xml | 4 +- .../src/Diagnostics.cpp | 11 +- .../src/ImageInstanceSegmentation.cpp | 45 +++++- .../src/PerceptionOutputs.cpp | 140 ++++++++++++++++++ 14 files changed, 303 insertions(+), 11 deletions(-) create mode 100644 image_instance_segmentation/src/PerceptionOutputs.cpp diff --git a/.github/workflows/docker-ros.yml b/.github/workflows/docker-ros.yml index 299fa75..9a24546 100644 --- a/.github/workflows/docker-ros.yml +++ b/.github/workflows/docker-ros.yml @@ -51,6 +51,7 @@ jobs: --target-compose-svc image-instance-segmentation --dep-exclude-compose-svc-all --include-bin /opt/tritonclient/lib/libgrpcclient.so + --include-path /docker-ros/ws/install/perception_msgs --include-bin /opt/ros/jazzy/lib/libcompressed_image_transport.so --include-bin /opt/ros/jazzy/lib/librcl_interfaces__rosidl_generator_py.so --include-exe lttng diff --git a/.repos b/.repos index 3de1ac8..9536a06 100644 --- a/.repos +++ b/.repos @@ -3,3 +3,7 @@ repositories: type: git url: https://github.com/openads-project/triton_cpp.git version: v1.2.1 + perception_interfaces: + type: git + url: https://github.com/ika-rwth-aachen/perception_interfaces.git + version: 900b05f02fa3452a2ee1735eac79d9e7886329fd \ No newline at end of file diff --git a/deployment/compose/docker-compose.yml b/deployment/compose/docker-compose.yml index 583d544..76a5673 100644 --- a/deployment/compose/docker-compose.yml +++ b/deployment/compose/docker-compose.yml @@ -12,6 +12,9 @@ services: CLASS_MASK_TOPIC: ~/segmentation/class_mask INSTANCE_MASK_TOPIC: ~/segmentation/instance_mask DETECTIONS_TOPIC: ~/segmentation/detections + ROAD_USERS_TOPIC: ~/perception/road_users + TRAFFIC_LIGHTS_TOPIC: ~/perception/traffic_lights + TRAFFIC_SIGNS_TOPIC: ~/perception/traffic_signs CLASS_OVERLAY_TOPIC: ~/debug/overlay/class INSTANCE_OVERLAY_TOPIC: ~/debug/overlay/instance LOG_LEVEL: ${LOG_LEVEL:-info} @@ -36,6 +39,9 @@ services: class_mask_topic:=$${CLASS_MASK_TOPIC} \ instance_mask_topic:=$${INSTANCE_MASK_TOPIC} \ detections_topic:=$${DETECTIONS_TOPIC} \ + road_users_topic:=$${ROAD_USERS_TOPIC} \ + traffic_lights_topic:=$${TRAFFIC_LIGHTS_TOPIC} \ + traffic_signs_topic:=$${TRAFFIC_SIGNS_TOPIC} \ class_overlay_topic:=$${CLASS_OVERLAY_TOPIC} \ instance_overlay_topic:=$${INSTANCE_OVERLAY_TOPIC} # volumes: diff --git a/deployment/helm/values.yaml b/deployment/helm/values.yaml index d258313..080ecef 100644 --- a/deployment/helm/values.yaml +++ b/deployment/helm/values.yaml @@ -11,6 +11,9 @@ openadservice: CLASS_MASK_TOPIC: ~/segmentation/class_mask INSTANCE_MASK_TOPIC: ~/segmentation/instance_mask DETECTIONS_TOPIC: ~/segmentation/detections + ROAD_USERS_TOPIC: ~/perception/road_users + TRAFFIC_LIGHTS_TOPIC: ~/perception/traffic_lights + TRAFFIC_SIGNS_TOPIC: ~/perception/traffic_signs CLASS_OVERLAY_TOPIC: ~/debug/overlay/class INSTANCE_OVERLAY_TOPIC: ~/debug/overlay/instance LOG_LEVEL: info @@ -35,6 +38,9 @@ openadservice: class_mask_topic:=${CLASS_MASK_TOPIC} \ instance_mask_topic:=${INSTANCE_MASK_TOPIC} \ detections_topic:=${DETECTIONS_TOPIC} \ + road_users_topic:=${ROAD_USERS_TOPIC} \ + traffic_lights_topic:=${TRAFFIC_LIGHTS_TOPIC} \ + traffic_signs_topic:=${TRAFFIC_SIGNS_TOPIC} \ class_overlay_topic:=${CLASS_OVERLAY_TOPIC} \ instance_overlay_topic:=${INSTANCE_OVERLAY_TOPIC} rosParamFileMountPath: /docker-ros/ws/install/image_instance_segmentation/share/image_instance_segmentation/config/params.yml diff --git a/docs/IMPLEMENTATION.md b/docs/IMPLEMENTATION.md index ac72a98..c727d54 100644 --- a/docs/IMPLEMENTATION.md +++ b/docs/IMPLEMENTATION.md @@ -10,9 +10,10 @@ List camera names in `cameras` and configure each under `camera.`: | Parameter | Meaning | | --- | --- | +| `camera..sensor_id` | Unique camera ID for perception observations; defaults to its 1-based position in `cameras` | | `camera..image_topic` | Base image topic | | `camera..transport` | `raw` or `compressed`; omit `/compressed` from the base topic | -| `camera..output_prefix` | Prefix for segmentation and overlay outputs | +| `camera..output_prefix` | Prefix for camera output topics | The supplied parameter file configures one camera with raw transport, enables tracking, and selects RF-DETR-Seg decoding. @@ -38,6 +39,33 @@ In the topic tables, `config.image_topic` is the configured input and `joinTopic places outputs under the camera's prefix. Parameter names `image_topic`, `transport`, and `output_prefix` are per-camera suffixes. +## Perception objects + +Enable each object-list output independently at startup: + +```yaml +perception.publish_road_users: true +perception.publish_traffic_lights: true +perception.publish_traffic_signs: true +``` + +Topics are `perception/road_users`, `perception/traffic_lights` and +`perception/traffic_signs` under each camera's output prefix. They carry +`perception_msgs/msg/ObjectList` with `ISCACTR`, `TRAFFICLIGHT` and `TRAFFICSIGN` +states respectively. Metric components remain unmeasured; light state, sign type +and road-user light states remain unknown. + +The standard `model.class_names` select the category and road-user classification, +independently of `model.class_ids`. Unmapped names remain in segmentation outputs. +Object IDs persist for a tracked object's lifetime and are not recycled when +legacy mask IDs are reused. Without tracking, each published detection gets a +fresh ID. IDs are scoped to a camera stream and node lifetime. + +Observations retain source coordinates and headers. `perception.include_crops` +and `perception.include_masks` independently include BGR crops and binary `mono8` +ROI masks. Pixels are prepared only for subscribed outputs; empty lists are +published for processed frames without matching detections. + ## Triton model Set `prediction.triton_server_url`, `prediction.model_name`, and diff --git a/image_instance_segmentation/CMakeLists.txt b/image_instance_segmentation/CMakeLists.txt index 9c139b7..b8e7072 100644 --- a/image_instance_segmentation/CMakeLists.txt +++ b/image_instance_segmentation/CMakeLists.txt @@ -10,6 +10,8 @@ find_package(OpenCV REQUIRED COMPONENTS core dnn imgproc video) find_package(diagnostic_msgs REQUIRED) find_package(diagnostic_updater REQUIRED) find_package(image_transport REQUIRED) +find_package(perception_msgs REQUIRED) +find_package(perception_msgs_utils REQUIRED) find_package(rcl_interfaces REQUIRED) find_package(rclcpp REQUIRED) find_package(rclcpp_components REQUIRED) @@ -21,6 +23,7 @@ find_package(vision_msgs REQUIRED) add_library(${PROJECT_NAME}_lib SHARED src/ImageInstanceSegmentation.cpp src/Diagnostics.cpp + src/PerceptionOutputs.cpp ) target_include_directories(${PROJECT_NAME}_lib PUBLIC @@ -34,6 +37,8 @@ ament_target_dependencies(${PROJECT_NAME}_lib diagnostic_msgs diagnostic_updater image_transport + perception_msgs + perception_msgs_utils rcl_interfaces rclcpp rclcpp_components diff --git a/image_instance_segmentation/README.md b/image_instance_segmentation/README.md index 2aed3af..ee6c255 100644 --- a/image_instance_segmentation/README.md +++ b/image_instance_segmentation/README.md @@ -17,8 +17,11 @@ flowchart LR NODE -->|"joinTopic(config.output_prefix, 'segmentation/class_mask')"| P0:::hidden NODE -->|"joinTopic(config.output_prefix, 'segmentation/instance_mask')"| P1:::hidden NODE -->|"joinTopic(config.output_prefix, 'segmentation/detections')"| P2:::hidden - NODE -->|"joinTopic(config.output_prefix, 'debug/overlay/class')"| P3:::hidden - NODE -->|"joinTopic(config.output_prefix, 'debug/overlay/instance')"| P4:::hidden + NODE -->|"joinTopic(config.output_prefix, 'perception/road_users')"| P3:::hidden + NODE -->|"joinTopic(config.output_prefix, 'perception/traffic_lights')"| P4:::hidden + NODE -->|"joinTopic(config.output_prefix, 'perception/traffic_signs')"| P5:::hidden + NODE -->|"joinTopic(config.output_prefix, 'debug/overlay/class')"| P6:::hidden + NODE -->|"joinTopic(config.output_prefix, 'debug/overlay/instance')"| P7:::hidden classDef hidden display: none; ``` @@ -35,6 +38,9 @@ flowchart LR | `joinTopic(config.output_prefix, "segmentation/class_mask")` | `sensor_msgs/msg/Image` | `mono16` semantic class IDs; zero is background | | `joinTopic(config.output_prefix, "segmentation/instance_mask")` | `sensor_msgs/msg/Image` | `mono16` instance IDs; track IDs when tracking is enabled; zero is background | | `joinTopic(config.output_prefix, "segmentation/detections")` | `vision_msgs/msg/Detection2DArray` | Pixel-coordinate boxes, class names, confidence scores, and optional track IDs | +| `joinTopic(config.output_prefix, "perception/road_users")` | `perception_msgs/msg/ObjectList` | Optional image-only road users (`ISCACTR`) with source camera observations | +| `joinTopic(config.output_prefix, "perception/traffic_lights")` | `perception_msgs/msg/ObjectList` | Optional image-only traffic lights (`TRAFFICLIGHT`) with source camera observations | +| `joinTopic(config.output_prefix, "perception/traffic_signs")` | `perception_msgs/msg/ObjectList` | Optional image-only traffic signs (`TRAFFICSIGN`) with source camera observations | | `joinTopic(config.output_prefix, "debug/overlay/class")` | `sensor_msgs/msg/Image` | Optional `bgr8` overlay colored by class | | `joinTopic(config.output_prefix, "debug/overlay/instance")` | `sensor_msgs/msg/Image` | Optional `bgr8` overlay colored by instance or track | @@ -72,11 +78,17 @@ flowchart LR | `tracking.match_iou_threshold` | `float` | `0.3` | Minimum IoU used for tracker association | | `tracking.max_lost_frames` | `int` | `30` | Frames a track may remain unmatched before retirement | | `tracking.min_box_area_px` | `float` | `25.0` | Minimum detection area eligible for tracking | +| `perception.publish_road_users` | `bool` | `false` | Publish image-only road-user object lists | +| `perception.publish_traffic_lights` | `bool` | `false` | Publish image-only traffic-light object lists | +| `perception.publish_traffic_signs` | `bool` | `false` | Publish image-only traffic-sign object lists | +| `perception.include_crops` | `bool` | `true` | Include BGR image crops in perception objects | +| `perception.include_masks` | `bool` | `true` | Include binary instance masks in perception objects | | `debug.publish_overlay` | `bool` | `false` | Publish overlay images | | `debug.print_timing` | `bool` | `false` | Log inference, postprocessing, and total processing times | | `debug.overlay_alpha` | `float` | `0.45` | Mask opacity in debug overlays | | `debug.overlay_draw_boxes` | `bool` | `true` | Draw boxes and labels in debug overlays | | `cameras` | `string[]` | `["camera"]` | Names of cameras to process | +| `sensor_id` | `int` | `1` | Non-negative camera identifier in perception observations | | `image_topic` | `string` | `"~/image"` | Raw image base topic | | `transport` | `string` | `"raw"` | Image transport hint: raw or compressed | | `output_prefix` | `string` | `"~"` | Prefix for this camera's output topics | @@ -92,6 +104,9 @@ flowchart LR | `class_mask_topic` | `"~/segmentation/class_mask"` | semantic mask topic remap | | `instance_mask_topic` | `"~/segmentation/instance_mask"` | instance mask topic remap | | `detections_topic` | `"~/segmentation/detections"` | 2D detections topic remap | +| `road_users_topic` | `"~/perception/road_users"` | road-user objects topic remap | +| `traffic_lights_topic` | `"~/perception/traffic_lights"` | traffic-light objects topic remap | +| `traffic_signs_topic` | `"~/perception/traffic_signs"` | traffic-sign objects topic remap | | `class_overlay_topic` | `"~/debug/overlay/class"` | class overlay topic remap | | `instance_overlay_topic` | `"~/debug/overlay/instance"` | instance overlay topic remap | | `name` | `"image_instance_segmentation"` | node name | diff --git a/image_instance_segmentation/config/params.yml b/image_instance_segmentation/config/params.yml index 845167e..ca96abb 100644 --- a/image_instance_segmentation/config/params.yml +++ b/image_instance_segmentation/config/params.yml @@ -48,12 +48,19 @@ tracking.max_lost_frames: 30 tracking.min_box_area_px: 25.0 + perception.publish_road_users: false + perception.publish_traffic_lights: false + perception.publish_traffic_signs: false + perception.include_crops: true + perception.include_masks: true + debug.publish_overlay: false debug.print_timing: false debug.overlay_alpha: 0.45 debug.overlay_draw_boxes: true cameras: [camera] + camera.camera.sensor_id: 1 camera.camera.image_topic: "~/image" camera.camera.transport: "raw" camera.camera.output_prefix: "~" diff --git a/image_instance_segmentation/include/image_instance_segmentation/ImageInstanceSegmentation.hpp b/image_instance_segmentation/include/image_instance_segmentation/ImageInstanceSegmentation.hpp index b1d6da6..6b433ff 100644 --- a/image_instance_segmentation/include/image_instance_segmentation/ImageInstanceSegmentation.hpp +++ b/image_instance_segmentation/include/image_instance_segmentation/ImageInstanceSegmentation.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,7 @@ namespace image_instance_segmentation { struct CameraConfig { std::string name; + int64_t sensor_id = 1; std::string image_topic = "~/image"; std::string transport = "raw"; std::string output_prefix = "~"; @@ -50,6 +52,7 @@ struct Detection { int semantic_class_id = 0; float score = 0.0f; std::uint16_t track_id = 0; + std::uint64_t object_id = 0; bool is_tracked = false; std::vector mask_coefficients; // YOLO: coefficients for the prototype masks int mask_query = -1; // RF-DETR: query whose mask logits belong to this detection @@ -89,6 +92,11 @@ enum class OverlayColorMode { Instance, }; +struct PerceptionClass { + std::uint8_t model_id = 0; + std::uint8_t classification = 0; +}; + class ITracker; class ThreadPool; @@ -151,6 +159,9 @@ class ImageInstanceSegmentation : public rclcpp::Node { rclcpp::Publisher::SharedPtr class_mask_publisher; rclcpp::Publisher::SharedPtr instance_mask_publisher; rclcpp::Publisher::SharedPtr detections_publisher; + rclcpp::Publisher::SharedPtr road_users_publisher; + rclcpp::Publisher::SharedPtr traffic_lights_publisher; + rclcpp::Publisher::SharedPtr traffic_signs_publisher; image_transport::Publisher class_overlay_publisher; image_transport::Publisher instance_overlay_publisher; rclcpp::CallbackGroup::SharedPtr callback_group; @@ -285,6 +296,14 @@ class ImageInstanceSegmentation : public rclcpp::Node { const std::vector& detections, int image_width, int image_height); + /** @brief Resolve model class names to perception state models and road-user classes. */ + void configurePerceptionClasses(); + /** @brief Publish enabled image-only object lists, retaining optional ROI pixels. */ + void publishPerceptionObjects(const CameraRuntime& camera, + const std_msgs::msg::Header& header, + const cv::Mat& bgr_image, + const std::vector& detections, + const std::vector& masks) const; /** @brief Copy a mono16 mask into a ROS image while preserving the input * header. */ sensor_msgs::msg::Image matToMono16Image(const cv::Mat& mask, const std_msgs::msg::Header& header) const; @@ -340,6 +359,14 @@ class ImageInstanceSegmentation : public rclcpp::Node { // clang-format on std::vector class_ids_ = {1, 2, 3, 4, 5, 7, 8, 12, 13, 20, 29}; + bool publish_road_users_ = false; + bool publish_traffic_lights_ = false; + bool publish_traffic_signs_ = false; + bool perception_include_crops_ = true; + bool perception_include_masks_ = true; + std::vector perception_classes_; + mutable std::atomic next_untracked_object_id_{1}; + double confidence_threshold_ = 0.25; double mask_threshold_ = 0.5; double nms_iou_threshold_ = 0.45; diff --git a/image_instance_segmentation/launch/image_instance_segmentation.launch.py b/image_instance_segmentation/launch/image_instance_segmentation.launch.py index dc81431..d94882e 100644 --- a/image_instance_segmentation/launch/image_instance_segmentation.launch.py +++ b/image_instance_segmentation/launch/image_instance_segmentation.launch.py @@ -28,6 +28,15 @@ def generate_launch_description(): DeclareLaunchArgument( "detections_topic", default_value="~/segmentation/detections", description="2D detections topic remap" ), + DeclareLaunchArgument( + "road_users_topic", default_value="~/perception/road_users", description="road-user objects topic remap" + ), + DeclareLaunchArgument( + "traffic_lights_topic", default_value="~/perception/traffic_lights", description="traffic-light objects topic remap" + ), + DeclareLaunchArgument( + "traffic_signs_topic", default_value="~/perception/traffic_signs", description="traffic-sign objects topic remap" + ), DeclareLaunchArgument( "class_overlay_topic", default_value="~/debug/overlay/class", description="class overlay topic remap" ), diff --git a/image_instance_segmentation/package.xml b/image_instance_segmentation/package.xml index 05fe1de..5c0aa45 100644 --- a/image_instance_segmentation/package.xml +++ b/image_instance_segmentation/package.xml @@ -2,7 +2,7 @@ image_instance_segmentation - 1.1.0 + 1.2.0 Image instance segmentation inference node backed by Triton Lukas Ostendorf @@ -17,6 +17,8 @@ diagnostic_updater image_transport libopencv-dev + perception_msgs + perception_msgs_utils rcl_interfaces rclcpp rclcpp_components diff --git a/image_instance_segmentation/src/Diagnostics.cpp b/image_instance_segmentation/src/Diagnostics.cpp index 41f0e98..4249c83 100644 --- a/image_instance_segmentation/src/Diagnostics.cpp +++ b/image_instance_segmentation/src/Diagnostics.cpp @@ -99,10 +99,13 @@ void ImageInstanceSegmentation::setupDiagnostics() { diagnostic_updater_->setHardwareID("none"); for (auto& [name, state] : camera_health_) { const auto& camera = cameras_.at(name); - const std::map topics{{"input", camera.image_subscriber.getTopic()}, - {"class_mask", camera.class_mask_publisher->get_topic_name()}, - {"instance_mask", camera.instance_mask_publisher->get_topic_name()}, - {"detections", camera.detections_publisher->get_topic_name()}}; + std::map topics{{"input", camera.image_subscriber.getTopic()}, + {"class_mask", camera.class_mask_publisher->get_topic_name()}, + {"instance_mask", camera.instance_mask_publisher->get_topic_name()}, + {"detections", camera.detections_publisher->get_topic_name()}}; + if (camera.road_users_publisher) topics.emplace("road_users", camera.road_users_publisher->get_topic_name()); + if (camera.traffic_lights_publisher) topics.emplace("traffic_lights", camera.traffic_lights_publisher->get_topic_name()); + if (camera.traffic_signs_publisher) topics.emplace("traffic_signs", camera.traffic_signs_publisher->get_topic_name()); for (const auto& [key, topic] : topics) { auto& cfg = state.topics[key]; const std::string prefix = "diagnostic_updater." + name + "." + key + "."; diff --git a/image_instance_segmentation/src/ImageInstanceSegmentation.cpp b/image_instance_segmentation/src/ImageInstanceSegmentation.cpp index f9175ea..880957c 100644 --- a/image_instance_segmentation/src/ImageInstanceSegmentation.cpp +++ b/image_instance_segmentation/src/ImageInstanceSegmentation.cpp @@ -53,6 +53,9 @@ ImageInstanceSegmentation::CameraRuntime::CameraRuntime(CameraRuntime&& other) n class_mask_publisher(std::move(other.class_mask_publisher)), instance_mask_publisher(std::move(other.instance_mask_publisher)), detections_publisher(std::move(other.detections_publisher)), + road_users_publisher(std::move(other.road_users_publisher)), + traffic_lights_publisher(std::move(other.traffic_lights_publisher)), + traffic_signs_publisher(std::move(other.traffic_signs_publisher)), class_overlay_publisher(std::move(other.class_overlay_publisher)), instance_overlay_publisher(std::move(other.instance_overlay_publisher)), callback_group(std::move(other.callback_group)), @@ -66,6 +69,9 @@ ImageInstanceSegmentation::CameraRuntime& ImageInstanceSegmentation::CameraRunti class_mask_publisher = std::move(other.class_mask_publisher); instance_mask_publisher = std::move(other.instance_mask_publisher); detections_publisher = std::move(other.detections_publisher); + road_users_publisher = std::move(other.road_users_publisher); + traffic_lights_publisher = std::move(other.traffic_lights_publisher); + traffic_signs_publisher = std::move(other.traffic_signs_publisher); class_overlay_publisher = std::move(other.class_overlay_publisher); instance_overlay_publisher = std::move(other.instance_overlay_publisher); callback_group = std::move(other.callback_group); @@ -563,6 +569,7 @@ class ByteTracker final : public ITracker { track.state = TrackLifecycle::Tracked; } track.latest_detection.track_id = track.id; + track.latest_detection.object_id = track.object_id; track.latest_detection.is_tracked = true; tracked_detections.push_back(track.latest_detection); continue; @@ -604,6 +611,7 @@ class ByteTracker final : public ITracker { Detection latest_detection; TrackLifecycle state = TrackLifecycle::Tentative; std::uint16_t id = 0; + std::uint64_t object_id = 0; int hits = 0; int lost_frames = 0; bool updated_this_frame = false; @@ -683,6 +691,7 @@ class ByteTracker final : public ITracker { track.latest_detection = detection; track.latest_detection.box = track.predicted_box; track.latest_detection.track_id = track.id; + track.latest_detection.object_id = track.object_id; track.latest_detection.is_tracked = true; track.updated_this_frame = true; track.lost_frames = 0; @@ -704,7 +713,10 @@ class ByteTracker final : public ITracker { track.filter = makeKalmanFilter(detection.box); track.predicted_box = detection.box; track.latest_detection = detection; + if (next_object_id_ == 0) throw std::overflow_error("Object tracking ID exhausted"); + track.object_id = next_object_id_++; track.latest_detection.track_id = id; + track.latest_detection.object_id = track.object_id; track.latest_detection.is_tracked = true; track.state = TrackLifecycle::Tentative; track.id = id; @@ -742,6 +754,7 @@ class ByteTracker final : public ITracker { std::vector tracks_; std::deque reusable_ids_; std::uint16_t next_track_id_ = 1; + std::uint64_t next_object_id_ = 1; }; } // namespace @@ -755,6 +768,7 @@ ImageInstanceSegmentation::ImageInstanceSegmentation(const rclcpp::NodeOptions& loadParameters(); validateParameters(); + configurePerceptionClasses(); initializeModel(); setupCameras(); setupDiagnostics(); @@ -948,6 +962,15 @@ void ImageInstanceSegmentation::loadParameters() { "Minimum detection area eligible for tracking", false, false, true, 0.0, std::numeric_limits::max(), 0.0); + declareAndLoadParameter("perception.publish_road_users", publish_road_users_, "Publish image-only road-user object lists"); + declareAndLoadParameter("perception.publish_traffic_lights", publish_traffic_lights_, + "Publish image-only traffic-light object lists"); + declareAndLoadParameter("perception.publish_traffic_signs", publish_traffic_signs_, + "Publish image-only traffic-sign object lists"); + declareAndLoadParameter("perception.include_crops", perception_include_crops_, "Include BGR image crops in perception objects"); + declareAndLoadParameter("perception.include_masks", perception_include_masks_, + "Include binary instance masks in perception objects"); + declareAndLoadParameter("debug.publish_overlay", publish_overlay_, "Publish overlay images", true, false, false); declareAndLoadParameter("debug.print_timing", print_timing_, "Log inference, postprocessing, and total processing times", true, false, false); @@ -970,10 +993,12 @@ void ImageInstanceSegmentation::loadParameters() { const std::string prefix = "camera." + name + "."; CameraConfig config; config.name = name; + config.sensor_id = static_cast(camera_configs_.size()) + 1; if (name != "camera") { config.image_topic = "~/" + name + "/image"; config.output_prefix = "~/" + name; } + declareAndLoadParameter(prefix + "sensor_id", config.sensor_id, "Non-negative camera identifier in perception observations"); declareAndLoadParameter(prefix + "image_topic", config.image_topic, "Raw image base topic"); declareAndLoadParameter(prefix + "transport", config.transport, "Image transport hint: raw or compressed"); declareAndLoadParameter(prefix + "output_prefix", config.output_prefix, "Prefix for this camera's output topics"); @@ -1043,11 +1068,15 @@ void ImageInstanceSegmentation::validateParameters() const { fail("tracking.min_box_area_px must be non-negative"); if (camera_configs_.empty()) fail("cameras must contain at least one camera name"); std::vector camera_names; + std::vector sensor_ids; for (const auto& camera : camera_configs_) { if (std::find(camera_names.begin(), camera_names.end(), camera.name) != camera_names.end()) { fail("camera names must be unique"); } camera_names.push_back(camera.name); + if (camera.sensor_id < 0 || std::find(sensor_ids.begin(), sensor_ids.end(), camera.sensor_id) != sensor_ids.end()) + fail("camera sensor IDs must be non-negative and unique"); + sensor_ids.push_back(camera.sensor_id); if (camera.name.empty()) fail("camera names must not be empty"); if (camera.image_topic.empty()) fail("camera." + camera.name + ".image_topic must not be empty"); if (camera.output_prefix.empty()) fail("camera." + camera.name + ".output_prefix must not be empty"); @@ -1145,6 +1174,15 @@ void ImageInstanceSegmentation::setupCameras() { joinTopic(config.output_prefix, "segmentation/instance_mask"), rclcpp::SensorDataQoS(), pub_options); runtime.detections_publisher = create_publisher( joinTopic(config.output_prefix, "segmentation/detections"), rclcpp::SensorDataQoS(), pub_options); + if (publish_road_users_) + runtime.road_users_publisher = create_publisher( + joinTopic(config.output_prefix, "perception/road_users"), rclcpp::SensorDataQoS(), pub_options); + if (publish_traffic_lights_) + runtime.traffic_lights_publisher = create_publisher( + joinTopic(config.output_prefix, "perception/traffic_lights"), rclcpp::SensorDataQoS(), pub_options); + if (publish_traffic_signs_) + runtime.traffic_signs_publisher = create_publisher( + joinTopic(config.output_prefix, "perception/traffic_signs"), rclcpp::SensorDataQoS(), pub_options); runtime.class_overlay_publisher = image_transport::create_publisher( this, get_node_topics_interface()->resolve_topic_name(joinTopic(config.output_prefix, "debug/overlay/class")), rclcpp::SensorDataQoS().get_rmw_qos_profile(), pub_options); @@ -1378,9 +1416,9 @@ void ImageInstanceSegmentation::processImage(const std_msgs::msg::Header& header // Keep publication in the same critical section as inference/tracking. publishResults(camera, header, bgr_image, detections, masks); auto& state = camera_health_.at(camera_name); - for (const auto* key : {"class_mask", "instance_mask", "detections"}) { - if (auto& task = state.topics.at(key).task; task && header.stamp.sec >= 0 && header.stamp.nanosec < 1000000000u) - task->tick(header.stamp); + for (auto& [key, topic] : state.topics) { + if (key == "input") continue; + if (auto& task = topic.task; task && header.stamp.sec >= 0 && header.stamp.nanosec < 1000000000u) task->tick(header.stamp); } { std::lock_guard state_lock(state.mutex); @@ -1770,6 +1808,7 @@ void ImageInstanceSegmentation::publishResults(const CameraRuntime& camera, camera.class_mask_publisher->publish(matToMono16Image(class_mask, header)); camera.instance_mask_publisher->publish(matToMono16Image(instance_mask, header)); camera.detections_publisher->publish(makeDetectionsMessage(detections, header)); + publishPerceptionObjects(camera, header, bgr_image, detections, masks); if (publish_overlay_) { if (camera.class_overlay_publisher && camera.class_overlay_publisher.getNumSubscribers() > 0) { camera.class_overlay_publisher.publish(makeOverlay(bgr_image, detections, masks, header, OverlayColorMode::Class)); diff --git a/image_instance_segmentation/src/PerceptionOutputs.cpp b/image_instance_segmentation/src/PerceptionOutputs.cpp new file mode 100644 index 0000000..ba2c000 --- /dev/null +++ b/image_instance_segmentation/src/PerceptionOutputs.cpp @@ -0,0 +1,140 @@ +// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University +// SPDX-License-Identifier: Apache-2.0 + +#include "image_instance_segmentation/ImageInstanceSegmentation.hpp" + +#include +#include +#include +#include +#include +#include + +namespace image_instance_segmentation { +namespace { + +/** @brief Copy ROI pixels directly into a packed ROS image. */ +sensor_msgs::msg::Image roiImage(const cv::Mat& pixels, const std_msgs::msg::Header& header, const std::string& encoding) { + sensor_msgs::msg::Image image; + image.header = header; + image.width = static_cast(pixels.cols); + image.height = static_cast(pixels.rows); + image.encoding = encoding; + image.step = static_cast(pixels.cols * pixels.elemSize()); + image.data.resize(static_cast(image.step) * image.height); + for (int row = 0; row < pixels.rows; ++row) + std::memcpy(image.data.data() + static_cast(row) * image.step, pixels.ptr(row), image.step); + return image; +} + +/** @brief Clip the detection rectangle to the source image before integer conversion. */ +cv::Rect sourceRoi(const cv::Rect2f& box, const cv::Size& size) { + const int left = static_cast(std::clamp(std::floor(static_cast(box.x)), 0.0, static_cast(size.width))); + const int top = static_cast(std::clamp(std::floor(static_cast(box.y)), 0.0, static_cast(size.height))); + const int right = static_cast( + std::clamp(std::ceil(static_cast(box.x) + box.width), static_cast(left), static_cast(size.width))); + const int bottom = static_cast( + std::clamp(std::ceil(static_cast(box.y) + box.height), static_cast(top), static_cast(size.height))); + return {left, top, right - left, bottom - top}; +} + +} // namespace + +void ImageInstanceSegmentation::configurePerceptionClasses() { + using Classification = perception_msgs::msg::ObjectClassification; + using RoadUser = perception_msgs::msg::ISCACTR; + const std::map classes{ + {"PEDESTRIAN", {RoadUser::MODEL_ID, Classification::PEDESTRIAN}}, + {"BICYCLE", {RoadUser::MODEL_ID, Classification::BICYCLE}}, + {"MOTORCYCLE", {RoadUser::MODEL_ID, Classification::MOTORCYCLE}}, + {"MOTORBIKE", {RoadUser::MODEL_ID, Classification::MOTORCYCLE}}, + {"CAR", {RoadUser::MODEL_ID, Classification::CAR}}, + {"VAN", {RoadUser::MODEL_ID, Classification::CAR}}, + {"UTILITY", {RoadUser::MODEL_ID, Classification::UTILITY}}, + {"TRUCK", {RoadUser::MODEL_ID, Classification::UTILITY}}, + {"TRAILER", {RoadUser::MODEL_ID, Classification::UTILITY}}, + {"TRAIN", {RoadUser::MODEL_ID, Classification::UTILITY}}, + {"BUS", {RoadUser::MODEL_ID, Classification::BUS}}, + {"ANIMAL", {RoadUser::MODEL_ID, Classification::ANIMAL}}, + {"VRU", {RoadUser::MODEL_ID, Classification::VRU}}, + {"MICRO", {RoadUser::MODEL_ID, Classification::MICRO}}, + {"TRAFFIC_LIGHT", {perception_msgs::msg::TRAFFICLIGHT::MODEL_ID, 0}}, + {"TRAFFIC_SIGN", {perception_msgs::msg::TRAFFICSIGN::MODEL_ID, 0}}, + }; + perception_classes_.assign(class_names_.size(), {}); + if (!publish_road_users_ && !publish_traffic_lights_ && !publish_traffic_signs_) return; + for (std::size_t i = 0; i < class_names_.size(); ++i) { + const auto entry = classes.find(class_names_[i]); + if (entry != classes.end()) { + perception_classes_[i] = entry->second; + } else { + RCLCPP_WARN(get_logger(), "Class '%s' has no perception mapping; publishing it only in segmentation outputs", + class_names_[i].c_str()); + } + } +} + +void ImageInstanceSegmentation::publishPerceptionObjects(const CameraRuntime& camera, + const std_msgs::msg::Header& header, + const cv::Mat& bgr_image, + const std::vector& detections, + const std::vector& masks) const { + using namespace perception_msgs::object_access; + const auto publish = [&](const rclcpp::Publisher::SharedPtr& publisher, + std::uint8_t model_id) { + if (!publisher || (publisher->get_subscription_count() == 0 && publisher->get_intra_process_subscription_count() == 0)) + return; + auto objects = std::make_unique(); + objects->header = header; + for (std::size_t i = 0; i < detections.size(); ++i) { + const auto& detection = detections[i]; + const auto& classification = perception_classes_.at(static_cast(detection.class_index)); + if (classification.model_id != model_id) continue; + perception_msgs::msg::Object object; + object.id = detection.object_id; + if (!detection.is_tracked) { + object.id = next_untracked_object_id_.fetch_add(1, std::memory_order_relaxed); + if (object.id == 0) throw std::overflow_error("Untracked object ID exhausted"); + } + object.existence_probability = detection.score; + initializeState(object, model_id); + object.state.header = header; + object.state.sensor_id.push_back(static_cast(camera.config.sensor_id)); + if (model_id == perception_msgs::msg::ISCACTR::MODEL_ID) { + perception_msgs::msg::ObjectClassification road_class; + road_class.type = classification.classification; + road_class.probability = detection.score; + object.state.classifications.push_back(road_class); + } else if (model_id == perception_msgs::msg::TRAFFICLIGHT::MODEL_ID) { + setTrafficLightType(object, perception_msgs::msg::TRAFFICLIGHT::TYPE_UNKNOWN); + } + perception_msgs::msg::ImageObservation image; + image.header = header; + image.sensor_id = static_cast(camera.config.sensor_id); + image.image_width = static_cast(bgr_image.cols); + image.image_height = static_cast(bgr_image.rows); + image.bounding_box.center.position.x = detection.box.x + detection.box.width * 0.5; + image.bounding_box.center.position.y = detection.box.y + detection.box.height * 0.5; + image.bounding_box.size_x = detection.box.width; + image.bounding_box.size_y = detection.box.height; + const cv::Rect roi = i < masks.size() && !masks[i].roi.empty() ? masks[i].roi : sourceRoi(detection.box, bgr_image.size()); + if (!roi.empty()) { + image.roi.x_offset = static_cast(roi.x); + image.roi.y_offset = static_cast(roi.y); + image.roi.width = static_cast(roi.width); + image.roi.height = static_cast(roi.height); + if (perception_include_crops_) image.crop = roiImage(bgr_image(roi), header, sensor_msgs::image_encodings::BGR8); + if (perception_include_masks_ && i < masks.size() && !masks[i].pixels.empty()) + image.mask = roiImage(masks[i].pixels, header, sensor_msgs::image_encodings::MONO8); + } + object.state.image_observations.push_back(std::move(image)); + objects->objects.push_back(std::move(object)); + } + publisher->publish(std::move(objects)); + }; + publish(camera.road_users_publisher, perception_msgs::msg::ISCACTR::MODEL_ID); + publish(camera.traffic_lights_publisher, perception_msgs::msg::TRAFFICLIGHT::MODEL_ID); + publish(camera.traffic_signs_publisher, perception_msgs::msg::TRAFFICSIGN::MODEL_ID); +} + +} // namespace image_instance_segmentation From e1c4778afd11a79ef4949619fb64682d46d501a9 Mon Sep 17 00:00:00 2001 From: Lukas Ostendorf Date: Fri, 13 Nov 2026 14:24:42 +0100 Subject: [PATCH 2/6] Update Docker and Helm configurations to version 1.2.0; enhance perception object publishing with header validation --- .github/workflows/docker-ros.yml | 1 + .repos | 2 +- deployment/compose/docker-compose.yml | 2 +- deployment/helm/Chart.yaml | 4 ++-- deployment/helm/values.yaml | 2 +- docs/IMPLEMENTATION.md | 4 ++-- image_instance_segmentation/src/PerceptionOutputs.cpp | 3 +++ 7 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docker-ros.yml b/.github/workflows/docker-ros.yml index 9a24546..6b82bd6 100644 --- a/.github/workflows/docker-ros.yml +++ b/.github/workflows/docker-ros.yml @@ -42,6 +42,7 @@ jobs: rmw-implementation: rmw_zenoh_cpp command: ros2 launch image_instance_segmentation image_instance_segmentation.launch.py enable-recursive-vcs-import: "false" + enable-build-required-packages-only: "true" enable-industrial-ci: true enable-slim: "true" # Retain optional runtime binaries and plugin dependencies. diff --git a/.repos b/.repos index 9536a06..d8f9336 100644 --- a/.repos +++ b/.repos @@ -6,4 +6,4 @@ repositories: perception_interfaces: type: git url: https://github.com/ika-rwth-aachen/perception_interfaces.git - version: 900b05f02fa3452a2ee1735eac79d9e7886329fd \ No newline at end of file + version: 900b05f02fa3452a2ee1735eac79d9e7886329fd diff --git a/deployment/compose/docker-compose.yml b/deployment/compose/docker-compose.yml index 76a5673..b3546c8 100644 --- a/deployment/compose/docker-compose.yml +++ b/deployment/compose/docker-compose.yml @@ -1,7 +1,7 @@ services: image-instance-segmentation: - image: ghcr.io/openads-project/image_instance_segmentation:v1.1.0 + image: ghcr.io/openads-project/image_instance_segmentation:v1.2.0 environment: # --- name ------ NAMESPACE: / diff --git a/deployment/helm/Chart.yaml b/deployment/helm/Chart.yaml index b15ff6f..31c6080 100644 --- a/deployment/helm/Chart.yaml +++ b/deployment/helm/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 name: image-instance-segmentation -version: 1.1.0 -appVersion: 1.1.0 +version: 1.2.0 +appVersion: 1.2.0 description: ROS 2 Image Instance Segmentation for Automated Driving dependencies: - repository: oci://ghcr.io/openads-project/openads-helm diff --git a/deployment/helm/values.yaml b/deployment/helm/values.yaml index 080ecef..3c23423 100644 --- a/deployment/helm/values.yaml +++ b/deployment/helm/values.yaml @@ -1,6 +1,6 @@ openadservice: name: image-instance-segmentation - image: ghcr.io/openads-project/image_instance_segmentation:v1.1.0 + image: ghcr.io/openads-project/image_instance_segmentation:v1.2.0 env: # --- name ------ NAMESPACE: / diff --git a/docs/IMPLEMENTATION.md b/docs/IMPLEMENTATION.md index c727d54..aa37e81 100644 --- a/docs/IMPLEMENTATION.md +++ b/docs/IMPLEMENTATION.md @@ -37,7 +37,7 @@ reused after a track ends. In the topic tables, `config.image_topic` is the configured input and `joinTopic` places outputs under the camera's prefix. Parameter names `image_topic`, -`transport`, and `output_prefix` are per-camera suffixes. +`sensor_id`, `transport`, and `output_prefix` are per-camera suffixes. ## Perception objects @@ -58,7 +58,7 @@ and road-user light states remain unknown. The standard `model.class_names` select the category and road-user classification, independently of `model.class_ids`. Unmapped names remain in segmentation outputs. Object IDs persist for a tracked object's lifetime and are not recycled when -legacy mask IDs are reused. Without tracking, each published detection gets a +mask IDs are reused. Without tracking, each published detection gets a fresh ID. IDs are scoped to a camera stream and node lifetime. Observations retain source coordinates and headers. `perception.include_crops` diff --git a/image_instance_segmentation/src/PerceptionOutputs.cpp b/image_instance_segmentation/src/PerceptionOutputs.cpp index ba2c000..4832ef0 100644 --- a/image_instance_segmentation/src/PerceptionOutputs.cpp +++ b/image_instance_segmentation/src/PerceptionOutputs.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace image_instance_segmentation { namespace { @@ -80,6 +81,8 @@ void ImageInstanceSegmentation::publishPerceptionObjects(const CameraRuntime& ca const std::vector& detections, const std::vector& masks) const { using namespace perception_msgs::object_access; + // Image observations require a valid source camera header. + if (header.frame_id.empty() || header.stamp.sec < 0 || header.stamp.nanosec >= 1000000000u) return; const auto publish = [&](const rclcpp::Publisher::SharedPtr& publisher, std::uint8_t model_id) { if (!publisher || (publisher->get_subscription_count() == 0 && publisher->get_intra_process_subscription_count() == 0)) From c4cb8e013b8f604ca5aff613cda29767721f148b Mon Sep 17 00:00:00 2001 From: Lukas Ostendorf Date: Fri, 13 Nov 2026 14:28:51 +0100 Subject: [PATCH 3/6] Update perception output references from ISCACTR to HEXAMOTION --- docs/IMPLEMENTATION.md | 2 +- image_instance_segmentation/README.md | 2 +- image_instance_segmentation/src/PerceptionOutputs.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/IMPLEMENTATION.md b/docs/IMPLEMENTATION.md index aa37e81..7dd30ce 100644 --- a/docs/IMPLEMENTATION.md +++ b/docs/IMPLEMENTATION.md @@ -51,7 +51,7 @@ perception.publish_traffic_signs: true Topics are `perception/road_users`, `perception/traffic_lights` and `perception/traffic_signs` under each camera's output prefix. They carry -`perception_msgs/msg/ObjectList` with `ISCACTR`, `TRAFFICLIGHT` and `TRAFFICSIGN` +`perception_msgs/msg/ObjectList` with `HEXAMOTION`, `TRAFFICLIGHT` and `TRAFFICSIGN` states respectively. Metric components remain unmeasured; light state, sign type and road-user light states remain unknown. diff --git a/image_instance_segmentation/README.md b/image_instance_segmentation/README.md index ee6c255..827710c 100644 --- a/image_instance_segmentation/README.md +++ b/image_instance_segmentation/README.md @@ -38,7 +38,7 @@ flowchart LR | `joinTopic(config.output_prefix, "segmentation/class_mask")` | `sensor_msgs/msg/Image` | `mono16` semantic class IDs; zero is background | | `joinTopic(config.output_prefix, "segmentation/instance_mask")` | `sensor_msgs/msg/Image` | `mono16` instance IDs; track IDs when tracking is enabled; zero is background | | `joinTopic(config.output_prefix, "segmentation/detections")` | `vision_msgs/msg/Detection2DArray` | Pixel-coordinate boxes, class names, confidence scores, and optional track IDs | -| `joinTopic(config.output_prefix, "perception/road_users")` | `perception_msgs/msg/ObjectList` | Optional image-only road users (`ISCACTR`) with source camera observations | +| `joinTopic(config.output_prefix, "perception/road_users")` | `perception_msgs/msg/ObjectList` | Optional image-only road users (`HEXAMOTION`) with source camera observations | | `joinTopic(config.output_prefix, "perception/traffic_lights")` | `perception_msgs/msg/ObjectList` | Optional image-only traffic lights (`TRAFFICLIGHT`) with source camera observations | | `joinTopic(config.output_prefix, "perception/traffic_signs")` | `perception_msgs/msg/ObjectList` | Optional image-only traffic signs (`TRAFFICSIGN`) with source camera observations | | `joinTopic(config.output_prefix, "debug/overlay/class")` | `sensor_msgs/msg/Image` | Optional `bgr8` overlay colored by class | diff --git a/image_instance_segmentation/src/PerceptionOutputs.cpp b/image_instance_segmentation/src/PerceptionOutputs.cpp index 4832ef0..e2c2a40 100644 --- a/image_instance_segmentation/src/PerceptionOutputs.cpp +++ b/image_instance_segmentation/src/PerceptionOutputs.cpp @@ -43,7 +43,7 @@ cv::Rect sourceRoi(const cv::Rect2f& box, const cv::Size& size) { void ImageInstanceSegmentation::configurePerceptionClasses() { using Classification = perception_msgs::msg::ObjectClassification; - using RoadUser = perception_msgs::msg::ISCACTR; + using RoadUser = perception_msgs::msg::HEXAMOTION; const std::map classes{ {"PEDESTRIAN", {RoadUser::MODEL_ID, Classification::PEDESTRIAN}}, {"BICYCLE", {RoadUser::MODEL_ID, Classification::BICYCLE}}, @@ -103,7 +103,7 @@ void ImageInstanceSegmentation::publishPerceptionObjects(const CameraRuntime& ca initializeState(object, model_id); object.state.header = header; object.state.sensor_id.push_back(static_cast(camera.config.sensor_id)); - if (model_id == perception_msgs::msg::ISCACTR::MODEL_ID) { + if (model_id == perception_msgs::msg::HEXAMOTION::MODEL_ID) { perception_msgs::msg::ObjectClassification road_class; road_class.type = classification.classification; road_class.probability = detection.score; @@ -135,7 +135,7 @@ void ImageInstanceSegmentation::publishPerceptionObjects(const CameraRuntime& ca } publisher->publish(std::move(objects)); }; - publish(camera.road_users_publisher, perception_msgs::msg::ISCACTR::MODEL_ID); + publish(camera.road_users_publisher, perception_msgs::msg::HEXAMOTION::MODEL_ID); publish(camera.traffic_lights_publisher, perception_msgs::msg::TRAFFICLIGHT::MODEL_ID); publish(camera.traffic_signs_publisher, perception_msgs::msg::TRAFFICSIGN::MODEL_ID); } From eed009e1d5cb3a194a87e3f4fe7a35b4bd17ca4c Mon Sep 17 00:00:00 2001 From: Lukas Ostendorf Date: Fri, 13 Nov 2026 16:07:56 +0100 Subject: [PATCH 4/6] Refactor perception output handling: remove overlay topics, add image-only object lists for road users, traffic lights, and traffic signs; update documentation and launch configurations accordingly. --- README.md | 4 +- demo/README.md | 15 ++- demo/config/params.yml | 10 +- demo/docker-compose.yml | 11 +- demo/visualization/demo.rviz | 86 +++++++++++++ demo/visualization/open_image_view.py | 36 ------ deployment/compose/docker-compose.yml | 6 +- deployment/helm/values.yaml | 6 +- docs/IMPLEMENTATION.md | 10 +- image_instance_segmentation/README.md | 9 -- image_instance_segmentation/config/params.yml | 3 - .../ImageInstanceSegmentation.hpp | 20 +-- .../image_instance_segmentation.launch.py | 8 -- .../src/ImageInstanceSegmentation.cpp | 114 ------------------ 14 files changed, 120 insertions(+), 218 deletions(-) create mode 100644 demo/visualization/demo.rviz delete mode 100644 demo/visualization/open_image_view.py diff --git a/README.md b/README.md index 98da622..88eae1b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This OpenADS service performs image instance segmentation through Triton Inference Server. It supports multiple cameras, optional tracking, segmentation masks, 2D detections, -and debug overlays. Model weights and datasets are supplied separately. +and image-only perception object lists. Model weights and datasets are supplied separately.

🚀 Quick Start • 💻 Development • 📝 Documentation @@ -32,7 +32,7 @@ and debug overlays. Model weights and datasets are supplied separately. ## 🚀 Quick Start -Run the demo with Triton, recorded camera images, and a segmentation overlay viewer: +Run the demo with Triton, recorded camera images, and an RViz view of the detected objects: ```bash cd demo diff --git a/demo/README.md b/demo/README.md index d72f993..f969258 100644 --- a/demo/README.md +++ b/demo/README.md @@ -1,7 +1,7 @@ # RF-DETR-Seg Demo Four services run RF-DETR-Seg inference on a recorded camera stream: Triton, -rosbag playback, image instance segmentation, and `rqt_image_view`. +rosbag playback, image instance segmentation, and RViz. Requires Docker Compose 2.35 or newer, NVIDIA Container Toolkit with a compatible GPU/driver, and an X11 or XWayland display. @@ -28,10 +28,15 @@ To customize the demo, copy `.env.example` to `.env` and edit the settings. the Triton model image. Model and node settings are in [config/params.yml](config/params.yml). -The viewer opens `/demo/overlay/instance`; select `/demo/overlay/class` in its -topic dropdown for class colors. Masks and boxes are published on -`/demo/class_mask`, `/demo/instance_mask`, and `/demo/detections`. -No calibration or TF is needed for these image-coordinate outputs. +RViz shows the image-only object lists `/demo/perception/road_users`, +`/demo/perception/traffic_signs`, and `/demo/perception/traffic_lights` in +separate panels: road users with boxes, masks, and track IDs on the matching +camera image, traffic signs and lights as their image crops. Panels can be +rearranged or floated as windows; the layout is in +[visualization/demo.rviz](visualization/demo.rviz). Full-frame masks and boxes +are published on `/demo/class_mask`, `/demo/instance_mask`, and +`/demo/detections`. No calibration or TF is needed for these image-coordinate +outputs. The first start can take several minutes while TensorRT prepares the model. Its cache is retained in a Docker volume for subsequent runs. diff --git a/demo/config/params.yml b/demo/config/params.yml index 25d2591..fd6754f 100644 --- a/demo/config/params.yml +++ b/demo/config/params.yml @@ -48,10 +48,14 @@ tracking.max_lost_frames: 30 tracking.min_box_area_px: 25.0 - debug.publish_overlay: true + # Image-only object lists with boxes, masks, and crops, shown by the RViz demo view. + perception.publish_road_users: true + perception.publish_traffic_lights: true + perception.publish_traffic_signs: true + perception.include_crops: true + perception.include_masks: true + debug.print_timing: false - debug.overlay_alpha: 0.45 - debug.overlay_draw_boxes: true cameras: [camera] camera.camera.image_topic: "~/image" diff --git a/demo/docker-compose.yml b/demo/docker-compose.yml index ae4d21a..ebbd785 100644 --- a/demo/docker-compose.yml +++ b/demo/docker-compose.yml @@ -58,8 +58,9 @@ services: - class_mask_topic:=/demo/class_mask - instance_mask_topic:=/demo/instance_mask - detections_topic:=/demo/detections - - class_overlay_topic:=/demo/overlay/class - - instance_overlay_topic:=/demo/overlay/instance + - road_users_topic:=/demo/perception/road_users + - traffic_lights_topic:=/demo/perception/traffic_lights + - traffic_signs_topic:=/demo/perception/traffic_signs bag-play: image: ghcr.io/openads-project/monitoring:v1.0.0 @@ -94,7 +95,7 @@ services: - --disable-keyboard-controls visualization: - image: ghcr.io/openads-project/monitoring:v1.0.0 + image: ${VISUALIZATION_IMAGE:-ghcr.io/openads-project/monitoring:v1.0.0} depends_on: image-instance-segmentation: condition: service_started @@ -105,8 +106,8 @@ services: QT_X11_NO_MITSHM: "1" volumes: - /tmp/.X11-unix:/tmp/.X11-unix:rw - - ./visualization/open_image_view.py:/demo/open_image_view.py:ro - command: [python3, /demo/open_image_view.py] + - ./visualization/demo.rviz:/demo/demo.rviz:ro + command: [ros2, run, rviz2, rviz2, -d, /demo/demo.rviz] volumes: triton-cache: diff --git a/demo/visualization/demo.rviz b/demo/visualization/demo.rviz new file mode 100644 index 0000000..c8eaa3a --- /dev/null +++ b/demo/visualization/demo.rviz @@ -0,0 +1,86 @@ +Panels: + - Class: rviz_common/Displays + Name: Displays +Visualization Manager: + Class: "" + Displays: + - Class: perception_msgs/ImageObservations + Enabled: true + Name: Road users + Topic: + Value: /demo/perception/road_users + Depth: 5 + Durability Policy: Volatile + History Policy: Keep Last + Reliability Policy: Best Effort + Image Source: + Value: Image topic + Image Topic: /demo/image + Transport: compressed + Synchronization: Synchronized + Tolerance [ms]: 5 + Image Buffer: 60 + Mask: + Value: true + Mode: Filled + contour + Alpha: 0.35 + Label: + Value: true + Format: "{id} {class} {class_prob}" + Font Size: 14 + - Class: perception_msgs/ImageObservations + Enabled: true + Name: Traffic signs + Topic: + Value: /demo/perception/traffic_signs + Depth: 5 + Durability Policy: Volatile + History Policy: Keep Last + Reliability Policy: Best Effort + Image Source: + Value: Crop mosaic + Mask: + Value: true + Mode: Contour + Color: Fixed + Label: + Value: true + Format: "{id} sign {exist}" + - Class: perception_msgs/ImageObservations + Enabled: true + Name: Traffic lights + Topic: + Value: /demo/perception/traffic_lights + Depth: 5 + Durability Policy: Volatile + History Policy: Keep Last + Reliability Policy: Best Effort + Image Source: + Value: Crop mosaic + Mask: + Value: true + Mode: Contour + Color: By object ID + Label: + Value: true + Format: "{id} light {exist}" + Global Options: + Fixed Frame: map + Views: + Current: + Class: rviz_default_plugins/Orbit + Distance: 15 +Window Geometry: + Displays: + collapsed: false + Road users: + collapsed: false + Traffic signs: + collapsed: false + Traffic lights: + collapsed: false + Hide Left Dock: false + Hide Right Dock: true + QMainWindow State: 000000ff00000000fd000000010000000000000638000003e8fc0200000001fc00000000000003e80000002c00fffffffc0100000002fb000000100044006900730070006c0061007900730100000000000001040000003a00fffffffc0000010a0000052e0000007a00fffffffc0200000002fb000000140052006f006100640020007500730065007200730100000000000002730000001300fffffffc000002790000016f0000001300fffffffc0100000002fb0000001a00540072006100660066006900630020007300690067006e0073010000010a000002940000003a00fffffffb0000001c00540072006100660066006900630020006c0069006700680074007301000003a4000002940000003a00ffffff00000002000003e800000004000000040000000800000008fc00000000 + Width: 1600 + Height: 1000 diff --git a/demo/visualization/open_image_view.py b/demo/visualization/open_image_view.py deleted file mode 100644 index ce4b418..0000000 --- a/demo/visualization/open_image_view.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python3 -# Copyright Institute for Automotive Engineering (ika), RWTH Aachen University -# SPDX-License-Identifier: Apache-2.0 - -"""Open the demo image viewer maximized.""" - -import sys - -from rqt_gui.main import Main - - -class MaximizedImageView(Main): - """Use the standard rqt image viewer with a maximized main window.""" - - def create_application(self, argv): - """Maximize the window after rqt finishes creating it.""" - app = super().create_application(argv) - from python_qt_binding.QtCore import QTimer - from python_qt_binding.QtWidgets import QMainWindow - - def maximize_window(): - """Adapt the viewer size to the current screen.""" - for widget in app.topLevelWidgets(): - if isinstance(widget, QMainWindow): - widget.showMaximized() - - QTimer.singleShot(0, maximize_window) - return app - - -if __name__ == "__main__": - sys.exit( - MaximizedImageView().main( - argv=[sys.argv[0], "--standalone", "rqt_image_view/ImageView", "--args", "/demo/overlay/instance"] - ) - ) diff --git a/deployment/compose/docker-compose.yml b/deployment/compose/docker-compose.yml index b3546c8..681816d 100644 --- a/deployment/compose/docker-compose.yml +++ b/deployment/compose/docker-compose.yml @@ -15,8 +15,6 @@ services: ROAD_USERS_TOPIC: ~/perception/road_users TRAFFIC_LIGHTS_TOPIC: ~/perception/traffic_lights TRAFFIC_SIGNS_TOPIC: ~/perception/traffic_signs - CLASS_OVERLAY_TOPIC: ~/debug/overlay/class - INSTANCE_OVERLAY_TOPIC: ~/debug/overlay/instance LOG_LEVEL: ${LOG_LEVEL:-info} USE_SIM_TIME: ${USE_SIM_TIME:-false} PARAMS: /docker-ros/ws/install/image_instance_segmentation/share/image_instance_segmentation/config/params.yml @@ -41,8 +39,6 @@ services: detections_topic:=$${DETECTIONS_TOPIC} \ road_users_topic:=$${ROAD_USERS_TOPIC} \ traffic_lights_topic:=$${TRAFFIC_LIGHTS_TOPIC} \ - traffic_signs_topic:=$${TRAFFIC_SIGNS_TOPIC} \ - class_overlay_topic:=$${CLASS_OVERLAY_TOPIC} \ - instance_overlay_topic:=$${INSTANCE_OVERLAY_TOPIC} + traffic_signs_topic:=$${TRAFFIC_SIGNS_TOPIC} # volumes: # - ./params.yml:/docker-ros/ws/install/image_instance_segmentation/share/image_instance_segmentation/config/params.yml diff --git a/deployment/helm/values.yaml b/deployment/helm/values.yaml index 3c23423..8e829b8 100644 --- a/deployment/helm/values.yaml +++ b/deployment/helm/values.yaml @@ -14,8 +14,6 @@ openadservice: ROAD_USERS_TOPIC: ~/perception/road_users TRAFFIC_LIGHTS_TOPIC: ~/perception/traffic_lights TRAFFIC_SIGNS_TOPIC: ~/perception/traffic_signs - CLASS_OVERLAY_TOPIC: ~/debug/overlay/class - INSTANCE_OVERLAY_TOPIC: ~/debug/overlay/instance LOG_LEVEL: info USE_SIM_TIME: false PARAMS: /docker-ros/ws/install/image_instance_segmentation/share/image_instance_segmentation/config/params.yml @@ -40,8 +38,6 @@ openadservice: detections_topic:=${DETECTIONS_TOPIC} \ road_users_topic:=${ROAD_USERS_TOPIC} \ traffic_lights_topic:=${TRAFFIC_LIGHTS_TOPIC} \ - traffic_signs_topic:=${TRAFFIC_SIGNS_TOPIC} \ - class_overlay_topic:=${CLASS_OVERLAY_TOPIC} \ - instance_overlay_topic:=${INSTANCE_OVERLAY_TOPIC} + traffic_signs_topic:=${TRAFFIC_SIGNS_TOPIC} rosParamFileMountPath: /docker-ros/ws/install/image_instance_segmentation/share/image_instance_segmentation/config/params.yml rosParamFileData: null diff --git a/docs/IMPLEMENTATION.md b/docs/IMPLEMENTATION.md index 7dd30ce..cd9f783 100644 --- a/docs/IMPLEMENTATION.md +++ b/docs/IMPLEMENTATION.md @@ -105,8 +105,10 @@ Cameras run concurrently with one Triton client each. Busy cameras drop frames at the admission limit. Set `prediction.max_in_flight_per_camera: 1` for low latency; tracking enforces this limit to preserve frame order. -Enable `debug.publish_overlay` for overlays and `debug.print_timing` for -processing times. +Enable `debug.print_timing` for processing times. To inspect results, enable +the `perception.publish_*` object lists and view their image observations with +the `perception_msgs/ImageObservations` RViz display from +[perception_interfaces](https://github.com/ika-rwth-aachen/perception_interfaces). Use `ros_tracing:=true` to enable OpenADS dual-session tracing. Service images include the `jazzy-ika` tracing fork. @@ -151,8 +153,8 @@ All settings below have the prefix `diagnostic_updater.` and are read-only. | `..nominal_frequency` | `0.0` Hz, disabling that topic check | | `..min_frequency` / `max_frequency` | `0.8` / `1.2` times nominal frequency | -`` is `input`, `class_mask`, `instance_mask` or `detections`; overlays are -demand-driven. Rate checks use five reports and the ROS clock. Output timestamp +`` is `input`, `class_mask`, `instance_mask` or `detections`; perception +object lists are demand-driven. Rate checks use five reports and the ROS clock. Output timestamp limits add `processing.timeout` to `inputs.max_age`. Topic details under `topic..` are `frequency_hz`, `{min,max,target}_frequency_hz`, `events_in_window`, `events_since_start`, `window_s`, `{min,max}_delay_s`, diff --git a/image_instance_segmentation/README.md b/image_instance_segmentation/README.md index 827710c..522485a 100644 --- a/image_instance_segmentation/README.md +++ b/image_instance_segmentation/README.md @@ -20,8 +20,6 @@ flowchart LR NODE -->|"joinTopic(config.output_prefix, 'perception/road_users')"| P3:::hidden NODE -->|"joinTopic(config.output_prefix, 'perception/traffic_lights')"| P4:::hidden NODE -->|"joinTopic(config.output_prefix, 'perception/traffic_signs')"| P5:::hidden - NODE -->|"joinTopic(config.output_prefix, 'debug/overlay/class')"| P6:::hidden - NODE -->|"joinTopic(config.output_prefix, 'debug/overlay/instance')"| P7:::hidden classDef hidden display: none; ``` @@ -41,8 +39,6 @@ flowchart LR | `joinTopic(config.output_prefix, "perception/road_users")` | `perception_msgs/msg/ObjectList` | Optional image-only road users (`HEXAMOTION`) with source camera observations | | `joinTopic(config.output_prefix, "perception/traffic_lights")` | `perception_msgs/msg/ObjectList` | Optional image-only traffic lights (`TRAFFICLIGHT`) with source camera observations | | `joinTopic(config.output_prefix, "perception/traffic_signs")` | `perception_msgs/msg/ObjectList` | Optional image-only traffic signs (`TRAFFICSIGN`) with source camera observations | -| `joinTopic(config.output_prefix, "debug/overlay/class")` | `sensor_msgs/msg/Image` | Optional `bgr8` overlay colored by class | -| `joinTopic(config.output_prefix, "debug/overlay/instance")` | `sensor_msgs/msg/Image` | Optional `bgr8` overlay colored by instance or track | #### Parameters @@ -83,10 +79,7 @@ flowchart LR | `perception.publish_traffic_signs` | `bool` | `false` | Publish image-only traffic-sign object lists | | `perception.include_crops` | `bool` | `true` | Include BGR image crops in perception objects | | `perception.include_masks` | `bool` | `true` | Include binary instance masks in perception objects | -| `debug.publish_overlay` | `bool` | `false` | Publish overlay images | | `debug.print_timing` | `bool` | `false` | Log inference, postprocessing, and total processing times | -| `debug.overlay_alpha` | `float` | `0.45` | Mask opacity in debug overlays | -| `debug.overlay_draw_boxes` | `bool` | `true` | Draw boxes and labels in debug overlays | | `cameras` | `string[]` | `["camera"]` | Names of cameras to process | | `sensor_id` | `int` | `1` | Non-negative camera identifier in perception observations | | `image_topic` | `string` | `"~/image"` | Raw image base topic | @@ -107,8 +100,6 @@ flowchart LR | `road_users_topic` | `"~/perception/road_users"` | road-user objects topic remap | | `traffic_lights_topic` | `"~/perception/traffic_lights"` | traffic-light objects topic remap | | `traffic_signs_topic` | `"~/perception/traffic_signs"` | traffic-sign objects topic remap | -| `class_overlay_topic` | `"~/debug/overlay/class"` | class overlay topic remap | -| `instance_overlay_topic` | `"~/debug/overlay/instance"` | instance overlay topic remap | | `name` | `"image_instance_segmentation"` | node name | | `namespace` | `""` | node namespace | | `params` | `os.path.join( diff --git a/image_instance_segmentation/config/params.yml b/image_instance_segmentation/config/params.yml index ca96abb..0fa802f 100644 --- a/image_instance_segmentation/config/params.yml +++ b/image_instance_segmentation/config/params.yml @@ -54,10 +54,7 @@ perception.include_crops: true perception.include_masks: true - debug.publish_overlay: false debug.print_timing: false - debug.overlay_alpha: 0.45 - debug.overlay_draw_boxes: true cameras: [camera] camera.camera.sensor_id: 1 diff --git a/image_instance_segmentation/include/image_instance_segmentation/ImageInstanceSegmentation.hpp b/image_instance_segmentation/include/image_instance_segmentation/ImageInstanceSegmentation.hpp index 6b433ff..9935f75 100644 --- a/image_instance_segmentation/include/image_instance_segmentation/ImageInstanceSegmentation.hpp +++ b/image_instance_segmentation/include/image_instance_segmentation/ImageInstanceSegmentation.hpp @@ -87,11 +87,6 @@ enum class ModelArchitecture { RfDetr, // RF-DETR-Seg: stretch, per-query class logits and mask logits, NMS }; -enum class OverlayColorMode { - Class, - Instance, -}; - struct PerceptionClass { std::uint8_t model_id = 0; std::uint8_t classification = 0; @@ -162,8 +157,6 @@ class ImageInstanceSegmentation : public rclcpp::Node { rclcpp::Publisher::SharedPtr road_users_publisher; rclcpp::Publisher::SharedPtr traffic_lights_publisher; rclcpp::Publisher::SharedPtr traffic_signs_publisher; - image_transport::Publisher class_overlay_publisher; - image_transport::Publisher instance_overlay_publisher; rclcpp::CallbackGroup::SharedPtr callback_group; std::unique_ptr tracker; std::atomic in_flight{0}; @@ -271,8 +264,7 @@ class ImageInstanceSegmentation : public rclcpp::Node { /** @brief Keep confidence-ordered detections using class-specific IoU * suppression. */ std::vector applyNms(std::vector detections) const; - /** @brief Publish masks and detection metadata, and generate overlays only - * when requested. */ + /** @brief Publish masks, detection metadata, and enabled perception object lists. */ void publishResults(const CameraRuntime& camera, const std_msgs::msg::Header& header, const cv::Mat& bgr_image, @@ -307,13 +299,6 @@ class ImageInstanceSegmentation : public rclcpp::Node { /** @brief Copy a mono16 mask into a ROS image while preserving the input * header. */ sensor_msgs::msg::Image matToMono16Image(const cv::Mat& mask, const std_msgs::msg::Header& header) const; - /** @brief Blend instance mask ROIs onto the input image and optionally draw - * labeled boxes. */ - sensor_msgs::msg::Image makeOverlay(const cv::Mat& bgr_image, - const std::vector& detections, - const std::vector& masks, - const std_msgs::msg::Header& header, - OverlayColorMode color_mode) const; /** @brief Build original-image detections with class scores and optional * per-camera track IDs. */ vision_msgs::msg::Detection2DArray makeDetectionsMessage(const std::vector& detections, @@ -372,9 +357,6 @@ class ImageInstanceSegmentation : public rclcpp::Node { double nms_iou_threshold_ = 0.45; TrackerConfig tracker_config_; bool print_timing_ = false; - bool publish_overlay_ = false; - double overlay_alpha_ = 0.45; - bool overlay_draw_boxes_ = true; std::vector camera_configs_; std::unordered_map cameras_; diff --git a/image_instance_segmentation/launch/image_instance_segmentation.launch.py b/image_instance_segmentation/launch/image_instance_segmentation.launch.py index d94882e..4f24f92 100644 --- a/image_instance_segmentation/launch/image_instance_segmentation.launch.py +++ b/image_instance_segmentation/launch/image_instance_segmentation.launch.py @@ -37,14 +37,6 @@ def generate_launch_description(): DeclareLaunchArgument( "traffic_signs_topic", default_value="~/perception/traffic_signs", description="traffic-sign objects topic remap" ), - DeclareLaunchArgument( - "class_overlay_topic", default_value="~/debug/overlay/class", description="class overlay topic remap" - ), - DeclareLaunchArgument( - "instance_overlay_topic", - default_value="~/debug/overlay/instance", - description="instance overlay topic remap", - ), ] args = [ DeclareLaunchArgument("name", default_value="image_instance_segmentation", description="node name"), diff --git a/image_instance_segmentation/src/ImageInstanceSegmentation.cpp b/image_instance_segmentation/src/ImageInstanceSegmentation.cpp index 880957c..df1a5e9 100644 --- a/image_instance_segmentation/src/ImageInstanceSegmentation.cpp +++ b/image_instance_segmentation/src/ImageInstanceSegmentation.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -56,8 +55,6 @@ ImageInstanceSegmentation::CameraRuntime::CameraRuntime(CameraRuntime&& other) n road_users_publisher(std::move(other.road_users_publisher)), traffic_lights_publisher(std::move(other.traffic_lights_publisher)), traffic_signs_publisher(std::move(other.traffic_signs_publisher)), - class_overlay_publisher(std::move(other.class_overlay_publisher)), - instance_overlay_publisher(std::move(other.instance_overlay_publisher)), callback_group(std::move(other.callback_group)), tracker(std::move(other.tracker)), in_flight(other.in_flight.load()) {} @@ -72,8 +69,6 @@ ImageInstanceSegmentation::CameraRuntime& ImageInstanceSegmentation::CameraRunti road_users_publisher = std::move(other.road_users_publisher); traffic_lights_publisher = std::move(other.traffic_lights_publisher); traffic_signs_publisher = std::move(other.traffic_signs_publisher); - class_overlay_publisher = std::move(other.class_overlay_publisher); - instance_overlay_publisher = std::move(other.instance_overlay_publisher); callback_group = std::move(other.callback_group); tracker = std::move(other.tracker); in_flight.store(other.in_flight.load()); @@ -265,30 +260,6 @@ InstanceMask maskFromLogits( return mask; } -/** @brief Choose a repeatable BGR overlay color from the palette. */ -cv::Scalar colorForInstance(std::size_t index) { - static const std::array colors = {cv::Scalar(255, 56, 56), cv::Scalar(255, 157, 151), cv::Scalar(255, 112, 31), - cv::Scalar(255, 178, 29), cv::Scalar(207, 210, 49), cv::Scalar(72, 249, 10), - cv::Scalar(146, 204, 23), cv::Scalar(61, 219, 134), cv::Scalar(26, 147, 52), - cv::Scalar(0, 212, 187), cv::Scalar(44, 153, 168), cv::Scalar(0, 194, 255)}; - return colors[index % colors.size()]; -} - -// Instances keep a stable color across frames by keying off the track ID when -// tracking is enabled; otherwise they fall back to the (frame-local, unstable) -// detection index. -/** @brief Choose the palette index from semantic class, track ID, or - * frame-local instance. */ -std::size_t overlayColorIndex(const Detection& detection, - std::size_t detection_index, - OverlayColorMode color_mode, - bool tracking_enabled) { - if (color_mode == OverlayColorMode::Class) { - return static_cast(detection.class_index); - } - return tracking_enabled && detection.track_id != 0 ? static_cast(detection.track_id - 1) : detection_index; -} - /** @brief Validate image storage and convert supported encodings to BGR; BGR * input shares storage. */ cv::Mat rawImageToBgr(const sensor_msgs::msg::Image& msg) { @@ -971,13 +942,8 @@ void ImageInstanceSegmentation::loadParameters() { declareAndLoadParameter("perception.include_masks", perception_include_masks_, "Include binary instance masks in perception objects"); - declareAndLoadParameter("debug.publish_overlay", publish_overlay_, "Publish overlay images", true, false, false); declareAndLoadParameter("debug.print_timing", print_timing_, "Log inference, postprocessing, and total processing times", true, false, false); - declareAndLoadParameter("debug.overlay_alpha", overlay_alpha_, "Mask opacity in debug overlays", true, false, false, 0.0, 1.0, - 0.0); - declareAndLoadParameter("debug.overlay_draw_boxes", overlay_draw_boxes_, "Draw boxes and labels in debug overlays", true, false, - false); if (tracker_config_.enabled && max_in_flight_per_camera_ != 1) { RCLCPP_INFO(get_logger(), @@ -1038,8 +1004,6 @@ void ImageInstanceSegmentation::validateParameters() const { if (!std::isfinite(mask_threshold_) || mask_threshold_ < 0.0 || mask_threshold_ > 1.0) fail("mask threshold must be in [0, 1]"); if (!std::isfinite(nms_iou_threshold_) || nms_iou_threshold_ < 0.0 || nms_iou_threshold_ > 1.0) fail("NMS IoU threshold must be in [0, 1]"); - if (!std::isfinite(overlay_alpha_) || overlay_alpha_ < 0.0 || overlay_alpha_ > 1.0) - fail("debug.overlay_alpha must be in [0, 1]"); if (tracker_config_.backend != "bytetrack") fail("tracking.backend must be 'bytetrack'"); if (!std::isfinite(tracker_config_.low_confidence_threshold) || tracker_config_.low_confidence_threshold < 0.0 || tracker_config_.low_confidence_threshold > 1.0) { @@ -1183,12 +1147,6 @@ void ImageInstanceSegmentation::setupCameras() { if (publish_traffic_signs_) runtime.traffic_signs_publisher = create_publisher( joinTopic(config.output_prefix, "perception/traffic_signs"), rclcpp::SensorDataQoS(), pub_options); - runtime.class_overlay_publisher = image_transport::create_publisher( - this, get_node_topics_interface()->resolve_topic_name(joinTopic(config.output_prefix, "debug/overlay/class")), - rclcpp::SensorDataQoS().get_rmw_qos_profile(), pub_options); - runtime.instance_overlay_publisher = image_transport::create_publisher( - this, get_node_topics_interface()->resolve_topic_name(joinTopic(config.output_prefix, "debug/overlay/instance")), - rclcpp::SensorDataQoS().get_rmw_qos_profile(), pub_options); runtime.image_subscriber = image_transport::create_subscription( this, get_node_topics_interface()->resolve_topic_name(config.image_topic), [this, name = config.name](const sensor_msgs::msg::Image::ConstSharedPtr& msg) { imageCallback(msg, name); }, @@ -1809,14 +1767,6 @@ void ImageInstanceSegmentation::publishResults(const CameraRuntime& camera, camera.instance_mask_publisher->publish(matToMono16Image(instance_mask, header)); camera.detections_publisher->publish(makeDetectionsMessage(detections, header)); publishPerceptionObjects(camera, header, bgr_image, detections, masks); - if (publish_overlay_) { - if (camera.class_overlay_publisher && camera.class_overlay_publisher.getNumSubscribers() > 0) { - camera.class_overlay_publisher.publish(makeOverlay(bgr_image, detections, masks, header, OverlayColorMode::Class)); - } - if (camera.instance_overlay_publisher && camera.instance_overlay_publisher.getNumSubscribers() > 0) { - camera.instance_overlay_publisher.publish(makeOverlay(bgr_image, detections, masks, header, OverlayColorMode::Instance)); - } - } } sensor_msgs::msg::Image ImageInstanceSegmentation::matToMono16Image(const cv::Mat& mask, @@ -1837,70 +1787,6 @@ sensor_msgs::msg::Image ImageInstanceSegmentation::matToMono16Image(const cv::Ma return msg; } -sensor_msgs::msg::Image ImageInstanceSegmentation::makeOverlay(const cv::Mat& bgr_image, - const std::vector& detections, - const std::vector& masks, - const std_msgs::msg::Header& header, - OverlayColorMode color_mode) const { - cv::Mat overlay = bgr_image.clone(); - - // Alpha-blend each instance's mask color into the camera image, restricted to - // that mask's pixels, so unsegmented background stays untouched instead of - // turning black. - cv::Mat color_layer(overlay.size(), overlay.type(), cv::Scalar(0, 0, 0)); - cv::Mat coverage(overlay.size(), CV_8UC1, cv::Scalar(0)); - for (std::size_t i = 0; i < detections.size() && i < masks.size(); ++i) { - const std::size_t color_index = overlayColorIndex(detections[i], i, color_mode, tracker_config_.enabled); - if (masks[i].pixels.empty()) continue; - color_layer(masks[i].roi).setTo(colorForInstance(color_index), masks[i].pixels); - coverage(masks[i].roi).setTo(255, masks[i].pixels); - } - cv::Mat blended; - cv::addWeighted(overlay, 1.0 - overlay_alpha_, color_layer, overlay_alpha_, 0.0, blended); - blended.copyTo(overlay, coverage); - - if (overlay_draw_boxes_) { - for (std::size_t i = 0; i < detections.size(); ++i) { - const Detection& detection = detections[i]; - const std::size_t color_index = overlayColorIndex(detection, i, color_mode, tracker_config_.enabled); - const cv::Scalar color = colorForInstance(color_index); - - const cv::Rect box = boxRoi(detection.box, overlay.cols, overlay.rows); - cv::rectangle(overlay, box, color, 2); - - std::string label = detection.class_index >= 0 && static_cast(detection.class_index) < class_names_.size() - ? class_names_[static_cast(detection.class_index)] - : "?"; - if (tracker_config_.enabled && detection.track_id != 0) { - label += " #" + std::to_string(detection.track_id); - } - char score_suffix[16]; - std::snprintf(score_suffix, sizeof(score_suffix), " %.2f", static_cast(detection.score)); - label += score_suffix; - - int baseline = 0; - const cv::Size text_size = cv::getTextSize(label, cv::FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseline); - const int label_bottom = std::max(box.y, text_size.height + 4); - cv::rectangle(overlay, cv::Point(box.x, label_bottom - text_size.height - 4), - cv::Point(box.x + text_size.width + 4, label_bottom), color, cv::FILLED); - cv::putText(overlay, label, cv::Point(box.x + 2, label_bottom - 2), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 0, 0), 1, - cv::LINE_AA); - } - } - - sensor_msgs::msg::Image msg; - msg.header = header; - msg.height = static_cast(overlay.rows); - msg.width = static_cast(overlay.cols); - msg.encoding = sensor_msgs::image_encodings::BGR8; - msg.is_bigendian = false; - msg.step = static_cast(overlay.cols * overlay.elemSize()); - const std::size_t size = static_cast(msg.step) * msg.height; - msg.data.resize(size); - std::memcpy(msg.data.data(), overlay.data, size); - return msg; -} - vision_msgs::msg::Detection2DArray ImageInstanceSegmentation::makeDetectionsMessage(const std::vector& detections, const std_msgs::msg::Header& header) const { vision_msgs::msg::Detection2DArray msg; From 08b8229cdbaa3ad6ed893d3a4b897bd3ba0064e1 Mon Sep 17 00:00:00 2001 From: Lukas Ostendorf Date: Tue, 17 Nov 2026 19:13:11 +0100 Subject: [PATCH 5/6] Update perception object state initialization to include CONTINUOUS_STATE_UNMEASURED --- image_instance_segmentation/src/PerceptionOutputs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/image_instance_segmentation/src/PerceptionOutputs.cpp b/image_instance_segmentation/src/PerceptionOutputs.cpp index e2c2a40..eee98d1 100644 --- a/image_instance_segmentation/src/PerceptionOutputs.cpp +++ b/image_instance_segmentation/src/PerceptionOutputs.cpp @@ -100,7 +100,7 @@ void ImageInstanceSegmentation::publishPerceptionObjects(const CameraRuntime& ca if (object.id == 0) throw std::overflow_error("Untracked object ID exhausted"); } object.existence_probability = detection.score; - initializeState(object, model_id); + initializeState(object, model_id, CONTINUOUS_STATE_UNMEASURED); object.state.header = header; object.state.sensor_id.push_back(static_cast(camera.config.sensor_id)); if (model_id == perception_msgs::msg::HEXAMOTION::MODEL_ID) { From d60dd4b9d9f3a6d2d4e57b637710c75a13b4f427 Mon Sep 17 00:00:00 2001 From: Lukas Ostendorf Date: Wed, 18 Nov 2026 16:34:50 +0100 Subject: [PATCH 6/6] Update perception message types to use ObjectListWithEvidence for road users, traffic lights, and traffic signs --- .repos | 2 +- demo/visualization/demo.rviz | 6 +++--- docs/IMPLEMENTATION.md | 10 ++++----- image_instance_segmentation/README.md | 8 +++---- .../ImageInstanceSegmentation.hpp | 8 +++---- .../src/ImageInstanceSegmentation.cpp | 8 +++---- .../src/PerceptionOutputs.cpp | 21 +++++++++++-------- 7 files changed, 33 insertions(+), 30 deletions(-) diff --git a/.repos b/.repos index d8f9336..5a35fd6 100644 --- a/.repos +++ b/.repos @@ -6,4 +6,4 @@ repositories: perception_interfaces: type: git url: https://github.com/ika-rwth-aachen/perception_interfaces.git - version: 900b05f02fa3452a2ee1735eac79d9e7886329fd + version: d908af198393c3b26bedea259080b5d7b1060716 diff --git a/demo/visualization/demo.rviz b/demo/visualization/demo.rviz index c8eaa3a..e1b2883 100644 --- a/demo/visualization/demo.rviz +++ b/demo/visualization/demo.rviz @@ -4,7 +4,7 @@ Panels: Visualization Manager: Class: "" Displays: - - Class: perception_msgs/ImageObservations + - Class: perception_msgs/ImageEvidence Enabled: true Name: Road users Topic: @@ -28,7 +28,7 @@ Visualization Manager: Value: true Format: "{id} {class} {class_prob}" Font Size: 14 - - Class: perception_msgs/ImageObservations + - Class: perception_msgs/ImageEvidence Enabled: true Name: Traffic signs Topic: @@ -46,7 +46,7 @@ Visualization Manager: Label: Value: true Format: "{id} sign {exist}" - - Class: perception_msgs/ImageObservations + - Class: perception_msgs/ImageEvidence Enabled: true Name: Traffic lights Topic: diff --git a/docs/IMPLEMENTATION.md b/docs/IMPLEMENTATION.md index cd9f783..d58d39e 100644 --- a/docs/IMPLEMENTATION.md +++ b/docs/IMPLEMENTATION.md @@ -10,7 +10,7 @@ List camera names in `cameras` and configure each under `camera.`: | Parameter | Meaning | | --- | --- | -| `camera..sensor_id` | Unique camera ID for perception observations; defaults to its 1-based position in `cameras` | +| `camera..sensor_id` | Unique camera ID for perception evidence; defaults to its 1-based position in `cameras` | | `camera..image_topic` | Base image topic | | `camera..transport` | `raw` or `compressed`; omit `/compressed` from the base topic | | `camera..output_prefix` | Prefix for camera output topics | @@ -51,7 +51,7 @@ perception.publish_traffic_signs: true Topics are `perception/road_users`, `perception/traffic_lights` and `perception/traffic_signs` under each camera's output prefix. They carry -`perception_msgs/msg/ObjectList` with `HEXAMOTION`, `TRAFFICLIGHT` and `TRAFFICSIGN` +`perception_msgs/msg/ObjectListWithEvidence` with `HEXAMOTION`, `TRAFFICLIGHT` and `TRAFFICSIGN` states respectively. Metric components remain unmeasured; light state, sign type and road-user light states remain unknown. @@ -61,7 +61,7 @@ Object IDs persist for a tracked object's lifetime and are not recycled when mask IDs are reused. Without tracking, each published detection gets a fresh ID. IDs are scoped to a camera stream and node lifetime. -Observations retain source coordinates and headers. `perception.include_crops` +Image evidence retains source coordinates and headers. `perception.include_crops` and `perception.include_masks` independently include BGR crops and binary `mono8` ROI masks. Pixels are prepared only for subscribed outputs; empty lists are published for processed frames without matching detections. @@ -106,8 +106,8 @@ at the admission limit. Set `prediction.max_in_flight_per_camera: 1` for low latency; tracking enforces this limit to preserve frame order. Enable `debug.print_timing` for processing times. To inspect results, enable -the `perception.publish_*` object lists and view their image observations with -the `perception_msgs/ImageObservations` RViz display from +the `perception.publish_*` object lists and view their image evidence with +the `perception_msgs/ImageEvidence` RViz display from [perception_interfaces](https://github.com/ika-rwth-aachen/perception_interfaces). Use `ros_tracing:=true` to enable OpenADS dual-session tracing. Service images include the `jazzy-ika` tracing fork. diff --git a/image_instance_segmentation/README.md b/image_instance_segmentation/README.md index 522485a..93ece1c 100644 --- a/image_instance_segmentation/README.md +++ b/image_instance_segmentation/README.md @@ -36,9 +36,9 @@ flowchart LR | `joinTopic(config.output_prefix, "segmentation/class_mask")` | `sensor_msgs/msg/Image` | `mono16` semantic class IDs; zero is background | | `joinTopic(config.output_prefix, "segmentation/instance_mask")` | `sensor_msgs/msg/Image` | `mono16` instance IDs; track IDs when tracking is enabled; zero is background | | `joinTopic(config.output_prefix, "segmentation/detections")` | `vision_msgs/msg/Detection2DArray` | Pixel-coordinate boxes, class names, confidence scores, and optional track IDs | -| `joinTopic(config.output_prefix, "perception/road_users")` | `perception_msgs/msg/ObjectList` | Optional image-only road users (`HEXAMOTION`) with source camera observations | -| `joinTopic(config.output_prefix, "perception/traffic_lights")` | `perception_msgs/msg/ObjectList` | Optional image-only traffic lights (`TRAFFICLIGHT`) with source camera observations | -| `joinTopic(config.output_prefix, "perception/traffic_signs")` | `perception_msgs/msg/ObjectList` | Optional image-only traffic signs (`TRAFFICSIGN`) with source camera observations | +| `joinTopic(config.output_prefix, "perception/road_users")` | `perception_msgs/msg/ObjectListWithEvidence` | Optional image-only road users (`HEXAMOTION`) with source camera evidence | +| `joinTopic(config.output_prefix, "perception/traffic_lights")` | `perception_msgs/msg/ObjectListWithEvidence` | Optional image-only traffic lights (`TRAFFICLIGHT`) with source camera evidence | +| `joinTopic(config.output_prefix, "perception/traffic_signs")` | `perception_msgs/msg/ObjectListWithEvidence` | Optional image-only traffic signs (`TRAFFICSIGN`) with source camera evidence | #### Parameters @@ -81,7 +81,7 @@ flowchart LR | `perception.include_masks` | `bool` | `true` | Include binary instance masks in perception objects | | `debug.print_timing` | `bool` | `false` | Log inference, postprocessing, and total processing times | | `cameras` | `string[]` | `["camera"]` | Names of cameras to process | -| `sensor_id` | `int` | `1` | Non-negative camera identifier in perception observations | +| `sensor_id` | `int` | `1` | Non-negative camera identifier in perception evidence | | `image_topic` | `string` | `"~/image"` | Raw image base topic | | `transport` | `string` | `"raw"` | Image transport hint: raw or compressed | | `output_prefix` | `string` | `"~"` | Prefix for this camera's output topics | diff --git a/image_instance_segmentation/include/image_instance_segmentation/ImageInstanceSegmentation.hpp b/image_instance_segmentation/include/image_instance_segmentation/ImageInstanceSegmentation.hpp index 9935f75..0ceceef 100644 --- a/image_instance_segmentation/include/image_instance_segmentation/ImageInstanceSegmentation.hpp +++ b/image_instance_segmentation/include/image_instance_segmentation/ImageInstanceSegmentation.hpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include @@ -154,9 +154,9 @@ class ImageInstanceSegmentation : public rclcpp::Node { rclcpp::Publisher::SharedPtr class_mask_publisher; rclcpp::Publisher::SharedPtr instance_mask_publisher; rclcpp::Publisher::SharedPtr detections_publisher; - rclcpp::Publisher::SharedPtr road_users_publisher; - rclcpp::Publisher::SharedPtr traffic_lights_publisher; - rclcpp::Publisher::SharedPtr traffic_signs_publisher; + rclcpp::Publisher::SharedPtr road_users_publisher; + rclcpp::Publisher::SharedPtr traffic_lights_publisher; + rclcpp::Publisher::SharedPtr traffic_signs_publisher; rclcpp::CallbackGroup::SharedPtr callback_group; std::unique_ptr tracker; std::atomic in_flight{0}; diff --git a/image_instance_segmentation/src/ImageInstanceSegmentation.cpp b/image_instance_segmentation/src/ImageInstanceSegmentation.cpp index df1a5e9..9883c16 100644 --- a/image_instance_segmentation/src/ImageInstanceSegmentation.cpp +++ b/image_instance_segmentation/src/ImageInstanceSegmentation.cpp @@ -964,7 +964,7 @@ void ImageInstanceSegmentation::loadParameters() { config.image_topic = "~/" + name + "/image"; config.output_prefix = "~/" + name; } - declareAndLoadParameter(prefix + "sensor_id", config.sensor_id, "Non-negative camera identifier in perception observations"); + declareAndLoadParameter(prefix + "sensor_id", config.sensor_id, "Non-negative camera identifier in perception evidence"); declareAndLoadParameter(prefix + "image_topic", config.image_topic, "Raw image base topic"); declareAndLoadParameter(prefix + "transport", config.transport, "Image transport hint: raw or compressed"); declareAndLoadParameter(prefix + "output_prefix", config.output_prefix, "Prefix for this camera's output topics"); @@ -1139,13 +1139,13 @@ void ImageInstanceSegmentation::setupCameras() { runtime.detections_publisher = create_publisher( joinTopic(config.output_prefix, "segmentation/detections"), rclcpp::SensorDataQoS(), pub_options); if (publish_road_users_) - runtime.road_users_publisher = create_publisher( + runtime.road_users_publisher = create_publisher( joinTopic(config.output_prefix, "perception/road_users"), rclcpp::SensorDataQoS(), pub_options); if (publish_traffic_lights_) - runtime.traffic_lights_publisher = create_publisher( + runtime.traffic_lights_publisher = create_publisher( joinTopic(config.output_prefix, "perception/traffic_lights"), rclcpp::SensorDataQoS(), pub_options); if (publish_traffic_signs_) - runtime.traffic_signs_publisher = create_publisher( + runtime.traffic_signs_publisher = create_publisher( joinTopic(config.output_prefix, "perception/traffic_signs"), rclcpp::SensorDataQoS(), pub_options); runtime.image_subscriber = image_transport::create_subscription( this, get_node_topics_interface()->resolve_topic_name(config.image_topic), diff --git a/image_instance_segmentation/src/PerceptionOutputs.cpp b/image_instance_segmentation/src/PerceptionOutputs.cpp index eee98d1..3614828 100644 --- a/image_instance_segmentation/src/PerceptionOutputs.cpp +++ b/image_instance_segmentation/src/PerceptionOutputs.cpp @@ -81,19 +81,20 @@ void ImageInstanceSegmentation::publishPerceptionObjects(const CameraRuntime& ca const std::vector& detections, const std::vector& masks) const { using namespace perception_msgs::object_access; - // Image observations require a valid source camera header. + // Image evidence requires a valid source camera header. if (header.frame_id.empty() || header.stamp.sec < 0 || header.stamp.nanosec >= 1000000000u) return; - const auto publish = [&](const rclcpp::Publisher::SharedPtr& publisher, + const auto publish = [&](const rclcpp::Publisher::SharedPtr& publisher, std::uint8_t model_id) { if (!publisher || (publisher->get_subscription_count() == 0 && publisher->get_intra_process_subscription_count() == 0)) return; - auto objects = std::make_unique(); + auto objects = std::make_unique(); objects->header = header; for (std::size_t i = 0; i < detections.size(); ++i) { const auto& detection = detections[i]; const auto& classification = perception_classes_.at(static_cast(detection.class_index)); if (classification.model_id != model_id) continue; - perception_msgs::msg::Object object; + perception_msgs::msg::ObjectWithEvidence entry; + auto& object = entry.object; object.id = detection.object_id; if (!detection.is_tracked) { object.id = next_untracked_object_id_.fetch_add(1, std::memory_order_relaxed); @@ -111,9 +112,10 @@ void ImageInstanceSegmentation::publishPerceptionObjects(const CameraRuntime& ca } else if (model_id == perception_msgs::msg::TRAFFICLIGHT::MODEL_ID) { setTrafficLightType(object, perception_msgs::msg::TRAFFICLIGHT::TYPE_UNKNOWN); } - perception_msgs::msg::ImageObservation image; - image.header = header; - image.sensor_id = static_cast(camera.config.sensor_id); + perception_msgs::msg::Evidence evidence; + evidence.header = header; + evidence.sensor_id = static_cast(camera.config.sensor_id); + perception_msgs::msg::ImageEvidence image; image.image_width = static_cast(bgr_image.cols); image.image_height = static_cast(bgr_image.rows); image.bounding_box.center.position.x = detection.box.x + detection.box.width * 0.5; @@ -130,8 +132,9 @@ void ImageInstanceSegmentation::publishPerceptionObjects(const CameraRuntime& ca if (perception_include_masks_ && i < masks.size() && !masks[i].pixels.empty()) image.mask = roiImage(masks[i].pixels, header, sensor_msgs::image_encodings::MONO8); } - object.state.image_observations.push_back(std::move(image)); - objects->objects.push_back(std::move(object)); + evidence.image.push_back(std::move(image)); + entry.evidence.push_back(std::move(evidence)); + objects->objects.push_back(std::move(entry)); } publisher->publish(std::move(objects)); };