diff --git a/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-read.cpp b/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-read.cpp index cadef0cee8..e9a66e94af 100755 --- a/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-read.cpp +++ b/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-read.cpp @@ -53,6 +53,10 @@ int main(int argc, char **argv) int nb_data = *arr_nb_data.data(); std::cout << "Number of images: " << nb_data << std::endl; + // Load all the poses + visp::cnpy::NpyArray arr_vec_poses = npz_data["vec_poses"]; + double* vec_poses_ptr = arr_vec_poses.data(); + for (int iter = 0; iter < nb_data; iter++) { std::string img_data_str = toString("png_image_%06d", iter); visp::cnpy::NpyArray arr_nb_data = npz_data[img_data_str]; @@ -81,10 +85,13 @@ int main(int argc, char **argv) } } - const std::string vec_pose_str = toString("vec_pose_%06d", iter); - visp::cnpy::NpyArray arr_vec_pose = npz_data[vec_pose_str]; - vpHomogeneousMatrix cMo(vpTranslationVector(arr_vec_pose.data()[3], arr_vec_pose.data()[4], arr_vec_pose.data()[5]), - vpThetaUVector(arr_vec_pose.data()[0], arr_vec_pose.data()[1], arr_vec_pose.data()[2]) + // const std::string vec_pose_str = toString("vec_pose_%06d", iter); + // visp::cnpy::NpyArray arr_vec_pose = npz_data[vec_pose_str]; + // vpHomogeneousMatrix cMo(vpTranslationVector(arr_vec_pose.data()[3], arr_vec_pose.data()[4], arr_vec_pose.data()[5]), + // vpThetaUVector(arr_vec_pose.data()[0], arr_vec_pose.data()[1], arr_vec_pose.data()[2]) + // ); + vpHomogeneousMatrix cMo(vpTranslationVector(vec_poses_ptr[6*iter + 3], vec_poses_ptr[6*iter + 4], vec_poses_ptr[6*iter + 5]), + vpThetaUVector(vec_poses_ptr[6*iter], vec_poses_ptr[6*iter + 1], vec_poses_ptr[6*iter + 2]) ); std::cout << "\ncMo:\n" << cMo << std::endl; diff --git a/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-save.cpp b/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-save.cpp index bc467362f5..470a10f757 100755 --- a/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-save.cpp +++ b/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-save.cpp @@ -75,8 +75,8 @@ int main(int argc, char **argv) << camera_name.c_str()[i] << " ; " << int(camera_name.c_str()[i]) << std::endl; } - visp::cnpy::npz_save(npz_filename, "camera_name", &vec_camera_name[0], { vec_camera_name.size() }, "a"); - visp::cnpy::npz_save(npz_filename, "height", &height, { 1 }, "a"); + visp::cnpy::npz_save(npz_filename, "camera_name", &vec_camera_name[0], { vec_camera_name.size() }, "w"); // overwrite + visp::cnpy::npz_save(npz_filename, "height", &height, { 1 }, "a"); // append visp::cnpy::npz_save(npz_filename, "width", &width, { 1 }, "a"); visp::cnpy::npz_save(npz_filename, "channel", &channel, { 1 }, "a"); @@ -86,6 +86,9 @@ int main(int argc, char **argv) visp::cnpy::npz_save(npz_filename, "cam_u0", &cam_u0, { 1 }, "a"); visp::cnpy::npz_save(npz_filename, "cam_v0", &cam_v0, { 1 }, "a"); + std::vector vec_poses; + vec_poses.reserve(g.getLastFrameIndex() * 6); + int iter = 0; while (!g.end()) { g.acquire(I); @@ -98,7 +101,9 @@ int main(int argc, char **argv) visp::cnpy::npz_save(npz_filename, toString("png_image_%06d", iter), &img_buffer[0], { (unsigned int) last_pos }, "a"); std::vector vec_pose = poseToVec(cMo); - visp::cnpy::npz_save(npz_filename, toString("vec_pose_%06d", iter), &vec_pose[0], { vec_pose.size() }, "a"); + vec_poses.insert(vec_poses.end(), vec_pose.begin(), vec_pose.end()); + // Commented, use instead a "multidimensional" array + // visp::cnpy::npz_save(npz_filename, toString("vec_pose_%06d", iter), &vec_pose[0], { vec_pose.size() }, "a"); std::map > > mapOfModels; std::map mapOfW; @@ -130,6 +135,9 @@ int main(int argc, char **argv) iter++; } + // Show how to save a "multidimensional" array + visp::cnpy::npz_save(npz_filename, "vec_poses", &vec_poses[0], { static_cast(iter), 6 }, "a"); + visp::cnpy::npz_save(npz_filename, "nb_data", &iter, { 1 }, "a"); return EXIT_SUCCESS;