40 #include <visp3/core/vpIoTools.h>
41 #include <visp3/core/vpXmlParserCamera.h>
45 #ifdef ENABLE_VISP_NAMESPACE
48 #if defined(VISP_HAVE_PUGIXML)
53 std::cout <<
"Create: " << tmp_dir << std::endl;
57 std::cout <<
"-- Test to save/load one single camera without distortion in a single file" << std::endl;
60 std::string filename = tmp_dir +
"test_write_cam_without_distortion.xml";
63 std::cout <<
"Write to: " << filename << std::endl;
65 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
74 std::cout <<
"Cam write:\n" << cam << std::endl;
75 std::cout <<
"Cam read:\n" << cam_read << std::endl;
76 if (cam != cam_read) {
77 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
87 std::cout <<
"Cam write:\n" << cam << std::endl;
88 std::cout <<
"Cam read:\n" << cam_read << std::endl;
89 if (cam != cam_read) {
90 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
97 std::cout <<
"-- Test to save/load one single camera with distortion in a single file" << std::endl;
98 std::string filename = tmp_dir +
"test_write_cam_with_distortion.xml";
103 std::cout <<
"Write to: " << filename << std::endl;
105 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
114 std::cout <<
"Cam write:\n" << cam << std::endl;
115 std::cout <<
"Cam read:\n" << cam_read << std::endl;
116 if (cam != cam_read) {
117 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
127 std::cout <<
"Cam write:\n" << cam << std::endl;
128 std::cout <<
"Cam read:\n" << cam_read << std::endl;
129 if (cam != cam_read) {
130 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
137 std::cout <<
"-- Test to save/load multiple cameras with and without distortion in a single file" << std::endl;
138 std::string filename = tmp_dir +
"test_write_cam_multiple.xml";
143 std::cout <<
"Write to: " << filename <<
" camera:\n" << cam1_w_d << std::endl;
145 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
154 std::cout <<
"Write to: " << filename <<
" camera:\n" << cam1_wo_d << std::endl;
156 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
164 std::cout <<
"Write to: " << filename <<
" camera:\n" << cam2_w_d << std::endl;
166 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
175 std::cout <<
"Write to: " << filename <<
" camera:\n" << cam2_wo_d << std::endl;
177 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
186 std::cout <<
"Cam write:\n" << cam1_w_d << std::endl;
187 std::cout <<
"Cam read:\n" << cam_read << std::endl;
188 if (cam1_w_d != cam_read) {
189 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
197 std::cout <<
"Cam write:\n" << cam1_wo_d << std::endl;
198 std::cout <<
"Cam read:\n" << cam_read << std::endl;
199 if (cam1_wo_d != cam_read) {
200 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
208 std::cout <<
"Cam write:\n" << cam2_w_d << std::endl;
209 std::cout <<
"Cam read:\n" << cam_read << std::endl;
210 if (cam2_w_d != cam_read) {
211 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
219 std::cout <<
"Cam write:\n" << cam2_wo_d << std::endl;
220 std::cout <<
"Cam read:\n" << cam_read << std::endl;
221 if (cam2_wo_d != cam_read) {
222 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
229 std::cout <<
"-- Test to save/load one single camera with Kannala Brandt distortion in a single file" << std::endl;
231 std::vector<double> distortion_coeffs;
232 distortion_coeffs.push_back(-0.00297341705299914);
233 distortion_coeffs.push_back(0.0352853797376156);
234 distortion_coeffs.push_back(-0.032205019146204);
235 distortion_coeffs.push_back(0.004446716979146);
236 distortion_coeffs.push_back(0);
239 std::string filename = tmp_dir +
"test_write_cam_with_KannalaBrandt_distortion.xml";
242 std::cout <<
"Write to: " << filename << std::endl;
244 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
253 std::cout <<
"Cam write:\n" << cam << std::endl;
254 std::cout <<
"Cam read:\n" << cam_read << std::endl;
255 if (cam != cam_read) {
256 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
263 std::cout <<
"-- Test to save/load one single camera with Kannala Brandt distortion in a single file wo name" << std::endl;
265 std::vector<double> distortion_coeffs;
266 distortion_coeffs.push_back(-0.00297341705299914);
267 distortion_coeffs.push_back(0.0352853797376156);
268 distortion_coeffs.push_back(-0.032205019146204);
269 distortion_coeffs.push_back(0.004446716979146);
270 distortion_coeffs.push_back(0);
273 std::string filename = tmp_dir +
"test_write_cam_with_KannalaBrandt_distortion_wo_name.xml";
276 std::cout <<
"Write to: " << filename << std::endl;
278 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
287 std::cout <<
"Cam write:\n" << cam << std::endl;
288 std::cout <<
"Cam read:\n" << cam_read << std::endl;
289 if (cam != cam_read) {
290 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
297 std::cout <<
"-- Test to save 2 cameras and parse them wo name thanks they differ in distortion" << std::endl;
300 std::string filename = tmp_dir +
"test_write_2_cam_differ_in_distortion.xml";
304 std::cout <<
"Write to: " << filename << std::endl;
305 std::cout <<
"Cam write:\n" << cam1 << std::endl;
307 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
313 std::vector<double> distortion_coeffs;
314 distortion_coeffs.push_back(-0.00297341705299914);
315 distortion_coeffs.push_back(0.0352853797376156);
316 distortion_coeffs.push_back(-0.032205019146204);
317 distortion_coeffs.push_back(0.004446716979146);
318 distortion_coeffs.push_back(0);
323 std::cout <<
"Write to: " << filename << std::endl;
324 std::cout <<
"Cam write:\n" << cam2 << std::endl;
326 std::cerr <<
"Cannot save XML file: " << filename << std::endl;
332 std::cout <<
"Attempt to read camera with perspective projection without distortion and without name" << std::endl;
337 std::cout <<
"Cam read:\n" << cam_read << std::endl;
338 if (cam1 != cam_read) {
339 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
345 std::cout <<
"Attempt to read camera with Kannala Brandt distortion and without name" << std::endl;
350 std::cout <<
"Cam read:\n" << cam_read << std::endl;
351 if (cam2 != cam_read) {
352 std::cerr <<
"Issue when parsing XML file: " << filename << std::endl;
360 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)