diff --git a/modules/core/test/camera/testXmlParserCamera.cpp b/modules/core/test/camera/testXmlParserCamera.cpp index e726a9a565..bf26a31369 100644 --- a/modules/core/test/camera/testXmlParserCamera.cpp +++ b/modules/core/test/camera/testXmlParserCamera.cpp @@ -278,7 +278,7 @@ int main() distortion_coeffs.push_back(0); cam.initProjWithKannalaBrandtDistortion(285.523895263672, 286.6708984375, 420.874114990234, 381.085388183594, distortion_coeffs); - std::string filename = tmp_dir + "test_write_cam_with_KannalaBrandt_distortion.xml"; + std::string filename = tmp_dir + "test_write_cam_with_KannalaBrandt_distortion_wo_name.xml"; { vpXmlParserCamera xml; std::cout << "Write to: " << filename << std::endl; @@ -300,7 +300,72 @@ int main() } } } + + { + std::cout << "-- Test to save 2 cameras and parse them wo name thanks they differ in distortion" << std::endl; + vpCameraParameters cam1; + + std::string filename = tmp_dir + "test_write_2_cam_differ_in_distortion.xml"; + + { + vpXmlParserCamera xml; + std::cout << "Write to: " << filename << std::endl; + std::cout << "Cam write:\n" << cam1 << std::endl; + if (xml.save(cam1, filename, "Camera 1", 320, 240, "", false) != vpXmlParserCamera::SEQUENCE_OK) { + std::cerr << "Cannot save XML file: " << filename << std::endl; + return EXIT_FAILURE; + } + } + + vpCameraParameters cam2; + std::vector distortion_coeffs; + distortion_coeffs.push_back(-0.00297341705299914); + distortion_coeffs.push_back(0.0352853797376156); + distortion_coeffs.push_back(-0.032205019146204); + distortion_coeffs.push_back(0.004446716979146); + distortion_coeffs.push_back(0); + cam2.initProjWithKannalaBrandtDistortion(285.523895263672, 286.6708984375, 420.874114990234, 381.085388183594, + distortion_coeffs); + { + vpXmlParserCamera xml; + std::cout << "Write to: " << filename << std::endl; + std::cout << "Cam write:\n" << cam2 << std::endl; + if (xml.save(cam2, filename, "Camera 2", 800, 848, "", false) != vpXmlParserCamera::SEQUENCE_OK) { + std::cerr << "Cannot save XML file: " << filename << std::endl; + return EXIT_FAILURE; + } + } + + { + std::cout << "Attempt to read camera with perspective projection without distortion and without name" << std::endl; + vpCameraParameters cam_read; + vpXmlParserCamera xml; + xml.parse(cam_read, filename, "", vpCameraParameters::perspectiveProjWithoutDistortion, 320, 240, false); + + std::cout << "Cam read:\n" << cam_read << std::endl; + if (cam1 != cam_read) { + std::cerr << "Issue when parsing XML file: " << filename << std::endl; + return EXIT_FAILURE; + } + } + + { + std::cout << "Attempt to read camera with Kannala Brandt distortion and without name" << std::endl; + vpCameraParameters cam_read; + vpXmlParserCamera xml; + xml.parse(cam_read, filename, "", vpCameraParameters::ProjWithKannalaBrandtDistortion, 800, 848, false); + + std::cout << "Cam read:\n" << cam_read << std::endl; + if (cam2 != cam_read) { + std::cerr << "Issue when parsing XML file: " << filename << std::endl; + return EXIT_FAILURE; + } + } + } + vpIoTools::remove(tmp_dir); + + std::cout << "Test succeed" << std::endl; #endif return EXIT_SUCCESS;