DepthAI ROS Integration

repository·develop·Indexed 43 days ago

https://github.com/luxonis/depthai-ros

ROS (Robot Operating System) integration and nodes for Luxonis OAK cameras, enabling depth sensing and AI capabilities. Includes tools like ImgSubscriber for bridging ROS 2 image topics into DepthAI pipelines and depthai_bridge::ImageConverter for transforming sensor_msgs::msg::Image data into dai::ImgFrame objects.

Tokens
709
Snippets
3
Records
3
Agent score
7%

What's inside DepthAI ROS

  1. Disable DepthAI ROS telemetry

    develop

    The library collects anonymized telemetry (such as node usage frequency and session duration) to improve the software. You can opt out of this data collection by setting the DEPTHAI_TELEMETRY environment variable to 0.

    export DEPTHAI_TELEMETRY=0
  2. Use depthai_bridge::ImageConverter for ROS to DepthAI conversion

    develop

    The depthai_bridge::ImageConverter is used within a host node to transform sensor_msgs::msg::Image data into dai::ImgFrame objects that the DepthAI pipeline can process.

    When initializing the converter, you can specify a frame prefix (e.g., for TF transformations) and a boolean flag for color conversion/handling.

    // Example initialization
    // Parameter 1: TF frame prefix
    // Parameter 2: Boolean flag (e.g., for color/format handling)
    auto rgbConverter = std::make_shared<depthai_bridge::ImageConverter>("oak_rgb_camera_optical_frame", true);
  3. Implement an RGB Subscriber using ImgSubscriber

    develop

    The ImgSubscriber class (derived from dai::node::ThreadedHostNode) allows you to bridge ROS 2 image topics into a DepthAI pipeline.

    To use it:

    1. Create an instance of ImgSubscriber within a dai::Pipeline.
    2. Call createSubScription(rclcpp_node_ptr) to link the node to a specific ROS 2 topic (defaulting to rgb_image in this implementation).
    3. Assign a depthai_bridge::ImageConverter to the conv member to handle the conversion from ROS messages to dai::ImgFrame.
    4. Link the output of the ImgSubscriber to subsequent nodes in your pipeline.
    dai::Pipeline pipeline;
    
    // 1. Create the subscriber node
    auto rosSubscriberNode = pipeline.create<ImgSubscriber>();
    
    // 2. Link to ROS 2 node and topic
    rosSubscriberNode->createSubScription(node);
    
    // 3. Configure the converter (e.g., for TF frame naming)
    auto rgbConverter = std::make_shared<depthai_bridge::ImageConverter>(tfPrefix + "_rgb_camera_optical_frame", true);
    rosSubscriberNode->conv = rgbConverter;
    
    // 4. Link output to next node
    auto display = pipeline.create<HostDisplay>();
    rosSubscriberNode->output.link(display->inputs["frame"]);
    
    pipeline.start();