how to stream realsense camera image in ros !!

asked 2017-04-17 04:14:44 -0500

zubair gravatar image

updated 2017-04-17 04:15:37 -0500

hello guys

 int main( int argc, char** argv )
 {
     rs::context ctx;

     // Access the first available RealSense device
     rs::device * dev = ctx.get_device(0);

     // Configure color stream to run at VGA resolution at 30 frames per second
     dev->enable_stream(rs::stream::color, 640, 480, rs::format::bgr8, 30);

     // We must also configure depth stream
     dev->enable_stream(rs::stream::depth, 640, 480, rs::format::z16, 30);


     // Start streaming
     dev->start();



     // Determine depth value corresponding to one meter
     //const uint16_t one_meter = static_cast<uint16_t>(1.0f / dev->get_depth_scale());


     // Creating OpenCV Matrix from a color image
     Mat color(Size(640, 480), CV_8UC3, (void*)dev->get_frame_data(rs::stream::color), Mat::AUTO_STEP);

     // Creating OpenCV Matrix from a depth image
     Mat depth(Size(640, 480), CV_16U, (void*)dev->get_frame_data(rs::stream::depth), Mat::AUTO_STEP);




     float scale = dev->get_depth_scale();




     // Display in a GUI
     namedWindow("Display Image depth", WINDOW_AUTOSIZE );
     namedWindow("Display Image", WINDOW_AUTOSIZE );
     namedWindow("Control", CV_WINDOW_AUTOSIZE); //create a window called "Control"

     int iLowH = 38;
     int iHighH = 75;

     int iLowS = 150;
     int iHighS = 255;

     int iLowV = 60;
     int iHighV = 255;

     //Create trackbars in "Control" window
     createTrackbar("LowH", "Control", &iLowH, 179); //Hue (0 - 179)
     createTrackbar("HighH", "Control", &iHighH, 179);

     createTrackbar("LowS", "Control", &iLowS, 255); //Saturation (0 - 255)
     createTrackbar("HighS", "Control", &iHighS, 255);

     createTrackbar("LowV", "Control", &iLowV, 255);//Value (0 - 255)
     createTrackbar("HighV", "Control", &iHighV, 255);



     //Create a black image with the size as the camera output
     Mat imgLines = Mat::zeros(color.size(), CV_8UC3 );;

this is my code, and as you can see in the starting i have done initialization of my realsense camera , now that i have converted this as ros node,, i want to stream images over ros with rviz or image_view,, what changes do i need to do in this code ??? remember, of those streams from my camera i am converting to MAT for further processing .. i have originally made this over eclipse and i was working properly,, now over ros i just need same output on image_veiw or rviz,, and want to know how can i initialize my camera .

please help !!

thanks

edit retag flag offensive close merge delete

Comments

I wonder why you are not using the official realsense ros driver.

Humpelstilzchen gravatar image Humpelstilzchen  ( 2017-04-18 02:28:40 -0500 )edit