Skip to content

Commit 935e84e

Browse files
multi cam works on rgb+info
1 parent 01e742e commit 935e84e

File tree

2 files changed

+65
-27
lines changed

2 files changed

+65
-27
lines changed

src/extended_object_detection_node/eod_node.cpp

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,37 @@ EOD_ROS::EOD_ROS(ros::NodeHandle nh, ros::NodeHandle nh_p){
3333

3434
frame_sequence = 0;
3535

36-
rgb_it_ = new image_transport::ImageTransport(nh_);
37-
38-
sub_rgb_.subscribe(*rgb_it_, "camera/image_raw", 10);
39-
sub_info_.subscribe(nh_, "camera/info", 10);
36+
//rgb_it_ = new image_transport::ImageTransport(nh_);
4037

4138
detect_rate_values = new boost::circular_buffer<double>(10);
4239

4340
// get params
44-
nh_p_.param("subscribe_depth", subscribe_depth, false);
41+
//nh_p_.param("subscribe_depth", subscribe_depth, false);
42+
43+
// multicamera stuff
44+
std::vector<std::string> rgb_image_topics;
45+
nh_p_.getParam("rgb_image_topics", rgb_image_topics);
46+
std::vector<std::string> rgb_info_topics;
47+
nh_p_.getParam("rgb_info_topics", rgb_info_topics);
48+
49+
if( rgb_image_topics.size() != rgb_info_topics.size() || rgb_image_topics.size() == 0){
50+
ROS_ERROR("rgb_image_topics have to be same size as rgb_info_topics and more than 0! Exit.");
51+
std::exit(-1);
52+
}
53+
54+
std::vector<std::string> depth_image_topics;
55+
nh_p_.getParam("depth_image_topics", depth_image_topics);
56+
std::vector<std::string> depth_info_topics;
57+
nh_p_.getParam("depth_info_topics", depth_info_topics);
58+
if( depth_image_topics.size() != depth_info_topics.size()){
59+
ROS_ERROR("depth_image_topics have to be same size as depth_info_topics! Exit.");
60+
std::exit(-1);
61+
}
62+
if( depth_image_topics.size() != 0 && depth_image_topics.size() != rgb_image_topics.size() ){
63+
ROS_ERROR("depth_image_topics have to be same size as rgb_image_topics or 0! Exit.");
64+
std::exit(-1);
65+
}
66+
4567
nh_p_.param("rate_limit_sec", rate_limit_sec, 0.1);
4668
nh_p_.param("publish_image_output", publish_image_output, false);
4769
nh_p_.param("use_actual_time", use_actual_time, false);
@@ -114,20 +136,36 @@ EOD_ROS::EOD_ROS(ros::NodeHandle nh, ros::NodeHandle nh_p){
114136
private_it_ = new image_transport::ImageTransport(nh_p_);
115137
output_image_pub_ = private_it_->advertise("detected_image", 1);
116138

117-
// set up message filters
118-
if( !subscribe_depth){
119-
//ROS_INFO("Configuring filter on rgb image and info...");
120-
rgb_sync_.reset( new RGBSynchronizer(RGBInfoSyncPolicy(10), sub_rgb_, sub_info_) );
121-
rgb_sync_->registerCallback(boost::bind(&EOD_ROS::rgb_info_cb, this, boost::placeholders::_1, boost::placeholders::_2));
122-
}
123-
else{
124-
//ROS_INFO("Configuring filter on rgbd images and infos...");
125-
sub_depth_.subscribe(*rgb_it_, "depth/image_raw", 10);
126-
sub_depth_info_.subscribe(nh_, "depth/info", 10);
139+
for( size_t i = 0 ; i < rgb_image_topics.size() ; i++ ){
140+
141+
ROS_INFO("Bounding %s and %s...",rgb_image_topics[i].c_str(), rgb_info_topics[i].c_str());
142+
143+
rgb_it_.push_back(new image_transport::ImageTransport(nh_));
144+
sub_rgb_.push_back(new image_transport::SubscriberFilter());
145+
sub_info_.push_back(new message_filters::Subscriber<sensor_msgs::CameraInfo>());
127146

128-
rgbd_sync_.reset( new RGBDSynchronizer(RGBDInfoSyncPolicy(10), sub_rgb_, sub_info_, sub_depth_, sub_depth_info_) );
129-
rgbd_sync_->registerCallback(boost::bind(&EOD_ROS::rgbd_info_cb, this, boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3, boost::placeholders::_4));
130-
}
147+
sub_rgb_[i]->subscribe(*rgb_it_[i], rgb_image_topics[i], 10);
148+
sub_info_[i]->subscribe(nh_, rgb_info_topics[i], 10);
149+
150+
// set up message filters
151+
if( depth_image_topics.size() == 0 ){
152+
153+
154+
rgb_sync_.push_back(new boost::shared_ptr<RGBSynchronizer>());
155+
rgb_sync_[i]->reset(new RGBSynchronizer(RGBInfoSyncPolicy(10), *sub_rgb_[i], *sub_info_[i]) );
156+
157+
(*rgb_sync_[i])->registerCallback(boost::bind(&EOD_ROS::rgb_info_cb, this, boost::placeholders::_1, boost::placeholders::_2));
158+
}
159+
/* else{
160+
//ROS_INFO("Configuring filter on rgbd images and infos...");
161+
sub_depth_.subscribe(*rgb_it_, "depth/image_raw", 10);
162+
sub_depth_info_.subscribe(nh_, "depth/info", 10);
163+
164+
rgbd_sync_.reset( new RGBDSynchronizer(RGBDInfoSyncPolicy(10), sub_rgb_, sub_info_, sub_depth_, sub_depth_info_) );
165+
rgbd_sync_->registerCallback(boost::bind(&EOD_ROS::rgbd_info_cb, this, boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3, boost::placeholders::_4));
166+
}*/
167+
168+
}
131169
//ROS_INFO("Configured!");
132170
}
133171

@@ -235,7 +273,7 @@ void EOD_ROS::rgbd_info_cb(const sensor_msgs::ImageConstPtr& rgb_image, const se
235273

236274

237275
void EOD_ROS::detect(const eod::InfoImage& rgb, const eod::InfoImage& depth, std_msgs::Header header){
238-
//ROS_INFO("Detecting...");
276+
ROS_INFO("Detecting...");
239277
if( frame_sequence != 0 ){
240278
detect_rate_values->push_back((ros::Time::now() - prev_detected_time).toSec());
241279
}

src/extended_object_detection_node/eod_node.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ class EOD_ROS{
4343
private:
4444
// ros stuff
4545
ros::NodeHandle nh_, nh_p_;
46-
image_transport::ImageTransport *rgb_it_;
47-
image_transport::SubscriberFilter sub_rgb_;
48-
message_filters::Subscriber<sensor_msgs::CameraInfo> sub_info_;
49-
boost::shared_ptr<RGBSynchronizer> rgb_sync_;
46+
std::vector<image_transport::ImageTransport*> rgb_it_;
47+
std::vector<image_transport::SubscriberFilter*> sub_rgb_;
48+
std::vector<message_filters::Subscriber<sensor_msgs::CameraInfo>* > sub_info_;
49+
std::vector<boost::shared_ptr<RGBSynchronizer>* > rgb_sync_;
5050

51-
image_transport::ImageTransport *depth_it_;
52-
image_transport::SubscriberFilter sub_depth_;
53-
message_filters::Subscriber<sensor_msgs::CameraInfo> sub_depth_info_;
54-
boost::shared_ptr<RGBDSynchronizer> rgbd_sync_;
51+
std::vector<image_transport::ImageTransport*> depth_it_;
52+
std::vector<image_transport::SubscriberFilter> sub_depth_;
53+
std::vector<message_filters::Subscriber<sensor_msgs::CameraInfo> > sub_depth_info_;
54+
std::vector<boost::shared_ptr<RGBDSynchronizer> > rgbd_sync_;
5555

5656
ros::Publisher simple_objects_pub_;
5757
ros::Publisher simple_objects_markers_pub_;

0 commit comments

Comments
 (0)