본문 바로가기
Libraries & Packages/RealSense

Realsense Image Publish in ROS

by yongee97 2023. 7. 4.

* Github(Private)

https://github.com/yongeePark/rs_depth_alignment.git

 

 

* Convert Realsense image input to opencv image

Example

    // RGB stream
    cfg.enable_stream(RS2_STREAM_COLOR,640, 480, RS2_FORMAT_RGB8, fps);
    // Depth stream
    cfg.enable_stream(RS2_STREAM_DEPTH,640, 480, RS2_FORMAT_Z16, fps);
    // Infrared stream
    cfg.enable_stream(RS2_STREAM_INFRARED,640, 480, RS2_FORMAT_Y8, fps);
    
        auto depth_frame     = frameset.get_depth_frame();
        auto color_frame     = frameset.get_color_frame();
        auto infra1_frame    = frameset.get_infrared_frame(1);
        auto infra2_frame    = frameset.get_infrared_frame(2);

 

RGB : RS2_FORMAT_RGB8

Depth : RS2_FORMAT_Z16

infrared : RS2_FORMAT_Y8

 

 

* Convert OpenCV image into ros image message

Example

   		sensor_msgs::ImagePtr image_msg, depth_msg, infra1_msg, infra2_msg;
        cv::Mat im, depth, infra1, infra2;
        
        im     = cv::Mat(cv::Size(width_img, height_img), CV_8UC3, (void*)(color_frame.get_data()),  cv::Mat::AUTO_STEP);
        depth  = cv::Mat(cv::Size(width_img, height_img), CV_16U,  (void*)(depth_frame.get_data()),  cv::Mat::AUTO_STEP);
        infra1 = cv::Mat(cv::Size(width_img, height_img), CV_8UC1, (void*)(infra1_frame.get_data()), cv::Mat::AUTO_STEP);
        
        image_msg = cv_bridge::CvImage(std_msgs::Header(), "rgb8", im).toImageMsg();
        image_msg->header.stamp = ros::Time::now();
        pub_image.publish(image_msg);

        depth_msg = cv_bridge::CvImage(std_msgs::Header(), "mono16", depth).toImageMsg();
        depth_msg->header.stamp = ros::Time::now();
        pub_depth.publish(depth_msg);

        infra1_msg = cv_bridge::CvImage(std_msgs::Header(), "mono8", infra1).toImageMsg();
        infra1_msg->header.stamp = ros::Time::now();
        pub_infra1.publish(infra1_msg);

RGB : CV_8UC3 / rgb8

Depth : CV_16U / mono16

infrared : CV_8UC1 / mono8

 

 

 

 

* Reference

http://wiki.ros.org/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages

 

cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages - ROS Wiki

Concepts ROS passes around images in its own sensor_msgs/Image message format, but many users will want to use images in conjunction with OpenCV. CvBridge is a ROS library that provides an interface between ROS and OpenCV. CvBridge can be found in the cv_b

wiki.ros.org

https://github.com/IntelRealSense/librealsense/issues/10940

 

How to convert RS2_FORMAT_BGR8 infrared channel to RS2_FORMAT_Y8 infrared channel? · Issue #10940 · IntelRealSense/librealsens

Required Info Camera Model D400 Firmware Version (Open RealSense Viewer --> Click info) Operating System & Version Win10 Kernel Version (Linux Only) Platform PC SDK Version { legacy / 2.. } Languag...

github.com

http://docs.ros.org/en/kinetic/api/librealsense2/html/rs__sensor_8h.html

 

librealsense2: rs_sensor.h File Reference

Exposes RealSense sensor functionality for C compilers. Definition in file rs_sensor.h.

docs.ros.org

https://github.com/IntelRealSense/librealsense/issues/1480

 

Export IR and RGB image from D400 to PNG · Issue #1480 · IntelRealSense/librealsense

Hi, I need to get the images of the 2 IR cameras and the rgb camera. For now, I successfully export the IR left and right image using OpenCV but I have issue with the RGB one. I think the format CV...

github.com