Ask Your Question

PLEASE HELP: 2 cameras subscriber & Depth perception code problem

asked 2016-06-07 20:16:19 -0600

laurent gravatar image

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: (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 ( ) 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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-06-08 03:27:22 -0600

updated 2016-06-08 05:02:08 -0600

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));


  return 0;
edit flag offensive delete link more


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)

laurent gravatar imagelaurent ( 2016-06-08 07:49:19 -0600 )edit

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

chwimmer gravatar imagechwimmer ( 2016-06-08 08:36:00 -0600 )edit

Okay, thank you so much!!!

laurent gravatar imagelaurent ( 2016-06-08 08:55:46 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2016-06-07 20:16:19 -0600

Seen: 130 times

Last updated: Jun 08 '16