Skip to content

Commit d3b399c

Browse files
added some msg fill
1 parent 5ecb8d6 commit d3b399c

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

src/extended_object_detection_node/eod_node.cpp

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
#include "eod_node.h"
22
#include <cstdint>
33
#include <sensor_msgs/image_encodings.h>
4+
#include <geometry_msgs/Vector3.h>
5+
#include <geometry_msgs/Point.h>
6+
7+
geometry_msgs::Vector3 getUnitTranslation(geometry_msgs::Point point){
8+
geometry_msgs::Vector3 unit_translate;
9+
unit_translate.x = (point.x - cx) / fx;
10+
unit_translate.y = (point.y - cy) / fy;
11+
unit_translate.z = 1;
12+
return unit_translate;
13+
}
414

515
EOD_ROS::EOD_ROS(ros::NodeHandle nh, ros::NodeHandle nh_p){
616
nh_ = nh;
@@ -18,6 +28,7 @@ EOD_ROS::EOD_ROS(ros::NodeHandle nh, ros::NodeHandle nh_p){
1828
nh_p_.param("subscribe_depth", subscribe_depth, false);
1929
nh_p_.param("rate_limit_sec", rate_limit_sec, 0.1);
2030
nh_p_.param("publish_output", publish_output, false);
31+
nh_p_.param("use_actual_time", use_actual_time, false);
2132

2233

2334
std::string object_base_path;
@@ -98,7 +109,7 @@ void EOD_ROS::rgb_info_cb(const sensor_msgs::ImageConstPtr& rgb_image, const sen
98109
ROS_ERROR("Could not convert from '%s' to 'bgr8'.", rgb_image->encoding.c_str());
99110
}
100111

101-
detect(rgb, cv::Mat());
112+
detect(rgb, cv::Mat(), rgb_image->header);
102113
}
103114

104115
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){
@@ -130,16 +141,17 @@ void EOD_ROS::rgbd_info_cb(const sensor_msgs::ImageConstPtr& rgb_image, const se
130141
ROS_ERROR_THROTTLE(5, "Depth image has unsupported encoding [%s]", depth_image->encoding.c_str());
131142
}
132143

133-
detect(rgb, depth);
144+
detect(rgb, depth, rgb_image->header);
134145
}
135146

136-
void EOD_ROS::detect(const cv::Mat& rgb, const cv::Mat& depth){
147+
void EOD_ROS::detect(const cv::Mat& rgb, const cv::Mat& depth, std_msgs::Header header){
137148
prev_detected_time = ros::Time::now();
138149

139150
cv::Mat image_to_draw;
140151

141152
extended_object_detection::SimpleObjectArray simples_msg;
142153

154+
143155
if(publish_output)
144156
image_to_draw = rgb.clone();
145157

@@ -151,24 +163,53 @@ void EOD_ROS::detect(const cv::Mat& rgb, const cv::Mat& depth){
151163

152164
}
153165

166+
simples_msg.header = header;
167+
if( use_actual_time )
168+
simples_msg.header.stamp = ros::Time::now();
169+
154170
simple_objects_pub_.publish(simples_msg);
155171

156172
frame_sequence++;
157173
}
158174

159-
void EOD_ROS::add_data_to_simple_msg(const eod::SimpleObject* so, extended_object_detection::SimpleObjectArray& msg){
160-
175+
void EOD_ROS::add_data_to_simple_msg(const eod::SimpleObject* so, extended_object_detection::SimpleObjectArray& msg){
161176
for(auto& eoi : so->objects){
162177
msg.objects.push_back(eoi_to_base_object(so, &eoi));
163-
}
164-
178+
}
165179
}
166180

167181
extended_object_detection::BaseObject EOD_ROS::eoi_to_base_object(const eod::SimpleObject* so, const eod::ExtendedObjectInfo* eoi){
168-
extended_object_detection::BaseObject base_object;
182+
extended_object_detection::BaseObject bo;
183+
// common
184+
bo.type_id = so->ID;
185+
bo.type_name = so->name;
186+
bo.score = eoi->total_score;
187+
188+
for( auto const& exi : eoi->extracted_info){
189+
bo.extracted_info.keys.push_back(exi.first);
190+
bo.extracted_info.values.push_back(exi.second);
191+
}
192+
193+
// rect
194+
bo.rect.left_bottom.x = eoi->x;
195+
bo.rect.left_bottom.y = eoi->y;
196+
bo.rect.right_bottom.x = eoi->x + eoi->width;
197+
bo.rect.right_bottom.y = eoi->y + eoi->height;
198+
199+
// transform
200+
if( eoi->tvec.size() > 0 ){
201+
bo.transform.translation.x = eoi->tvec[0][0];
202+
bo.transform.translation.y = eoi->tvec[0][1];
203+
bo.transform.translation.z = eoi->tvec[0][2];
204+
}
205+
else{
206+
bo.transform.translation = getUnitTranslation(ext_obj->getCenter());
207+
}
208+
169209

210+
//TODO tracks
170211

171-
return base_object;
212+
return bo;
172213
}
173214

174215
int main(int argc, char **argv)

src/extended_object_detection_node/eod_node.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <message_filters/synchronizer.h>
1111
#include <message_filters/sync_policies/approximate_time.h>
1212

13+
#include <std_msgs/Header.h>
1314
#include <sensor_msgs/Image.h>
1415
#include <sensor_msgs/CameraInfo.h>
1516

@@ -53,6 +54,7 @@ class EOD_ROS{
5354
bool subscribe_depth;
5455
double rate_limit_sec;
5556
bool publish_output;
57+
bool use_actual_time;
5658

5759
// vars
5860
int frame_sequence;
@@ -64,7 +66,7 @@ class EOD_ROS{
6466
void rgbd_info_cb(const sensor_msgs::ImageConstPtr& image, const sensor_msgs::CameraInfoConstPtr& info, const sensor_msgs::ImageConstPtr& depth_image, const sensor_msgs::CameraInfoConstPtr& depth_info);
6567

6668
// functions
67-
void detect(const cv::Mat& rgb, const cv::Mat& depth);
69+
void detect(const cv::Mat& rgb, const cv::Mat& depth, std_msgs::Header header);
6870
bool check_time(ros::Time stamp);
6971
void add_data_to_simple_msg(const eod::SimpleObject*, extended_object_detection::SimpleObjectArray& msg);
7072
extended_object_detection::BaseObject eoi_to_base_object(const eod::SimpleObject* so, const eod::ExtendedObjectInfo* eoi);

0 commit comments

Comments
 (0)