Wednesday, April 11, 2012

Converting ROS messages to Open CV images

Following tutorial provides a comprehensive explanation and implementation details about converting ros messages to opencv images.

http://siddhantahuja.wordpress.com/2011/07/20/working-with-ros-and-opencv-draft/

This tutorial works with RGB images, and you can easily extend it to depth images
 Make sure you change the subscribed topic and image encodings e.g 16UC1 for raw depth data, following code snippet might be of help :)

 for (int i=0;i<cv_ptr->image.rows;i++)
     {
         for (int j=0;j<cv_ptr->image.cols;j++)
         {
           
             pixel_depth = cv_ptr->image.data[i*cv_ptr->image.cols+j];
             if (pixel_depth == 0)
             {
               // do your stuff 
             }
         }
     }

No comments:

Post a Comment