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

PLEASE HELP: 2 cameras subscriber & Depth perception code problem

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

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: http://wiki.ros.org/cv_bridge/Tutoria... (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/... ) 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
0

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

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

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;
}
edit flag offensive delete link more

Comments

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 image laurent  ( 2016-06-08 07:49:19 -0500 )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 image chwimmer  ( 2016-06-08 08:36:00 -0500 )edit

Okay, thank you so much!!!

laurent gravatar image laurent  ( 2016-06-08 08:55:46 -0500 )edit

Question Tools

Stats

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

Seen: 294 times

Last updated: Jun 08 '16