Skip to content

Commit

Permalink
Add more tests for vpXmlParserCamera
Browse files Browse the repository at this point in the history
  • Loading branch information
fspindle committed Jan 4, 2024
1 parent c4e218e commit 7e16377
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion modules/core/test/camera/testXmlParserCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<double> 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;
Expand Down

0 comments on commit 7e16377

Please sign in to comment.