@@ -35,7 +35,7 @@ EOD_ROS::EOD_ROS(ros::NodeHandle nh, ros::NodeHandle nh_p){
35
35
36
36
// rgb_it_ = new image_transport::ImageTransport(nh_);
37
37
38
- detect_rate_values = new boost::circular_buffer<double >(10 );
38
+ // detect_rate_values = new boost::circular_buffer<double>(10);
39
39
40
40
// get params
41
41
// nh_p_.param("subscribe_depth", subscribe_depth, false);
@@ -63,14 +63,15 @@ EOD_ROS::EOD_ROS(ros::NodeHandle nh, ros::NodeHandle nh_p){
63
63
ROS_ERROR (" depth_image_topics have to be same size as rgb_image_topics or 0! Exit." );
64
64
std::exit (-1 );
65
65
}
66
-
66
+
67
67
nh_p_.param (" rate_limit_sec" , rate_limit_sec, 0.1 );
68
68
nh_p_.param (" publish_image_output" , publish_image_output, false );
69
69
nh_p_.param (" use_actual_time" , use_actual_time, false );
70
70
nh_p_.param (" publish_markers" , publish_markers, false );
71
71
nh_p_.param (" broadcast_tf" , broadcast_tf, false );
72
72
nh_p_.param (" allowed_lag_sec" , allowed_lag_sec, 0.0 );
73
73
nh_p_.param (" subs_queue_size" , subs_queue_size, 10 );
74
+ nh_p_.param (" stats_window" , stats_window, 10 );
74
75
75
76
std::string object_base_path;
76
77
nh_p_.getParam (" object_base" ,object_base_path);
@@ -134,11 +135,8 @@ EOD_ROS::EOD_ROS(ros::NodeHandle nh, ros::NodeHandle nh_p){
134
135
#endif
135
136
}
136
137
137
- // setup output image publishers
138
- // if( publish_image_output ){
139
- // private_it_ = new image_transport::ImageTransport(nh_p_);
140
- // output_image_pub_ = private_it_->advertise("detected_image", 1);
141
- // }
138
+ stats_pub_ = nh_p_.advertise <extended_object_detection::StatsArray>(" stats" , 1 );
139
+
142
140
143
141
// setup subscribers
144
142
for ( size_t i = 0 ; i < rgb_image_topics.size () ; i++ ){
@@ -176,19 +174,27 @@ EOD_ROS::EOD_ROS(ros::NodeHandle nh, ros::NodeHandle nh_p){
176
174
rgbd_sync_[i]->reset ( new RGBDSynchronizer (RGBDInfoSyncPolicy (subs_queue_size), *sub_rgb_[i], *sub_info_[i], *sub_depth_[i], *sub_depth_info_[i]) );
177
175
178
176
(*rgbd_sync_[i])->registerCallback (boost::bind (&EOD_ROS::rgbd_info_cb, this , boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3, boost::placeholders::_4));
179
- }
177
+ }
180
178
181
179
}
182
180
// ROS_INFO("Configured!");
183
181
}
184
182
185
183
186
184
bool EOD_ROS::check_time (const ros::Time& stamp, std::string frame_id){
187
- if ( frame_sequence == 0 ){
188
- prev_detected_time[frame_id] = stamp;
189
- return true ;
185
+ // if( frame_sequence == 0){
186
+ // prev_detected_time[frame_id] = stamp;
187
+ // return true;
188
+ // }
189
+ // return (stamp - prev_detected_time[frame_id]).toSec() > rate_limit_sec;
190
+
191
+ if (stats.find (frame_id) == stats.end ()){
192
+ stats[frame_id] = StreamStats ();
193
+ stats[frame_id].detect_rate_values = new boost::circular_buffer<double >(stats_window);
194
+ stats[frame_id].prev_detected_time = stamp;
195
+ return true ;
190
196
}
191
- return (stamp - prev_detected_time [frame_id]).toSec () > rate_limit_sec;
197
+ return (stamp - stats [frame_id]. prev_detected_time ).toSec () > rate_limit_sec;
192
198
}
193
199
194
200
@@ -221,15 +227,18 @@ cv::Mat EOD_ROS::getD(const sensor_msgs::CameraInfoConstPtr& info_msg){
221
227
222
228
223
229
void EOD_ROS::rgb_info_cb (const sensor_msgs::ImageConstPtr& rgb_image, const sensor_msgs::CameraInfoConstPtr& rgb_info){
230
+ publish_stats ();
224
231
// ROS_INFO("Got Image!");
225
232
// CHECK RATE
226
233
if ( !check_time (ros::Time::now (), rgb_image->header .frame_id ) ) {
227
234
// ROS_WARN("Skipped frame");
235
+ stats[rgb_image->header .frame_id ].skipped_frames ++;
228
236
return ;
229
237
}
230
238
double lag;
231
239
if ( !check_lag (rgb_image->header .stamp , lag) ) {
232
240
// ROS_WARN("Dropped frame, lag = %f", lag);
241
+ stats[rgb_image->header .frame_id ].dropped_frames ++;
233
242
return ;
234
243
}
235
244
cv::Mat rgb;
@@ -246,15 +255,18 @@ void EOD_ROS::rgb_info_cb(const sensor_msgs::ImageConstPtr& rgb_image, const sen
246
255
247
256
248
257
void EOD_ROS::rgbd_info_cb (const sensor_msgs::ImageConstPtr& rgb_image, const sensor_msgs::CameraInfoConstPtr& rgb_info, const sensor_msgs::ImageConstPtr& depth_image, const sensor_msgs::CameraInfoConstPtr& depth_info){
258
+ publish_stats ();
249
259
// ROS_INFO("Got RGBD!");
250
260
// CHECK RATE
251
261
if ( !check_time (ros::Time::now (), rgb_image->header .frame_id ) ) {
252
262
// ROS_WARN("Skipped frame");
263
+ stats[rgb_image->header .frame_id ].skipped_frames ++;
253
264
return ;
254
265
}
255
266
double lag;
256
267
if ( !check_lag (rgb_image->header .stamp , lag) ) {
257
268
// ROS_WARN("Dropped frame, lag = %f", lag);
269
+ stats[rgb_image->header .frame_id ].dropped_frames ++;
258
270
return ;
259
271
}
260
272
// TODO add possibility to exclude old stamp images (if detection goes to slow)
@@ -290,10 +302,17 @@ void EOD_ROS::rgbd_info_cb(const sensor_msgs::ImageConstPtr& rgb_image, const se
290
302
291
303
void EOD_ROS::detect (const eod::InfoImage& rgb, const eod::InfoImage& depth, std_msgs::Header header){
292
304
// ROS_INFO("Detecting...");
293
- if ( frame_sequence != 0 ){
294
- detect_rate_values->push_back ((ros::Time::now () - prev_detected_time[header.frame_id ]).toSec ());
305
+
306
+ // if( frame_sequence != 0 ){
307
+ // stats[header.frame_id].detect_rate_values->push_back((ros::Time::now() - stats[header.frame_id].prev_detected_time).toSec());
308
+ // }
309
+ //
310
+ // store data for detect rate calculus
311
+ if ( stats[header.frame_id ].proceeded_frames != 0 ){
312
+ stats[header.frame_id ].detect_rate_values ->push_back ((ros::Time::now () - stats[header.frame_id ].prev_detected_time ).toSec ());
295
313
}
296
- prev_detected_time[header.frame_id ] = ros::Time::now ();
314
+
315
+ stats[header.frame_id ].prev_detected_time = ros::Time::now ();
297
316
298
317
if ( header.frame_id [0 ] == ' /' )
299
318
header.frame_id .erase (0 ,1 );
@@ -406,7 +425,8 @@ void EOD_ROS::detect(const eod::InfoImage& rgb, const eod::InfoImage& depth, std
406
425
sensor_msgs::ImagePtr detected_image_msg = cv_bridge::CvImage (std_msgs::Header (), " bgr8" , image_to_draw).toImageMsg ();
407
426
output_image_pubs_[header.frame_id ].publish (detected_image_msg);
408
427
}
409
- frame_sequence++;
428
+ frame_sequence++;
429
+ stats[header.frame_id ].proceeded_frames ++;
410
430
// cv::waitKey(1);
411
431
}
412
432
@@ -468,7 +488,7 @@ visualization_msgs::Marker EOD_ROS::base_object_to_marker_arrow(extended_object_
468
488
mrk.ns = base_object.type_name +" _arrow" ;
469
489
mrk.id = id;
470
490
mrk.type = visualization_msgs::Marker::ARROW;
471
- mrk.lifetime = ros::Duration (get_detect_rate ());
491
+ mrk.lifetime = ros::Duration (get_detect_rate (header. frame_id ));
472
492
mrk.points .push_back (geometry_msgs::Point ());
473
493
geometry_msgs::Point end = fromVector (base_object.transform .translation );
474
494
mrk.points .push_back (end);
@@ -493,7 +513,7 @@ visualization_msgs::Marker EOD_ROS::base_object_to_marker_frame(extended_object_
493
513
mrk.ns = base_object.type_name +" _frame" ;
494
514
mrk.id = id;
495
515
mrk.type = visualization_msgs::Marker::LINE_STRIP;
496
- mrk.lifetime = ros::Duration (get_detect_rate ());
516
+ mrk.lifetime = ros::Duration (get_detect_rate (header. frame_id ));
497
517
for ( auto & corner : base_object.rect .cornerTranslates )
498
518
mrk.points .push_back (fromVector (corner));
499
519
mrk.points .push_back (mrk.points [0 ]);
@@ -515,7 +535,7 @@ visualization_msgs::Marker EOD_ROS::base_object_to_marker_text(extended_object_d
515
535
mrk.ns = base_object.type_name +" _text" ;
516
536
mrk.id = id;
517
537
mrk.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
518
- mrk.lifetime = ros::Duration (get_detect_rate ());
538
+ mrk.lifetime = ros::Duration (get_detect_rate (header. frame_id ));
519
539
mrk.pose .position = fromVector (base_object.transform .translation );
520
540
mrk.pose .position .y = base_object.rect .cornerTranslates [0 ].y - 0.14 ; // place text upper top frame part
521
541
mrk.text = std::to_string (base_object.type_id )+" :" +base_object.type_name +" [" +std::to_string (base_object.score ).substr (0 ,4 )+" ]" ;
@@ -651,15 +671,28 @@ bool EOD_ROS::set_complex_objects_cb(extended_object_detection::SetObjects::Requ
651
671
#endif
652
672
653
673
654
- double EOD_ROS::get_detect_rate (){
655
- if ( detect_rate_values->empty () )
674
+ double EOD_ROS::get_detect_rate (std::string frame_id ){
675
+ if ( stats[frame_id]. detect_rate_values ->empty () )
656
676
return 0 ;
657
677
double sum_rate = 0 ;
658
- for (auto & rate : *detect_rate_values)
678
+ for (auto & rate : *(stats[frame_id]. detect_rate_values ) )
659
679
sum_rate += rate;
660
- return sum_rate / detect_rate_values->size ();
680
+ return sum_rate / stats[frame_id]. detect_rate_values ->size ();
661
681
}
662
682
683
+ void EOD_ROS::publish_stats (){
684
+ extended_object_detection::StatsArray stats_array;
685
+ for ( const auto & stat : stats ){
686
+ extended_object_detection::StatsStream stream;
687
+ stream.frame_id = stat.first ;
688
+ stream.proceeded_frames = stat.second .proceeded_frames ;
689
+ stream.dropped_frames = stat.second .dropped_frames ;
690
+ stream.skipped_frames = stat.second .skipped_frames ;
691
+ stream.mean_rate = get_detect_rate (stat.first );
692
+ stats_array.streams .push_back (stream);
693
+ }
694
+ stats_pub_.publish (stats_array);
695
+ }
663
696
664
697
int main (int argc, char **argv)
665
698
{
0 commit comments