44#include < message_filters/subscriber.h>
55#include < message_filters/synchronizer.h>
66#include < message_filters/sync_policies/approximate_time.h>
7+ #include < tf2_ros/transform_broadcaster.h>
8+ #include < geometry_msgs/TransformStamped.h>
79
810#include " extended_object_detection/SimpleObject.h"
911#include " extended_object_detection/SimpleObjectArray.h"
@@ -45,7 +47,6 @@ ros::Publisher objects_pub_;
4547image_transport::Publisher detected_image_pub_;
4648ros::Publisher marker_array_simple_pub_;
4749
48-
4950vector<SimpleObject*> selected_to_detect_simple_objects;
5051vector<int > selected_on_start_simple;
5152#ifdef USE_IGRAPH
@@ -61,6 +62,7 @@ std::mutex mutex_image;
6162bool screenOutputFlag = true ;
6263bool publishImage = true ;
6364bool publishMarkers = false ;
65+ bool publishTf = false ;
6466vector<string> visualizationTypes;
6567double updateRateMs = 0 ;
6668bool subscribeDepth = false ;
@@ -751,6 +753,8 @@ void video_process_cb(const ros::TimerEvent&){
751753
752754 mutex_image.lock ();
753755
756+ static tf2_ros::TransformBroadcaster transform_broadcaster_;
757+
754758 if (!last_image.empty ()){
755759 if (image_frame_id == " " ){
756760 ROS_ERROR (" No camera intrinsic are provided, or camera frame_id is not set." );
@@ -784,6 +788,18 @@ void video_process_cb(const ros::TimerEvent&){
784788 current_object.type_id = selected_to_detect_simple_objects[i]->ID ;
785789 current_object.type_name = selected_to_detect_simple_objects[i]->name ;
786790 array_objects.objects .push_back (current_object);
791+
792+ if ( publishTf ){
793+ geometry_msgs::TransformStamped transformStamped;
794+
795+ transformStamped.header .stamp = ros::Time::now ();
796+ transformStamped.header .frame_id = image_frame_id;
797+ transformStamped.child_frame_id = current_object.type_name + " _" +std::to_string (j);
798+
799+ transformStamped.transform = current_object.transform ;
800+
801+ transform_broadcaster_.sendTransform (transformStamped);
802+ }
787803 }
788804 }
789805#ifdef USE_IGRAPH
@@ -871,7 +887,7 @@ void video_process_cb(const ros::TimerEvent&){
871887#else
872888 cvWaitKey (1 );
873889#endif
874- }
890+ }
875891 if ( publishImage ){
876892 sensor_msgs::ImagePtr detected_msg = cv_bridge::CvImage (std_msgs::Header (), " bgr8" , image2draw).toImageMsg ();
877893 detected_image_pub_.publish (detected_msg);
@@ -927,6 +943,9 @@ int main(int argc, char **argv)
927943 if ( !nh_p.getParam (" publishMarkers" ,publishMarkers) ){
928944 publishMarkers = false ;
929945 }
946+ if ( !nh_p.getParam (" publishTf" ,publishTf) ){
947+ publishTf = false ;
948+ }
930949
931950 nh_p.getParam (" rotate_image_180" , rotate_image_180);
932951
0 commit comments