40 #include <visp3/core/vpIoTools.h>
41 #include <visp3/core/vpXmlParserCamera.h>
45 #ifdef ENABLE_VISP_NAMESPACE
48 #if defined(VISP_HAVE_PUGIXML)
51 std::string tmp_dir =
"C:/temp/";
53 std::string tmp_dir =
"/tmp/";
60 tmp_dir += username +
"/test_xml_parser_camera/";
62 std::cout <<
"Create: " << tmp_dir << std::endl;
66 std::cout <<
"-- Test to save/load one single camera without distortion in a single file" << std::endl;
69 std::string filename = tmp_dir +
"test_write_cam_without_distortion.xml";
72 std::cout <<
"Write to: " << filename << std::endl;
74 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
83 std::cout <<
"Cam write:\n" << cam << std::endl;
84 std::cout <<
"Cam read:\n" << cam_read << std::endl;
85 if (cam != cam_read) {
86 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
96 std::cout <<
"Cam write:\n" << cam << std::endl;
97 std::cout <<
"Cam read:\n" << cam_read << std::endl;
98 if (cam != cam_read) {
99 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
106 std::cout <<
"-- Test to save/load one single camera with distortion in a single file" << std::endl;
107 std::string filename = tmp_dir +
"test_write_cam_with_distortion.xml";
112 std::cout <<
"Write to: " << filename << std::endl;
114 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
123 std::cout <<
"Cam write:\n" << cam << std::endl;
124 std::cout <<
"Cam read:\n" << cam_read << std::endl;
125 if (cam != cam_read) {
126 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
136 std::cout <<
"Cam write:\n" << cam << std::endl;
137 std::cout <<
"Cam read:\n" << cam_read << std::endl;
138 if (cam != cam_read) {
139 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
146 std::cout <<
"-- Test to save/load multiple cameras with and without distortion in a single file" << std::endl;
147 std::string filename = tmp_dir +
"test_write_cam_multiple.xml";
152 std::cout <<
"Write to: " << filename <<
" camera:\n" << cam1_w_d << std::endl;
154 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
163 std::cout <<
"Write to: " << filename <<
" camera:\n" << cam1_wo_d << std::endl;
165 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
173 std::cout <<
"Write to: " << filename <<
" camera:\n" << cam2_w_d << std::endl;
175 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
184 std::cout <<
"Write to: " << filename <<
" camera:\n" << cam2_wo_d << std::endl;
186 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
195 std::cout <<
"Cam write:\n" << cam1_w_d << std::endl;
196 std::cout <<
"Cam read:\n" << cam_read << std::endl;
197 if (cam1_w_d != cam_read) {
198 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
206 std::cout <<
"Cam write:\n" << cam1_wo_d << std::endl;
207 std::cout <<
"Cam read:\n" << cam_read << std::endl;
208 if (cam1_wo_d != cam_read) {
209 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
217 std::cout <<
"Cam write:\n" << cam2_w_d << std::endl;
218 std::cout <<
"Cam read:\n" << cam_read << std::endl;
219 if (cam2_w_d != cam_read) {
220 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
228 std::cout <<
"Cam write:\n" << cam2_wo_d << std::endl;
229 std::cout <<
"Cam read:\n" << cam_read << std::endl;
230 if (cam2_wo_d != cam_read) {
231 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
238 std::cout <<
"-- Test to save/load one single camera with Kannala Brandt distortion in a single file" << std::endl;
240 std::vector<double> distortion_coeffs;
241 distortion_coeffs.push_back(-0.00297341705299914);
242 distortion_coeffs.push_back(0.0352853797376156);
243 distortion_coeffs.push_back(-0.032205019146204);
244 distortion_coeffs.push_back(0.004446716979146);
245 distortion_coeffs.push_back(0);
248 std::string filename = tmp_dir +
"test_write_cam_with_KannalaBrandt_distortion.xml";
251 std::cout <<
"Write to: " << filename << std::endl;
253 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
262 std::cout <<
"Cam write:\n" << cam << std::endl;
263 std::cout <<
"Cam read:\n" << cam_read << std::endl;
264 if (cam != cam_read) {
265 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
272 std::cout <<
"-- Test to save/load one single camera with Kannala Brandt distortion in a single file wo name" << std::endl;
274 std::vector<double> distortion_coeffs;
275 distortion_coeffs.push_back(-0.00297341705299914);
276 distortion_coeffs.push_back(0.0352853797376156);
277 distortion_coeffs.push_back(-0.032205019146204);
278 distortion_coeffs.push_back(0.004446716979146);
279 distortion_coeffs.push_back(0);
282 std::string filename = tmp_dir +
"test_write_cam_with_KannalaBrandt_distortion_wo_name.xml";
285 std::cout <<
"Write to: " << filename << std::endl;
287 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
296 std::cout <<
"Cam write:\n" << cam << std::endl;
297 std::cout <<
"Cam read:\n" << cam_read << std::endl;
298 if (cam != cam_read) {
299 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
306 std::cout <<
"-- Test to save 2 cameras and parse them wo name thanks they differ in distortion" << std::endl;
309 std::string filename = tmp_dir +
"test_write_2_cam_differ_in_distortion.xml";
313 std::cout <<
"Write to: " << filename << std::endl;
314 std::cout <<
"Cam write:\n" << cam1 << std::endl;
316 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
322 std::vector<double> distortion_coeffs;
323 distortion_coeffs.push_back(-0.00297341705299914);
324 distortion_coeffs.push_back(0.0352853797376156);
325 distortion_coeffs.push_back(-0.032205019146204);
326 distortion_coeffs.push_back(0.004446716979146);
327 distortion_coeffs.push_back(0);
332 std::cout <<
"Write to: " << filename << std::endl;
333 std::cout <<
"Cam write:\n" << cam2 << std::endl;
335 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
341 std::cout <<
"Attempt to read camera with perspective projection without distortion and without name" << std::endl;
346 std::cout <<
"Cam read:\n" << cam_read << std::endl;
347 if (cam1 != cam_read) {
348 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
354 std::cout <<
"Attempt to read camera with Kannala Brandt distortion and without name" << std::endl;
359 std::cout <<
"Cam read:\n" << cam_read << std::endl;
360 if (cam2 != cam_read) {
361 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
369 std::cout <<
"Test succeed" << std::endl;
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)