0
$\begingroup$

Rosanswers logo

So I'm trying to build a depth map using two stereo images , from two cameras on my baxter robot. The structure of my code looks very similar to this one here: http://wiki.ros.org/cv_bridge/Tutorials/ConvertingBetweenROSImagesAndOpenCVImagesPython (the code under "01 An example ROS node")

My code is exactly like that one, minus all the rows columns and channels operations (basically my code is just taking a picture from my robot's camera, converting it to an opencv2 type and then displaying it)

What i want to be able to do, is to subscribe to a second camera, and using this piece of code (http://docs.opencv.org/master/dd/d53/tutorial_py_depthmap.html#gsc.tab=0) be able to create a depth map.

My problem is, with the main code structure that i have, i don't know how to subscribe to a second camera (do i need a second callback function?) and how/where would i add in the piece of code for the depth map operation?


Originally posted by laurent on ROS Answers with karma: 21 on 2016-06-07

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I think what you are searching for is the message_filters package espacially the Time Synchronizer. Try this example:

#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include <sensor_msgs/Image.h>

using namespace sensor_msgs;
using namespace message_filters;

void callback(const ImageConstPtr& image1, const ImageConstPtr& image2)
{
  // Enter the cv_bridge here like you did before
}

int main(int argc, char** argv)
{
  ros::init(argc, argv, "vision_node");

  ros::NodeHandle nh;

  message_filters::Subscriber<Image> image1_sub(nh, "image1_topic", 1);
  message_filters::Subscriber<Image> image2_sub(nh, "image2_topic", 1);
  TimeSynchronizer<Image, Image> sync(image1_sub, image2_sub, 10);
  sync.registerCallback(boost::bind(&callback, _1, _2));

  ros::spin();

  return 0;
}

Originally posted by chwimmer with karma: 436 on 2016-06-08

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by laurent on 2016-06-08:
So, at what point should i use the map depth code? (I'm unfamiliar with c++ so im having a hard time understanding the code structure)

Comment by chwimmer on 2016-06-08:
is python more familiar to you? There is also a python example at the link i posted. You can do your processing in the callback function than. Just use the cv_bridge first for conversion and than use the OpenCV Algorithm

Comment by laurent on 2016-06-08:
Okay, thank you so much!!!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.