Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cam parser #1297

Merged
merged 5 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/camera/vpXmlParserCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
98 changes: 98 additions & 0 deletions modules/core/test/camera/testXmlParserCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,105 @@ 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<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);
cam.initProjWithKannalaBrandtDistortion(285.523895263672, 286.6708984375, 420.874114990234, 381.085388183594,
distortion_coeffs);
std::string filename = tmp_dir + "test_write_cam_with_KannalaBrandt_distortion_wo_name.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;
}
}
}

{
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
Loading