Skip to content

Commit 34cfb59

Browse files
now can ignore old image frames
1 parent d4bf5b2 commit 34cfb59

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

launch/extended_object_detection_oakd_example.launch

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
<param name="subscribe_depth" value="true"/>
1919
<param name="rate_limit_sec" value="0.1"/>
20+
<param name="allowed_lag_sec" value="1"/>
2021
<param name="publish_image_output" value="true"/>
2122
<param name="publish_markers" value="true"/>
22-
<param name="broadcast_tf" value="true"/>
23+
<param name="broadcast_tf" value="true"/>
24+
2325

2426
<remap from="camera/image_raw" to="/oak/rgb/image"/>
2527
<remap from="camera/info" to="/oak/rgb/camera_info"/>

src/extended_object_detection_node/eod_node.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ EOD_ROS::EOD_ROS(ros::NodeHandle nh, ros::NodeHandle nh_p){
4545
nh_p_.param("use_actual_time", use_actual_time, false);
4646
nh_p_.param("publish_markers", publish_markers, false);
4747
nh_p_.param("broadcast_tf", broadcast_tf, false);
48+
nh_p_.param("allowed_lag_sec", allowed_lag_sec, 0.1);
4849

4950
std::string object_base_path;
5051
nh_p_.getParam("object_base",object_base_path);
@@ -136,6 +137,14 @@ bool EOD_ROS::check_time(ros::Time stamp){
136137
}
137138

138139

140+
bool EOD_ROS::check_lag(ros::Time stamp, double& lag){
141+
if( allowed_lag_sec == 0)
142+
return true;
143+
lag = (ros::Time::now() - stamp).toSec();
144+
return lag <= allowed_lag_sec;
145+
}
146+
147+
139148
cv::Mat EOD_ROS::getK(const sensor_msgs::CameraInfoConstPtr& info_msg){
140149
cv::Mat K = cv::Mat::zeros(3, 3, CV_64F);
141150
for (size_t i=0; i<3; i++) {
@@ -162,8 +171,12 @@ void EOD_ROS::rgb_info_cb(const sensor_msgs::ImageConstPtr& rgb_image, const sen
162171
if( !check_time(ros::Time::now()) ) {
163172
ROS_WARN("Skipped frame");
164173
return;
165-
}
166-
// TODO add possibility to exclude old stamp images (if detection goes to slow)
174+
}
175+
double lag;
176+
if( !check_lag(rgb_image->header.stamp, lag) ) {
177+
ROS_WARN("Dropped frame, lag = %f", lag);
178+
return;
179+
}
167180
cv::Mat rgb;
168181
try{
169182
rgb = cv_bridge::toCvCopy(rgb_image, "bgr8")->image;
@@ -184,6 +197,11 @@ void EOD_ROS::rgbd_info_cb(const sensor_msgs::ImageConstPtr& rgb_image, const se
184197
ROS_WARN("Skipped frame");
185198
return;
186199
}
200+
double lag;
201+
if( !check_lag(rgb_image->header.stamp, lag) ) {
202+
ROS_WARN("Dropped frame, lag = %f", lag);
203+
return;
204+
}
187205
// TODO add possibility to exclude old stamp images (if detection goes to slow)
188206
cv::Mat rgb;
189207
try{

src/extended_object_detection_node/eod_node.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class EOD_ROS{
7373
bool use_actual_time;
7474
bool publish_markers;
7575
bool broadcast_tf;
76+
double allowed_lag_sec;
7677

7778
// vars
7879
int frame_sequence;
@@ -92,6 +93,7 @@ class EOD_ROS{
9293
//void detect(const cv::Mat& rgb, const cv::Mat& depth, std_msgs::Header header);
9394
void detect(const eod::InfoImage& rgb, const eod::InfoImage& depth, std_msgs::Header header);
9495
bool check_time(ros::Time stamp);
96+
bool check_lag(ros::Time stamp, double &lag);
9597
//void add_data_to_simple_msg( eod::SimpleObject*, extended_object_detection::SimpleObjectArray& msg, const cv::Mat& K);
9698
extended_object_detection::BaseObject eoi_to_base_object(std::string name, int id, eod::ExtendedObjectInfo* eoi, const cv::Mat& K);
9799
cv::Mat getK(const sensor_msgs::CameraInfoConstPtr& info_msg);

0 commit comments

Comments
 (0)