42 #include <visp3/core/vpIoTools.h>
43 #include <visp3/core/vpXmlParserCamera.h>
47 #if defined(VISP_HAVE_PUGIXML)
50 std::string tmp_dir =
"C:/temp/";
52 std::string tmp_dir =
"/tmp/";
59 tmp_dir += username +
"/test_xml_parser_camera/";
61 std::cout <<
"Create: " << tmp_dir << std::endl;
65 std::cout <<
"-- Test to save/load one single camera without distortion in a single file" << std::endl;
68 std::string filename = tmp_dir +
"test_write_cam_without_distortion.xml";
71 std::cout <<
"Write to: " << filename << std::endl;
73 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
82 std::cout <<
"Cam write:\n" << cam << std::endl;
83 std::cout <<
"Cam read:\n" << cam_read << std::endl;
84 if (cam != cam_read) {
85 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
95 std::cout <<
"Cam write:\n" << cam << std::endl;
96 std::cout <<
"Cam read:\n" << cam_read << std::endl;
97 if (cam != cam_read) {
98 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
105 std::cout <<
"-- Test to save/load one single camera with distortion in a single file" << std::endl;
106 std::string filename = tmp_dir +
"test_write_cam_with_distortion.xml";
111 std::cout <<
"Write to: " << filename << std::endl;
113 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
122 std::cout <<
"Cam write:\n" << cam << std::endl;
123 std::cout <<
"Cam read:\n" << cam_read << std::endl;
124 if (cam != cam_read) {
125 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
135 std::cout <<
"Cam write:\n" << cam << std::endl;
136 std::cout <<
"Cam read:\n" << cam_read << std::endl;
137 if (cam != cam_read) {
138 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
145 std::cout <<
"-- Test to save/load multiple cameras with and without distortion in a single file" << std::endl;
146 std::string filename = tmp_dir +
"test_write_cam_multiple.xml";
151 std::cout <<
"Write to: " << filename <<
" camera:\n" << cam1_w_d << std::endl;
153 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
162 std::cout <<
"Write to: " << filename <<
" camera:\n" << cam1_wo_d << std::endl;
164 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
172 std::cout <<
"Write to: " << filename <<
" camera:\n" << cam2_w_d << std::endl;
174 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
183 std::cout <<
"Write to: " << filename <<
" camera:\n" << cam2_wo_d << std::endl;
185 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
194 std::cout <<
"Cam write:\n" << cam1_w_d << std::endl;
195 std::cout <<
"Cam read:\n" << cam_read << std::endl;
196 if (cam1_w_d != cam_read) {
197 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
205 std::cout <<
"Cam write:\n" << cam1_wo_d << std::endl;
206 std::cout <<
"Cam read:\n" << cam_read << std::endl;
207 if (cam1_wo_d != cam_read) {
208 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
216 std::cout <<
"Cam write:\n" << cam2_w_d << std::endl;
217 std::cout <<
"Cam read:\n" << cam_read << std::endl;
218 if (cam2_w_d != cam_read) {
219 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
227 std::cout <<
"Cam write:\n" << cam2_wo_d << std::endl;
228 std::cout <<
"Cam read:\n" << cam_read << std::endl;
229 if (cam2_wo_d != cam_read) {
230 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
237 std::cout <<
"-- Test to save/load one single camera with Kannala Brandt distortion in a single file" << std::endl;
239 std::vector<double> distortion_coeffs;
240 distortion_coeffs.push_back(-0.00297341705299914);
241 distortion_coeffs.push_back(0.0352853797376156);
242 distortion_coeffs.push_back(-0.032205019146204);
243 distortion_coeffs.push_back(0.004446716979146);
244 distortion_coeffs.push_back(0);
247 std::string filename = tmp_dir +
"test_write_cam_with_KannalaBrandt_distortion.xml";
250 std::cout <<
"Write to: " << filename << std::endl;
252 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
261 std::cout <<
"Cam write:\n" << cam << std::endl;
262 std::cout <<
"Cam read:\n" << cam_read << std::endl;
263 if (cam != cam_read) {
264 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
271 std::cout <<
"-- Test to save/load one single camera with Kannala Brandt distortion in a single file wo name" << std::endl;
273 std::vector<double> distortion_coeffs;
274 distortion_coeffs.push_back(-0.00297341705299914);
275 distortion_coeffs.push_back(0.0352853797376156);
276 distortion_coeffs.push_back(-0.032205019146204);
277 distortion_coeffs.push_back(0.004446716979146);
278 distortion_coeffs.push_back(0);
281 std::string filename = tmp_dir +
"test_write_cam_with_KannalaBrandt_distortion_wo_name.xml";
284 std::cout <<
"Write to: " << filename << std::endl;
286 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
295 std::cout <<
"Cam write:\n" << cam << std::endl;
296 std::cout <<
"Cam read:\n" << cam_read << std::endl;
297 if (cam != cam_read) {
298 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
305 std::cout <<
"-- Test to save 2 cameras and parse them wo name thanks they differ in distortion" << std::endl;
308 std::string filename = tmp_dir +
"test_write_2_cam_differ_in_distortion.xml";
312 std::cout <<
"Write to: " << filename << std::endl;
313 std::cout <<
"Cam write:\n" << cam1 << std::endl;
315 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
321 std::vector<double> distortion_coeffs;
322 distortion_coeffs.push_back(-0.00297341705299914);
323 distortion_coeffs.push_back(0.0352853797376156);
324 distortion_coeffs.push_back(-0.032205019146204);
325 distortion_coeffs.push_back(0.004446716979146);
326 distortion_coeffs.push_back(0);
331 std::cout <<
"Write to: " << filename << std::endl;
332 std::cout <<
"Cam write:\n" << cam2 << std::endl;
334 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
340 std::cout <<
"Attempt to read camera with perspective projection without distortion and without name" << std::endl;
345 std::cout <<
"Cam read:\n" << cam_read << std::endl;
346 if (cam1 != cam_read) {
347 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
353 std::cout <<
"Attempt to read camera with Kannala Brandt distortion and without name" << std::endl;
358 std::cout <<
"Cam read:\n" << cam_read << std::endl;
359 if (cam2 != cam_read) {
360 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
368 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)