Call Object Tracking State Correctly

Hey there,

I’m working on a basic body tracking script and am trying to get the tracking state of my bodies. For that I adapted the samples and got the following script. However, I always end up in “else” because I seem to call the tracking state wrong. Does anyone have an idea what I don’t see?

            if (bodies.is_new) {
                if (!bodies.object_list.empty()) {
                    for (auto object : bodies.object_list)
                        joint_nr = 0;
                        cout << bones_pos << endl;
                        OBJECT_TRACKING_STATE object_tracking_state = object.tracking_state;
                        if (object_tracking_state == OBJECT_TRACKING_STATE::OK) {
                            for (auto& kp_3d : object.keypoint)
                                bones_pos = "1/" + to_string(object.id) + "/" + to_string(kp_3d.x) + "/" + to_string(kp_3d.y) + "/" + to_string(kp_3d.z) + "/" + to_string(joint_nr);
                            cout << bones_pos << endl;
                            joint_nr = joint_nr + 1;
                        }
                        else if (object_tracking_state == OBJECT_TRACKING_STATE::TERMINATE) {
                            for (auto& kp_3d : object.keypoint)
                                bones_pos = "0/" + to_string(object.id) + "/" + to_string(kp_3d.x) + "/" + to_string(kp_3d.y) + "/" + to_string(kp_3d.z) + "/" + to_string(joint_nr);
                            cout << bones_pos << endl;
                        }
                        else if (object.tracking_state == OBJECT_TRACKING_STATE::SEARCHING) {
                            for (auto& kp_3d : object.keypoint)
                                bones_pos = "2/" + to_string(object.id) + "/" + to_string(kp_3d.x) + "/" + to_string(kp_3d.y) + "/" + to_string(kp_3d.z) + "/" + to_string(joint_nr);
                            cout << bones_pos << endl;
                        }
                        else {
                            bones_pos = "3/";
                            cout << bones_pos << endl;
                        }
                    
                }

            }

Hi,
Did you activate the tracking in the module?
https://www.stereolabs.com/docs/api/structsl_1_1ObjectDetectionParameters.html#a3ad4edec34c2c727581ec6299e6fc6b7

1 Like

edit: found my problem, I had missed to call objects.getObjectDataFromId()

Hi! Yes, tracking is enabled. Except for the part in my first post it’s basically the unmodified sample project.

The tracking status is given as “unknown”.

// Enable the Objects detection module
    ObjectDetectionParameters obj_det_params;
    obj_det_params.enable_tracking = true; // track people across images flow
    obj_det_params.enable_body_fitting = false; // smooth skeletons moves
	obj_det_params.body_format = sl::BODY_FORMAT::POSE_34;
    obj_det_params.detection_model = isJetson ? DETECTION_MODEL::HUMAN_BODY_FAST : DETECTION_MODEL::HUMAN_BODY_ACCURATE;
    returned_state = zed.enableObjectDetection(obj_det_params);