in body-tracking-samples/simple_3d_viewer/main.cpp [208:310]
void PlayFile(InputSettings inputSettings) {
// Initialize the 3d window controller
Window3dWrapper window3d;
//create the tracker and playback handle
k4a_calibration_t sensor_calibration;
k4abt_tracker_t tracker = NULL;
k4a_playback_t playback_handle = NULL;
const char* file = inputSettings.FileName.c_str();
if (k4a_playback_open(file, &playback_handle) != K4A_RESULT_SUCCEEDED)
{
printf("Failed to open recording: %s\n", file);
return;
}
if (k4a_playback_get_calibration(playback_handle, &sensor_calibration) != K4A_RESULT_SUCCEEDED)
{
printf("Failed to get calibration\n");
return;
}
k4a_capture_t capture = NULL;
k4a_stream_result_t result = K4A_STREAM_RESULT_SUCCEEDED;
k4abt_tracker_configuration_t tracker_config = { K4ABT_SENSOR_ORIENTATION_DEFAULT };
tracker_config.processing_mode = inputSettings.CpuOnlyMode ? K4ABT_TRACKER_PROCESSING_MODE_CPU : K4ABT_TRACKER_PROCESSING_MODE_GPU;
VERIFY(k4abt_tracker_create(&sensor_calibration, tracker_config, &tracker), "Body tracker initialization failed!");
k4abt_tracker_set_temporal_smoothing(tracker, 1);
int depthWidth = sensor_calibration.depth_camera_calibration.resolution_width;
int depthHeight = sensor_calibration.depth_camera_calibration.resolution_height;
window3d.Create("3D Visualization", sensor_calibration);
window3d.SetCloseCallback(CloseCallback);
window3d.SetKeyCallback(ProcessKey);
while (result == K4A_STREAM_RESULT_SUCCEEDED)
{
result = k4a_playback_get_next_capture(playback_handle, &capture);
// check to make sure we have a depth image
// if we are not at the end of the file
if (result != K4A_STREAM_RESULT_EOF) {
k4a_image_t depth_image = k4a_capture_get_depth_image(capture);
if (depth_image == NULL) {
//If no depth image, print a warning and skip to next frame
printf("Warning: No depth image, skipping frame\n");
k4a_capture_release(capture);
continue;
}
// Release the Depth image
k4a_image_release(depth_image);
}
if (result == K4A_STREAM_RESULT_SUCCEEDED)
{
//enque capture and pop results - synchronous
k4a_wait_result_t queue_capture_result = k4abt_tracker_enqueue_capture(tracker, capture, K4A_WAIT_INFINITE);
// Release the sensor capture once it is no longer needed.
k4a_capture_release(capture);
k4abt_frame_t bodyFrame = NULL;
k4a_wait_result_t pop_frame_result = k4abt_tracker_pop_result(tracker, &bodyFrame, K4A_WAIT_INFINITE);
if (pop_frame_result == K4A_WAIT_RESULT_SUCCEEDED)
{
size_t num_bodies = k4abt_frame_get_num_bodies(bodyFrame);
printf("%zu bodies are detected\n", num_bodies);
/************* Successfully get a body tracking result, process the result here ***************/
VisualizeResult(bodyFrame, window3d, depthWidth, depthHeight);
//Release the bodyFrame
k4abt_frame_release(bodyFrame);
}
else
{
printf("Pop body frame result failed!\n");
break;
}
}
window3d.SetLayout3d(s_layoutMode);
window3d.SetJointFrameVisualization(s_visualizeJointFrame);
window3d.Render();
if (result == K4A_STREAM_RESULT_EOF)
{
// End of file reached
break;
}
}
k4abt_tracker_shutdown(tracker);
k4abt_tracker_destroy(tracker);
window3d.Delete();
printf("Finished body tracking processing!\n");
k4a_playback_close(playback_handle);
}