@@ -35,7 +35,7 @@ EOD_ROS::EOD_ROS(ros::NodeHandle nh, ros::NodeHandle nh_p){
3535
3636 // rgb_it_ = new image_transport::ImageTransport(nh_);
3737
38- detect_rate_values = new boost::circular_buffer<double >(10 );
38+ // detect_rate_values = new boost::circular_buffer<double>(10);
3939
4040 // get params
4141 // nh_p_.param("subscribe_depth", subscribe_depth, false);
@@ -63,14 +63,15 @@ EOD_ROS::EOD_ROS(ros::NodeHandle nh, ros::NodeHandle nh_p){
6363 ROS_ERROR (" depth_image_topics have to be same size as rgb_image_topics or 0! Exit." );
6464 std::exit (-1 );
6565 }
66-
66+
6767 nh_p_.param (" rate_limit_sec" , rate_limit_sec, 0.1 );
6868 nh_p_.param (" publish_image_output" , publish_image_output, false );
6969 nh_p_.param (" use_actual_time" , use_actual_time, false );
7070 nh_p_.param (" publish_markers" , publish_markers, false );
7171 nh_p_.param (" broadcast_tf" , broadcast_tf, false );
7272 nh_p_.param (" allowed_lag_sec" , allowed_lag_sec, 0.0 );
7373 nh_p_.param (" subs_queue_size" , subs_queue_size, 10 );
74+ nh_p_.param (" stats_window" , stats_window, 10 );
7475
7576 std::string object_base_path;
7677 nh_p_.getParam (" object_base" ,object_base_path);
@@ -134,11 +135,8 @@ EOD_ROS::EOD_ROS(ros::NodeHandle nh, ros::NodeHandle nh_p){
134135#endif
135136 }
136137
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+
142140
143141 // setup subscribers
144142 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){
176174 rgbd_sync_[i]->reset ( new RGBDSynchronizer (RGBDInfoSyncPolicy (subs_queue_size), *sub_rgb_[i], *sub_info_[i], *sub_depth_[i], *sub_depth_info_[i]) );
177175
178176 (*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+ }
180178
181179 }
182180 // ROS_INFO("Configured!");
183181}
184182
185183
186184bool 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 ;
190196 }
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;
192198}
193199
194200
@@ -221,15 +227,18 @@ cv::Mat EOD_ROS::getD(const sensor_msgs::CameraInfoConstPtr& info_msg){
221227
222228
223229void EOD_ROS::rgb_info_cb (const sensor_msgs::ImageConstPtr& rgb_image, const sensor_msgs::CameraInfoConstPtr& rgb_info){
230+ publish_stats ();
224231 // ROS_INFO("Got Image!");
225232 // CHECK RATE
226233 if ( !check_time (ros::Time::now (), rgb_image->header .frame_id ) ) {
227234 // ROS_WARN("Skipped frame");
235+ stats[rgb_image->header .frame_id ].skipped_frames ++;
228236 return ;
229237 }
230238 double lag;
231239 if ( !check_lag (rgb_image->header .stamp , lag) ) {
232240 // ROS_WARN("Dropped frame, lag = %f", lag);
241+ stats[rgb_image->header .frame_id ].dropped_frames ++;
233242 return ;
234243 }
235244 cv::Mat rgb;
@@ -246,15 +255,18 @@ void EOD_ROS::rgb_info_cb(const sensor_msgs::ImageConstPtr& rgb_image, const sen
246255
247256
248257void 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 ();
249259 // ROS_INFO("Got RGBD!");
250260 // CHECK RATE
251261 if ( !check_time (ros::Time::now (), rgb_image->header .frame_id ) ) {
252262 // ROS_WARN("Skipped frame");
263+ stats[rgb_image->header .frame_id ].skipped_frames ++;
253264 return ;
254265 }
255266 double lag;
256267 if ( !check_lag (rgb_image->header .stamp , lag) ) {
257268 // ROS_WARN("Dropped frame, lag = %f", lag);
269+ stats[rgb_image->header .frame_id ].dropped_frames ++;
258270 return ;
259271 }
260272 // 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
290302
291303void EOD_ROS::detect (const eod::InfoImage& rgb, const eod::InfoImage& depth, std_msgs::Header header){
292304 // 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 ());
295313 }
296- prev_detected_time[header.frame_id ] = ros::Time::now ();
314+
315+ stats[header.frame_id ].prev_detected_time = ros::Time::now ();
297316
298317 if ( header.frame_id [0 ] == ' /' )
299318 header.frame_id .erase (0 ,1 );
@@ -406,7 +425,8 @@ void EOD_ROS::detect(const eod::InfoImage& rgb, const eod::InfoImage& depth, std
406425 sensor_msgs::ImagePtr detected_image_msg = cv_bridge::CvImage (std_msgs::Header (), " bgr8" , image_to_draw).toImageMsg ();
407426 output_image_pubs_[header.frame_id ].publish (detected_image_msg);
408427 }
409- frame_sequence++;
428+ frame_sequence++;
429+ stats[header.frame_id ].proceeded_frames ++;
410430 // cv::waitKey(1);
411431}
412432
@@ -468,7 +488,7 @@ visualization_msgs::Marker EOD_ROS::base_object_to_marker_arrow(extended_object_
468488 mrk.ns = base_object.type_name +" _arrow" ;
469489 mrk.id = id;
470490 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 ));
472492 mrk.points .push_back (geometry_msgs::Point ());
473493 geometry_msgs::Point end = fromVector (base_object.transform .translation );
474494 mrk.points .push_back (end);
@@ -493,7 +513,7 @@ visualization_msgs::Marker EOD_ROS::base_object_to_marker_frame(extended_object_
493513 mrk.ns = base_object.type_name +" _frame" ;
494514 mrk.id = id;
495515 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 ));
497517 for ( auto & corner : base_object.rect .cornerTranslates )
498518 mrk.points .push_back (fromVector (corner));
499519 mrk.points .push_back (mrk.points [0 ]);
@@ -515,7 +535,7 @@ visualization_msgs::Marker EOD_ROS::base_object_to_marker_text(extended_object_d
515535 mrk.ns = base_object.type_name +" _text" ;
516536 mrk.id = id;
517537 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 ));
519539 mrk.pose .position = fromVector (base_object.transform .translation );
520540 mrk.pose .position .y = base_object.rect .cornerTranslates [0 ].y - 0.14 ; // place text upper top frame part
521541 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
651671#endif
652672
653673
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 () )
656676 return 0 ;
657677 double sum_rate = 0 ;
658- for (auto & rate : *detect_rate_values)
678+ for (auto & rate : *(stats[frame_id]. detect_rate_values ) )
659679 sum_rate += rate;
660- return sum_rate / detect_rate_values->size ();
680+ return sum_rate / stats[frame_id]. detect_rate_values ->size ();
661681}
662682
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+ }
663696
664697int main (int argc, char **argv)
665698{
0 commit comments