ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

transform tf frames without losing previous frames when new user come [closed]

asked 2018-07-23 06:48:55 -0500

amal1 gravatar image

updated 2018-07-23 11:07:43 -0500

lucasw gravatar image

Hi, my question is can I transform all frames tracked by openni tracker without losing users while new user is tracked , for example if there is frame head_1 is detected and then new user come my code only transform head_2 and forget the first even if the user is not lost . Can I transform both of the frames .Thank you Here is the code , I just add the transformation of head_1 without other joints because the code is long ;

  string MAIN_FRAME_camera = "openni_depth_frame";
  string MAIN_FRAME = "torso_1";
  string FRAMES[] = {"head_", "neck_", "torso_", "left_shoulder_", "right_shoulder_", 
        "left_hand_", "right_hand_", "left_elbow_", "right_elbow_", "left_hip_",
        "right_hip_", "left_knee_", "right_knee_", "left_foot_", "right_foot_"};

  ros::NodeHandle node;

  tf::TransformListener listener;

  ros::Rate rate(30.0);

  ofstream myfile;
  ofstream myfile2;

  if( remove("/home/amal/catkin_ws/src/isr_activity_recognition/test_torso.txt") != 0 || remove("/home/amal/catkin_ws/src/isr_activity_recognition/test_camera.txt") != 0)
    perror( "Error deleting file" );
  else
    puts( "File successfully deleted" );
  char last_char;

  while (node.ok()){
  int contador = 0;    

    while(listener.frameExists("torso_1")==0 && listener.frameExists("torso_2")==0 && listener.frameExists("torso_3")==0 && listener.frameExists("torso_4")==0 && listener.frameExists("torso_5")==0 && listener.frameExists("torso_6")==0 && listener.frameExists("torso_7")==0){
      ros::Duration(0.1).sleep();
      ROS_INFO("Waiting..."); 
    }
    myfile.open("/home/amal/catkin_ws/src/isr_activity_recognition/test_torso.txt", ios::app);
    vector <string> ids;
    listener.getFrameStrings(ids);  

    //while(contador==0){
      //ros::Duration(0.5).sleep();
      //listener.getFrameStrings(ids);
      for(vector<string>::iterator i = ids.begin(); i < ids.end(); i++){
        string elem = *i;
        if (strstr(elem.c_str(),"torso_") != NULL){
          contador++;
          cout << "Numero de pessoas: " << contador <<endl;
          last_char = elem[elem.length()-1];

        }  

      }

    MAIN_FRAME = "torso_" + boost::lexical_cast<std::string>(int(last_char)-'0');
    cout << "MAIN_FRAME: " << MAIN_FRAME <<endl;

    //FRAMES[i] = FRAMES[i] + boost::lexical_cast<std::string>(contador);

    //ros::Duration(5).sleep();  
    tf::StampedTransform tf_head;

        try{
           ros::Duration timeout(1.0 / 30);
           listener.waitForTransform("torso_1", "openni_depth_frame", ros::Time(0), timeout );
        // head
        // torso
                listener.waitForTransform(MAIN_FRAME,FRAMES[0]+ boost::lexical_cast<std::string>(int(last_char)-'0'), ros::Time(0), timeout );
        listener.lookupTransform(MAIN_FRAME, FRAMES[0]+ boost::lexical_cast<std::string>(int(last_char)-'0'), ros::Time(0), tf_head);

        double x_head = tf_head.getOrigin().x();
        double y_head = tf_head.getOrigin().y();
        double z_head = tf_head.getOrigin().z();

        double roll_head, pitch_head, yaw_head ;
        tf_head.getBasis().getRPY(roll_head, pitch_head, yaw_head);
        tf::Quaternion q_head = tf_head.getRotation();
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by amal1
close date 2018-07-26 04:58:52.925568

Comments

Can you add the part of your code doing the transform to the question?

lucasw gravatar image lucasw  ( 2018-07-23 07:48:49 -0500 )edit

This looks like a general coding issue and not really ros related. It looks like you are only doing tf lookups for the last head, couldn't you put the lookup into a loop that goes over every head that is available?

lucasw gravatar image lucasw  ( 2018-07-23 11:16:40 -0500 )edit

Do you think that I should close the loop for for the end of the code . And how Can I change the listener_lookuptransform to accept 2 users tracked . I am sorry if I ask dumpy questions .I am new in Ros

amal1 gravatar image amal1  ( 2018-07-23 11:23:46 -0500 )edit

no problem . I fixed it . Thank you

amal1 gravatar image amal1  ( 2018-07-23 12:41:35 -0500 )edit

You asked almost the exact same question here. Opening multiple questions for the same issue makes things more confusing. In the future, just edit your original question. For now, I've closed your other Q.

jarvisschultz gravatar image jarvisschultz  ( 2018-07-23 14:19:18 -0500 )edit

@amal1 you can answer your own question (you could cut and paste the code that works for you) and mark it as the solution to close this out.

lucasw gravatar image lucasw  ( 2018-07-24 11:09:21 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-07-25 05:45:42 -0500

amal1 gravatar image

Thank you for your help . But the solution is very simple due to lack of concentration . I just close the loop that receive all frames transformed at the end of code . In this way tf transform transform frames tracked one by one .

     string MAIN_FRAME = "torso_1";
 string FRAMES[] = {"head_", "neck_", "torso_", "left_shoulder_", "right_shoulder_", 
    "left_hand_", "right_hand_", "left_elbow_", "right_elbow_", "left_hip_",
    "right_hip_", "left_knee_", "right_knee_", "left_foot_", "right_foot_"};
 ros::NodeHandle node;
 tf::TransformListener listener;
 ros::Rate rate(30.0);
 ofstream myfile;
 ofstream myfile2;
 if( remove("/home/amal/catkin_ws/src/isr_activity_recognition/test_torso.txt") != 0 || remove("/home/amal/catkin_ws/src/isr_activity_recognition/test_camera.txt") != 0)
perror( "Error deleting file" );
else
puts( "File successfully deleted" );
while (node.ok()){
int contador = 0;    

while(listener.frameExists("torso_1")==0 && listener.frameExists("torso_2")==0 && listener.frameExists("torso_3")==0 && listener.frameExists("torso_4")==0 && listener.frameExists("torso_5")==0 && listener.frameExists("torso_6")==0 && listener.frameExists("torso_7")==0){
  ros::Duration(0.1).sleep();
  ROS_INFO("Waiting..."); 
}
myfile.open("/home/amal/catkin_ws/src/isr_activity_recognition/test_torso.txt", ios::app);
vector <string> ids;
listener.getFrameStrings(ids);  
for(vector<string>::iterator i = ids.begin(); i < ids.end(); i++){
    string elem = *i;
    if (strstr(elem.c_str(),"torso_") != NULL){
      contador++;
      cout << "Numero de pessoas: " << contador <<endl;
      last_char = elem[elem.length()-1];

    }  

  }

MAIN_FRAME = "torso_" + boost::lexical_cast<std::string>(int(last_char)-'0');
cout << "MAIN_FRAME: " << MAIN_FRAME <<endl;

//FRAMES[i] = FRAMES[i] + boost::lexical_cast<std::string>(contador);

//ros::Duration(5).sleep();  
tf::StampedTransform tf_head;

    try{
       ros::Duration timeout(1.0 / 30);
       listener.waitForTransform("torso_1", "openni_depth_frame", ros::Time(0), timeout );
    // head
    // torso
            listener.waitForTransform(MAIN_FRAME,FRAMES[0]+ boost::lexical_cast<std::string>(int(last_char)-'0'), ros::Time(0), timeout );
    listener.lookupTransform(MAIN_FRAME, FRAMES[0]+ boost::lexical_cast<std::string>(int(last_char)-'0'), ros::Time(0), tf_head);

    double x_head = tf_head.getOrigin().x();
    double y_head = tf_head.getOrigin().y();
    double z_head = tf_head.getOrigin().z();

    double roll_head, pitch_head, yaw_head ;
    tf_head.getBasis().getRPY(roll_head, pitch_head, yaw_head);
    tf::Quaternion q_head = tf_head.getRotation();  }  }
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2018-07-23 06:48:55 -0500

Seen: 79 times

Last updated: Jul 25 '18