transform tf frames without losing previous frames when new user come [closed]
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();
Can you add the part of your code doing the transform to the question?
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?
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
no problem . I fixed it . Thank you
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.
@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.