Skip to content

Commit d75679f

Browse files
added stats publish
1 parent 4f76aaa commit d75679f

File tree

6 files changed

+84
-30
lines changed

6 files changed

+84
-30
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ add_message_files(
5555
SimpleObjectArray.msg
5656
ComplexObject.msg
5757
ComplexObjectArray.msg
58+
StatsStream.msg
59+
StatsArray.msg
5860
)
5961

6062
## Generate services in the 'srv' folder

launch/extended_object_detection_oakd_example.launch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<param name="object_base" value="$(arg objectBasePath)"/>
1717

1818
<param name="rate_limit_sec" value="0.1"/>
19-
<param name="allowed_lag_sec" value="1"/>
19+
<param name="allowed_lag_sec" value="0"/>
2020
<param name="publish_image_output" value="true"/>
2121
<param name="publish_markers" value="true"/>
2222
<param name="broadcast_tf" value="true"/>

msg/StatsArray.msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extended_object_detection/StatsStream[] streams

msg/StatsStream.msg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
string frame_id
2+
int32 proceeded_frames
3+
int32 skipped_frames
4+
int32 dropped_frames
5+
float64 mean_rate

src/extended_object_detection_node/eod_node.cpp

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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

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

223229
void 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

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

291303
void 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

664697
int main(int argc, char **argv)
665698
{

src/extended_object_detection_node/eod_node.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "extended_object_detection/SimpleObjectArray.h"
2121
#include "extended_object_detection/ComplexObjectArray.h"
2222
#include "extended_object_detection/SetObjects.h"
23+
#include "extended_object_detection/StatsArray.h"
24+
#include "extended_object_detection/StatsStream.h"
2325

2426
#include <boost/circular_buffer.hpp>
2527

@@ -35,6 +37,14 @@ typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::Image, sens
3537
typedef message_filters::Synchronizer<RGBDInfoSyncPolicy> RGBDSynchronizer;
3638

3739

40+
struct StreamStats{
41+
ros::Time prev_detected_time;
42+
int proceeded_frames = 0;
43+
int dropped_frames = 0;
44+
int skipped_frames = 0;
45+
boost::circular_buffer<double>* detect_rate_values;
46+
};
47+
3848
class EOD_ROS{
3949
public:
4050
EOD_ROS(ros::NodeHandle nh, ros::NodeHandle nh_p);
@@ -59,9 +69,9 @@ class EOD_ROS{
5969
ros::Publisher complex_objects_pub_;
6070
ros::Publisher complex_objects_markers_pub_;
6171
#endif
62-
std::map<std::string, image_transport::Publisher> output_image_pubs_;
63-
//image_transport::ImageTransport *private_it_;
64-
// image_transport::Publisher output_image_pub_;
72+
std::map<std::string, image_transport::Publisher> output_image_pubs_;
73+
ros::Publisher stats_pub_;
74+
6575

6676
ros::ServiceServer set_simple_objects_srv_;
6777
#ifdef USE_IGRAPH
@@ -78,11 +88,12 @@ class EOD_ROS{
7888
bool broadcast_tf;
7989
double allowed_lag_sec;
8090
int subs_queue_size;
91+
int stats_window;
8192

8293
// vars
8394
int frame_sequence;
84-
std::map<std::string, ros::Time> prev_detected_time;
85-
boost::circular_buffer<double>* detect_rate_values;
95+
std::map<std::string, StreamStats> stats;
96+
// boost::circular_buffer<double>* detect_rate_values;
8697

8798
// callbacks
8899
void rgb_info_cb(const sensor_msgs::ImageConstPtr& image, const sensor_msgs::CameraInfoConstPtr& info);
@@ -109,7 +120,7 @@ class EOD_ROS{
109120
#ifdef USE_IGRAPH
110121
int find_complex_obj_index_by_id(int id);
111122
#endif
112-
double get_detect_rate();
123+
double get_detect_rate(std::string frame_id);
113124

114125
// EOD
115126
eod::ObjectBase * object_base;
@@ -118,5 +129,7 @@ class EOD_ROS{
118129
std::vector<eod::ComplexObjectGraph*> selected_complex_objects;
119130
#endif
120131

132+
void publish_stats();
133+
121134

122135
};

0 commit comments

Comments
 (0)