#include <visp3/core/vpIoTools.h>
#include <visp3/core/vpXmlParserCamera.h>
int main()
{
#ifdef ENABLE_VISP_NAMESPACE
#endif
#if defined(VISP_HAVE_PUGIXML)
std::cout << "Create: " << tmp_dir << std::endl;
{
std::cout << "-- Test to save/load one single camera without distortion in a single file" << std::endl;
std::string filename = tmp_dir + "test_write_cam_without_distortion.xml";
{
std::cout << "Write to: " << filename << std::endl;
std::cerr << "Cannot save XML file: " << filename << std::endl;
return EXIT_FAILURE;
}
}
{
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 << "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/load one single camera with distortion in a single file" << std::endl;
std::string filename = tmp_dir + "test_write_cam_with_distortion.xml";
{
std::cout << "Write to: " << filename << std::endl;
std::cerr << "Cannot save XML file: " << filename << std::endl;
return EXIT_FAILURE;
}
}
{
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 << "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/load multiple cameras with and without distortion in a single file" << std::endl;
std::string filename = tmp_dir + "test_write_cam_multiple.xml";
{
std::cout << "Write to: " << filename << " camera:\n" << cam1_w_d << std::endl;
std::cerr << "Cannot save XML file: " << filename << std::endl;
return EXIT_FAILURE;
}
}
{
std::cout << "Write to: " << filename << " camera:\n" << cam1_wo_d << std::endl;
std::cerr << "Cannot save XML file: " << filename << std::endl;
return EXIT_FAILURE;
}
}
{
std::cout << "Write to: " << filename << " camera:\n" << cam2_w_d << std::endl;
std::cerr << "Cannot save XML file: " << filename << std::endl;
return EXIT_FAILURE;
}
}
{
std::cout << "Write to: " << filename << " camera:\n" << cam2_wo_d << std::endl;
std::cerr << "Cannot save XML file: " << filename << std::endl;
return EXIT_FAILURE;
}
}
{
std::cout << "Cam write:\n" << cam1_w_d << std::endl;
std::cout << "Cam read:\n" << cam_read << std::endl;
if (cam1_w_d != cam_read) {
std::cerr << "Issue when parsing XML file: " << filename << std::endl;
return EXIT_FAILURE;
}
}
{
std::cout << "Cam write:\n" << cam1_wo_d << std::endl;
std::cout << "Cam read:\n" << cam_read << std::endl;
if (cam1_wo_d != cam_read) {
std::cerr << "Issue when parsing XML file: " << filename << std::endl;
return EXIT_FAILURE;
}
}
{
std::cout << "Cam write:\n" << cam2_w_d << std::endl;
std::cout << "Cam read:\n" << cam_read << std::endl;
if (cam2_w_d != cam_read) {
std::cerr << "Issue when parsing XML file: " << filename << std::endl;
return EXIT_FAILURE;
}
}
{
std::cout << "Cam write:\n" << cam2_wo_d << std::endl;
std::cout << "Cam read:\n" << cam_read << std::endl;
if (cam2_wo_d != cam_read) {
std::cerr << "Issue when parsing XML file: " << filename << std::endl;
return EXIT_FAILURE;
}
}
}
{
std::cout << "-- Test to save/load one single camera with Kannala Brandt distortion in a single file" << std::endl;
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);
distortion_coeffs);
std::string filename = tmp_dir + "test_write_cam_with_KannalaBrandt_distortion.xml";
{
std::cout << "Write to: " << filename << std::endl;
std::cerr << "Cannot save XML file: " << filename << std::endl;
return EXIT_FAILURE;
}
}
{
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/load one single camera with Kannala Brandt distortion in a single file wo name" << std::endl;
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);
distortion_coeffs);
std::string filename = tmp_dir + "test_write_cam_with_KannalaBrandt_distortion_wo_name.xml";
{
std::cout << "Write to: " << filename << std::endl;
std::cerr << "Cannot save XML file: " << filename << std::endl;
return EXIT_FAILURE;
}
}
{
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;
std::string filename = tmp_dir + "test_write_2_cam_differ_in_distortion.xml";
{
std::cout << "Write to: " << filename << std::endl;
std::cout << "Cam write:\n" << cam1 << std::endl;
std::cerr << "Cannot save XML file: " << filename << std::endl;
return EXIT_FAILURE;
}
}
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);
distortion_coeffs);
{
std::cout << "Write to: " << filename << std::endl;
std::cout << "Cam write:\n" << cam2 << std::endl;
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;
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;
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;
}
}
}
std::cout << "Test succeed" << std::endl;
#endif
return EXIT_SUCCESS;
}
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
@ perspectiveProjWithDistortion
Perspective projection with distortion model.
@ ProjWithKannalaBrandtDistortion
Projection with Kannala-Brandt distortion model.
@ perspectiveProjWithoutDistortion
Perspective projection without distortion model.
void initPersProjWithDistortion(double px, double py, double u0, double v0, double kud, double kdu)
void initProjWithKannalaBrandtDistortion(double px, double py, double u0, double v0, const std::vector< double > &distortion_coefficients)
XML parser to load and save intrinsic camera parameters.
int save(const vpCameraParameters &cam, const std::string &filename, const std::string &camera_name, unsigned int image_width=0, unsigned int image_height=0, const std::string &additionalInfo="", bool verbose=true)
int parse(vpCameraParameters &cam, const std::string &filename, const std::string &camera_name, const vpCameraParameters::vpCameraParametersProjType &projModel, unsigned int image_width=0, unsigned int image_height=0, bool verbose=true)