ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

Hi Rydel!

Regarding which topic to subscribe, the topic camera/rgb/image_raw provides the raw image from the device with Bayer GRBG format (for kinect) and the topic camera/rgb/image_color provides the image already in RGB format.

So, between both of them, I would recommend you to subscribe to camera/rgb/image_color as it is already in RGB format. But, if you calibrated your camera, it would be even better to subscribe to the topic camera/rgb/image_rect_color (generated by the package openni_launch) as it provides the color rectified image (no lens distortion).

To handle the image the best option is to use OpenCV library, the package cv_bridge makes it really easy to transform from ROS images to OpenCV images. You can find a tutorial here.

Once you have your image in OpenCV you can, for example, access the horizontal line in the middle of the image like this:

cv::Mat received_image;

/* ... Subscribe to the topic... */
/* ... Convert image to OpenCV using cv_bridge ...*/  

//the matrix middle line will contain the horizontal line in the middle of the image
cv::Mat middle_line = received_image.row(received_image.rows/2);

I hope you find it helpful.

Hi Rydel!

Regarding which topic to subscribe, the topic camera/rgb/image_raw provides the raw image from the device with Bayer GRBG format (for kinect) and the topic camera/rgb/image_color provides the image already in RGB format.

So, between both of them, I would recommend you to subscribe to camera/rgb/image_color as it is already in RGB format. But, if you calibrated your camera, it would be even better to subscribe to the topic camera/rgb/image_rect_color (generated by the package openni_launch) as it provides the color rectified image (no lens distortion).

To handle the image the best option is to use OpenCV library, the package cv_bridge makes it really easy to transform from ROS images to OpenCV images. You can find a tutorial here.

By the way, never mind the image data being published as a 1-dimensional array, the data is serialized when published and with cv_bridge everything is being taken care for you.

Once you have your image in OpenCV you can, for example, access the horizontal line in the middle of the image like this:

cv::Mat received_image;

/* ... Subscribe to the topic... */
/* ... Convert image to OpenCV using cv_bridge ...*/  

//the matrix middle line will contain the horizontal line in the middle of the image
cv::Mat middle_line = received_image.row(received_image.rows/2);

I hope you find it helpful.