From 6d5787a2edcbc2c0e8ac3e50514753f69d944770 Mon Sep 17 00:00:00 2001 From: rlagneau Date: Thu, 4 Jan 2024 15:52:27 +0100 Subject: [PATCH 1/5] [TEST] Added a unit test to check if the xml parser is able to parse an xml file containing a single camera without being given a name --- .../core/test/camera/testXmlParserCamera.cpp | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/modules/core/test/camera/testXmlParserCamera.cpp b/modules/core/test/camera/testXmlParserCamera.cpp index f179ef151c..e726a9a565 100644 --- a/modules/core/test/camera/testXmlParserCamera.cpp +++ b/modules/core/test/camera/testXmlParserCamera.cpp @@ -267,6 +267,39 @@ int main() } } + { + std::cout << "-- Test to save/load one single camera with Kannala Brandt distortion in a single file wo name" << std::endl; + vpCameraParameters cam; + 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); + cam.initProjWithKannalaBrandtDistortion(285.523895263672, 286.6708984375, 420.874114990234, 381.085388183594, + distortion_coeffs); + std::string filename = tmp_dir + "test_write_cam_with_KannalaBrandt_distortion.xml"; + { + vpXmlParserCamera xml; + std::cout << "Write to: " << filename << std::endl; + if (xml.save(cam, filename, "Camera", 800, 848) != vpXmlParserCamera::SEQUENCE_OK) { + std::cerr << "Cannot save XML file: " << filename << std::endl; + return EXIT_FAILURE; + } + } + + vpCameraParameters cam_read; + { + vpXmlParserCamera xml; + xml.parse(cam_read, filename, "", vpCameraParameters::ProjWithKannalaBrandtDistortion, 800, 848, false); + std::cout << "Cam write:\n" << cam << std::endl; + std::cout << "Cam read:\n" << cam_read << std::endl; + if (cam != cam_read) { + std::cerr << "Issue when parsing XML file: " << filename << std::endl; + return EXIT_FAILURE; + } + } + } vpIoTools::remove(tmp_dir); #endif From 9633b63eb2d40b98bd7049b23369d219bbeb81e4 Mon Sep 17 00:00:00 2001 From: rlagneau Date: Thu, 4 Jan 2024 15:55:42 +0100 Subject: [PATCH 2/5] [FIX] Fixed the problem of vpXmlParserCamera::parse without camera name --- modules/core/src/camera/vpXmlParserCamera.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/camera/vpXmlParserCamera.cpp b/modules/core/src/camera/vpXmlParserCamera.cpp index 034bb0ec17..6f90d0d271 100644 --- a/modules/core/src/camera/vpXmlParserCamera.cpp +++ b/modules/core/src/camera/vpXmlParserCamera.cpp @@ -310,7 +310,7 @@ class vpXmlParserCamera::Impl } // if same name && same projection model && same image size camera already exists, we return SEQUENCE_OK // otherwise it is a new camera that need to be updated and we return SEQUENCE_OK - bool same_name = (!cam_name.empty() && (cam_name == camera_name_tmp)); + bool same_name = (cam_name.empty() || (cam_name == camera_name_tmp)); bool same_img_size = (abs((int)im_width - (int)image_width_tmp) < allowedPixelDiffOnImageSize || im_width == 0) && (abs((int)im_height - (int)image_height_tmp) < allowedPixelDiffOnImageSize || im_height == 0) && (test_subsampling_width) && (test_subsampling_height); From c4e218e4bc4cebb4988322a7902e4b0606abbf68 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Thu, 4 Jan 2024 17:35:42 +0100 Subject: [PATCH 3/5] Fix issue in vpXmlParserCamera::count() where args order was wrong --- modules/core/src/camera/vpXmlParserCamera.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/camera/vpXmlParserCamera.cpp b/modules/core/src/camera/vpXmlParserCamera.cpp index 6f90d0d271..4af8c03b72 100644 --- a/modules/core/src/camera/vpXmlParserCamera.cpp +++ b/modules/core/src/camera/vpXmlParserCamera.cpp @@ -554,7 +554,7 @@ class vpXmlParserCamera::Impl camera = cam; - int nbCamera = count(node, cam_name, cam.get_projModel(), verbose, im_width, im_height); + int nbCamera = count(node, cam_name, cam.get_projModel(), im_width, im_height, verbose); if (nbCamera) { return SEQUENCE_ERROR; } From 7e16377dbb4c7367eac804d0915d0639aad23110 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Thu, 4 Jan 2024 17:36:00 +0100 Subject: [PATCH 4/5] Add more tests for vpXmlParserCamera --- .../core/test/camera/testXmlParserCamera.cpp | 67 ++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) 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; From 8f5381ca2a60eb8a5ff2e63a47c49d145c63a76b Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Thu, 4 Jan 2024 17:36:13 +0100 Subject: [PATCH 5/5] Update bug fixed in vpXmlParserCamera. Closes #1296 --- ChangeLog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 31ad7472a8..d5f9e64b17 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -38,6 +38,7 @@ ViSP 3.x.x (Version in development) . [#1273] Build error in visp_java without deprecated functionalities . [#1274] Build issue no member named clamp in namespace std . [#1279] Issue in vpPoseVector json serialization + . [#1296] Unable to parse camera parameters with vpXmlParserCamera::parse() when camera name is empty ---------------------------------------------- ViSP 3.6.0 (released September 22, 2023) - Contributors: