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

Unable to parse camera parameters with vpXmlParserCamera::parse() when camera name is empty #1296

Closed
rolalaro opened this issue Jan 4, 2024 · 1 comment

Comments

@rolalaro
Copy link

rolalaro commented Jan 4, 2024

Issue

When calling vpXmlParserCamera::parse without specifying the camera name, the parsing does not work even if there is only one camera in the file.

Expected behavior

According to the documentation, if the XML file contains only one camera, the parsing should succeed.

To reproduce the error

#include <visp3/core/vpIoTools.h>
#include <visp3/core/vpXmlParserCamera.h>

int main() {
    // Get the user login name
    std::string username;
    vpIoTools::getUserName(username);

    std::string tmp_dir += username + "/test_xml_parser_camera/";
    vpIoTools::remove(tmp_dir);
    std::cout << "Create: " << tmp_dir << std::endl;
    vpIoTools::makeDirectory(tmp_dir);

    // Create the camera model
    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);

    // Save the model in a file
    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;
      }
    }
    return EXIT_SUCCESS;
}
@rolalaro
Copy link
Author

rolalaro commented Jan 4, 2024

Proposed a PR (#1297) to solve the issue

@fspindle fspindle changed the title Problem vpXmlParserCamera::parse Unable to parse camera parameters with vpXmlParserCamera::parse() when camera name is empty Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant