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
515EOD_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
104115void 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
167181extended_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
174215int main (int argc, char **argv)
0 commit comments