42 #include <visp3/core/vpXmlParserCamera.h>
44 #if defined(VISP_HAVE_PUGIXML)
45 #include <pugixml.hpp>
47 #include <visp3/core/vpDebug.h>
55 #define LABEL_XML_ROOT "root"
56 #define LABEL_XML_CAMERA "camera"
57 #define LABEL_XML_CAMERA_NAME "name"
58 #define LABEL_XML_WIDTH "image_width"
59 #define LABEL_XML_HEIGHT "image_height"
60 #define LABEL_XML_SUBSAMPLING_WIDTH "subsampling_width"
61 #define LABEL_XML_SUBSAMPLING_HEIGHT "subsampling_height"
62 #define LABEL_XML_FULL_WIDTH "full_width"
63 #define LABEL_XML_FULL_HEIGHT "full_height"
64 #define LABEL_XML_MODEL "model"
65 #define LABEL_XML_MODEL_TYPE "type"
66 #define LABEL_XML_U0 "u0"
67 #define LABEL_XML_V0 "v0"
68 #define LABEL_XML_PX "px"
69 #define LABEL_XML_PY "py"
70 #define LABEL_XML_KUD "kud"
71 #define LABEL_XML_KDU "kdu"
72 #define LABEL_XML_K1 "k1"
73 #define LABEL_XML_K2 "k2"
74 #define LABEL_XML_K3 "k3"
75 #define LABEL_XML_K4 "k4"
76 #define LABEL_XML_K5 "k5"
78 #define LABEL_XML_MODEL_WITHOUT_DISTORTION "perspectiveProjWithoutDistortion"
79 #define LABEL_XML_MODEL_WITH_DISTORTION "perspectiveProjWithDistortion"
80 #define LABEL_XML_MODEL_WITH_KANNALA_BRANDT_DISTORTION "ProjWithKannalaBrandtDistortion"
82 #define LABEL_XML_ADDITIONAL_INFO "additional_information"
84 #ifndef DOXYGEN_SHOULD_SKIP_THIS
85 class vpXmlParserCamera::Impl
98 CODE_XML_SUBSAMPLING_WIDTH,
99 CODE_XML_SUBSAMPLING_HEIGHT,
100 CODE_XML_FULL_HEIGHT,
115 CODE_XML_ADDITIONAL_INFO
120 : camera(), camera_name(), image_width(0), image_height(0), subsampling_width(0), subsampling_height(0),
121 full_width(0), full_height(0)
126 unsigned int im_height,
bool verbose)
128 pugi::xml_document doc;
129 if (!doc.load_file(filename.c_str())) {
133 pugi::xml_node node = doc.document_element();
138 int ret = read(node, cam_name, projModel, im_width, im_height, verbose);
162 int read(
const pugi::xml_node &node_,
const std::string &cam_name,
164 unsigned int im_height,
bool verbose,
unsigned int subsampl_width = 0,
unsigned int subsampl_height = 0)
168 unsigned int nbCamera = 0;
170 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
171 if (node.type() != pugi::node_element)
174 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
175 prop = CODE_XML_OTHER;
178 if (prop == CODE_XML_CAMERA) {
179 if (
SEQUENCE_OK == read_camera(node, cam_name, projModel, im_width, im_height, subsampl_width, subsampl_height, verbose))
188 vpCERROR <<
"No camera parameters is available" << std::endl <<
"with your specifications" << std::endl;
190 else if (nbCamera > 1) {
192 vpCERROR << nbCamera <<
" sets of camera parameters are available" << std::endl
193 <<
"with your specifications : " << std::endl
194 <<
"precise your choice..." << std::endl;
217 int read_camera(
const pugi::xml_node &node_,
const std::string &cam_name,
219 unsigned int im_height,
unsigned int subsampl_width,
unsigned int subsampl_height,
bool verbose)
223 std::string camera_name_tmp =
"";
224 unsigned int image_height_tmp = 0;
225 unsigned int image_width_tmp = 0;
226 unsigned int subsampling_width_tmp = 0;
227 unsigned int subsampling_height_tmp = 0;
230 bool same_proj_model =
false;
233 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
234 if (node.type() != pugi::node_element)
237 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
238 prop = CODE_XML_OTHER;
243 case CODE_XML_CAMERA_NAME: {
244 camera_name_tmp = node.text().as_string();
246 std::cout <<
"Found camera with name: \"" << camera_name_tmp <<
"\"" << std::endl;
251 image_width_tmp = node.text().as_uint();
254 case CODE_XML_HEIGHT:
255 image_height_tmp = node.text().as_uint();
257 case CODE_XML_SUBSAMPLING_WIDTH:
258 subsampling_width_tmp = node.text().as_uint();
260 case CODE_XML_SUBSAMPLING_HEIGHT:
261 subsampling_height_tmp = node.text().as_uint();
265 back = read_camera_model(node, cam_tmp_model);
267 cam_tmp = cam_tmp_model;
268 same_proj_model =
true;
272 case CODE_XML_ADDITIONAL_INFO:
277 case CODE_XML_CAMERA:
278 case CODE_XML_FULL_HEIGHT:
279 case CODE_XML_FULL_WIDTH:
280 case CODE_XML_MODEL_TYPE:
300 bool test_subsampling_width =
true;
301 bool test_subsampling_height =
true;
303 if (subsampling_width) {
304 test_subsampling_width = (abs((
int)subsampl_width - (
int)subsampling_width_tmp) <
305 (allowedPixelDiffOnImageSize * (int)(subsampling_width_tmp / subsampling_width)));
307 if (subsampling_height) {
308 test_subsampling_height = (abs((
int)subsampl_height - (
int)subsampling_height_tmp) <
309 (allowedPixelDiffOnImageSize * (int)(subsampling_height_tmp / subsampling_height)));
313 bool same_name = (cam_name.empty() || (cam_name == camera_name_tmp));
314 bool same_img_size = (abs((
int)im_width - (
int)image_width_tmp) < allowedPixelDiffOnImageSize || im_width == 0) &&
315 (abs((
int)im_height - (
int)image_height_tmp) < allowedPixelDiffOnImageSize || im_height == 0) &&
316 (test_subsampling_width) && (test_subsampling_height);
317 if (same_name && same_img_size && same_proj_model) {
320 camera_name = camera_name_tmp;
321 image_width = image_width_tmp;
322 image_height = image_height_tmp;
323 subsampling_width = subsampling_width_tmp;
324 subsampling_height = subsampling_height_tmp;
325 full_width = subsampling_width_tmp * image_width_tmp;
326 full_height = subsampling_height_tmp * image_height_tmp;
333 if (!((projModelFound ==
true) &&
334 (abs((
int)im_width - (
int)image_width_tmp) < allowedPixelDiffOnImageSize || im_width == 0) &&
335 (abs((
int)im_height - (
int)image_height_tmp) < allowedPixelDiffOnImageSize || im_height == 0) &&
336 (test_subsampling_width) && (test_subsampling_height))) {
338 if (!cam_name.empty() && (cam_name != camera_name_tmp)) {
347 camera_name = camera_name_tmp;
348 image_width = image_width_tmp;
349 image_height = image_height_tmp;
350 subsampling_width = subsampling_width_tmp;
351 subsampling_height = subsampling_height_tmp;
352 full_width = subsampling_width_tmp * image_width_tmp;
353 full_height = subsampling_height_tmp * image_height_tmp;
373 std::string model_type =
"";
374 double u0 = cam_tmp.
get_u0();
375 double v0 = cam_tmp.
get_v0();
376 double px = cam_tmp.
get_px();
377 double py = cam_tmp.
get_py();
378 double kud = cam_tmp.
get_kud();
379 double kdu = cam_tmp.
get_kdu();
380 std::vector<double> distortion_coeffs;
382 unsigned int validation = 0;
384 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
386 if (node.type() != pugi::node_element)
389 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
390 prop = CODE_XML_OTHER;
395 case CODE_XML_MODEL_TYPE: {
396 model_type = node.text().as_string();
398 validation = validation | 0x01;
401 u0 = node.text().as_double();
403 validation = validation | 0x02;
406 v0 = node.text().as_double();
408 validation = validation | 0x04;
411 px = node.text().as_double();
413 validation = validation | 0x08;
416 py = node.text().as_double();
418 validation = validation | 0x10;
421 kud = node.text().as_double();
423 validation = validation | 0x20;
426 kdu = node.text().as_double();
428 validation = validation | 0x40;
431 distortion_coeffs.push_back(node.text().as_double());
433 validation = validation | 0x20;
436 distortion_coeffs.push_back(node.text().as_double());
438 validation = validation | 0x40;
441 distortion_coeffs.push_back(node.text().as_double());
443 validation = validation | 0x80;
446 distortion_coeffs.push_back(node.text().as_double());
448 validation = validation | 0x100;
451 distortion_coeffs.push_back(node.text().as_double());
453 validation = validation | 0x200;
457 case CODE_XML_CAMERA:
458 case CODE_XML_CAMERA_NAME:
459 case CODE_XML_HEIGHT:
461 case CODE_XML_SUBSAMPLING_WIDTH:
462 case CODE_XML_SUBSAMPLING_HEIGHT:
463 case CODE_XML_FULL_HEIGHT:
464 case CODE_XML_FULL_WIDTH:
466 case CODE_XML_ADDITIONAL_INFO:
473 if (model_type.empty()) {
474 vpERROR_TRACE(
"projection model type doesn't match with any known model !");
478 if (!strcmp(model_type.c_str(), LABEL_XML_MODEL_WITHOUT_DISTORTION)) {
479 if (nb != 5 || validation != 0x001F) {
480 vpCERROR <<
"ERROR in 'model' field:\n";
481 vpCERROR <<
"it must contain 5 parameters\n";
487 else if (!strcmp(model_type.c_str(), LABEL_XML_MODEL_WITH_DISTORTION)) {
488 if (nb != 7 || validation != 0x7F) {
489 vpCERROR <<
"ERROR in 'model' field:\n";
490 vpCERROR <<
"it must contain 7 parameters\n";
496 else if (!strcmp(model_type.c_str(), LABEL_XML_MODEL_WITH_KANNALA_BRANDT_DISTORTION)) {
497 if (nb != 10 || validation != 0x3FF) {
498 vpCERROR <<
"ERROR in 'model' field:\n";
499 vpCERROR <<
"it must contain 10 parameters\n";
501 std::vector<double> fixed_distortion_coeffs;
507 int check = validation / 32;
510 for (
int i = 0; i < 5; ++i) {
513 fixed_distortion_coeffs.push_back(0.);
515 fixed_distortion_coeffs.push_back(distortion_coeffs[j++]);
525 vpERROR_TRACE(
"projection model type doesn't match with any known model !");
533 unsigned int im_width,
unsigned int im_height,
const std::string &additionalInfo,
bool verbose)
535 pugi::xml_document doc;
538 if (!doc.load_file(filename.c_str(), pugi::parse_default | pugi::parse_comments)) {
539 node = doc.append_child(pugi::node_declaration);
540 node.append_attribute(
"version") =
"1.0";
541 node = doc.append_child(LABEL_XML_ROOT);
542 pugi::xml_node nodeComment = node.append_child(pugi::node_comment);
543 nodeComment.set_value(
"This file stores intrinsic camera parameters used\n"
544 " in the vpCameraParameters Class of ViSP available\n"
545 " at https://visp.inria.fr/download/ .\n"
546 " It can be read with the parse method of\n"
547 " the vpXmlParserCamera class.");
550 node = doc.document_element();
557 int nbCamera = count(node, cam_name, cam.
get_projModel(), im_width, im_height, verbose);
562 pugi::xml_node nodeCamera = find_camera(node, cam_name, im_width, im_height);
564 write(node, cam_name, im_width, im_height);
567 write_camera(nodeCamera);
570 if (!additionalInfo.empty()) {
572 nodeCamera = find_camera(node, cam_name, im_width, im_height);
575 pugi::xml_node nodeAdditionalInfo = find_additional_info(nodeCamera);
577 if (!nodeAdditionalInfo) {
579 pugi::xml_node node_comment = nodeCamera.append_child(pugi::node_comment);
580 node_comment.set_value(
"Additional information");
582 nodeAdditionalInfo = nodeCamera.append_child(LABEL_XML_ADDITIONAL_INFO);
585 if (nodeAdditionalInfo) {
587 pugi::xml_document tmpDoc;
588 if (tmpDoc.load_string(additionalInfo.c_str())) {
589 for (node = tmpDoc.first_child(); node; node = node.next_sibling()) {
590 nodeAdditionalInfo.append_copy(node);
596 doc.save_file(filename.c_str(), PUGIXML_TEXT(
" "));
619 int count(
const pugi::xml_node &node_,
const std::string &cam_name,
621 unsigned int im_height,
bool verbose,
unsigned int subsampl_width = 0,
unsigned int subsampl_height = 0)
626 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
627 if (node.type() != pugi::node_element)
630 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
631 prop = CODE_XML_OTHER;
634 if (prop == CODE_XML_CAMERA) {
635 if (
SEQUENCE_OK == read_camera(node, cam_name, projModel, im_width, im_height, subsampl_width, subsampl_height, verbose))
659 pugi::xml_node find_camera(
const pugi::xml_node &node_,
const std::string &cam_name,
unsigned int im_width,
660 unsigned int im_height,
unsigned int subsampl_width = 0,
unsigned int subsampl_height = 0)
664 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
665 if (node.type() != pugi::node_element)
668 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
669 prop = CODE_XML_OTHER;
671 if (prop == CODE_XML_CAMERA) {
672 if (
SEQUENCE_OK == read_camera_header(node, cam_name, im_width, im_height, subsampl_width, subsampl_height)) {
677 return pugi::xml_node();
695 int read_camera_header(
const pugi::xml_node &node_,
const std::string &cam_name,
unsigned int im_width,
696 unsigned int im_height,
unsigned int subsampl_width = 0,
unsigned int subsampl_height = 0)
700 std::string camera_name_tmp =
"";
701 unsigned int image_height_tmp = 0;
702 unsigned int image_width_tmp = 0;
703 unsigned int subsampling_width_tmp = 0;
704 unsigned int subsampling_height_tmp = 0;
707 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
708 if (node.type() != pugi::node_element)
710 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
711 prop = CODE_XML_OTHER;
716 case CODE_XML_CAMERA_NAME:
717 camera_name_tmp = node.text().as_string();
721 image_width_tmp = node.text().as_uint();
724 case CODE_XML_HEIGHT:
725 image_height_tmp = node.text().as_uint();
728 case CODE_XML_SUBSAMPLING_WIDTH:
729 subsampling_width_tmp = node.text().as_uint();
732 case CODE_XML_SUBSAMPLING_HEIGHT:
733 subsampling_height_tmp = node.text().as_uint();
739 case CODE_XML_ADDITIONAL_INFO:
744 case CODE_XML_CAMERA:
745 case CODE_XML_FULL_HEIGHT:
746 case CODE_XML_FULL_WIDTH:
747 case CODE_XML_MODEL_TYPE:
759 if (!((cam_name == camera_name_tmp) && (im_width == image_width_tmp || im_width == 0) &&
760 (im_height == image_height_tmp || im_height == 0) &&
761 (subsampl_width == subsampling_width_tmp || subsampl_width == 0) &&
762 (subsampl_height == subsampling_height_tmp || subsampl_height == 0))) {
783 int write(pugi::xml_node &node,
const std::string &cam_name,
unsigned int im_width,
unsigned int im_height,
784 unsigned int subsampl_width = 0,
unsigned int subsampl_height = 0)
789 pugi::xml_node node_camera = node.append_child(LABEL_XML_CAMERA);
791 pugi::xml_node node_tmp;
794 if (!cam_name.empty()) {
795 node_tmp = node_camera.append_child(pugi::node_comment);
796 node_tmp.set_value(
"Name of the camera");
797 node_tmp = node_camera.append_child(LABEL_XML_CAMERA_NAME);
798 node_tmp.append_child(pugi::node_pcdata).set_value(cam_name.c_str());
801 if (im_width != 0 || im_height != 0) {
802 node_tmp = node_camera.append_child(pugi::node_comment);
803 node_tmp.set_value(
"Size of the image on which camera "
804 "calibration was performed");
807 node_tmp = node_camera.append_child(LABEL_XML_WIDTH);
808 node_tmp.append_child(pugi::node_pcdata).text() = im_width;
811 node_tmp = node_camera.append_child(LABEL_XML_HEIGHT);
812 node_tmp.append_child(pugi::node_pcdata).text() = im_height;
813 if (subsampling_width != 0 || subsampling_height != 0) {
814 node_tmp = node_camera.append_child(pugi::node_comment);
815 node_tmp.set_value(
"Subsampling used to obtain the "
816 "current size of the image.");
819 node_tmp = node_camera.append_child(LABEL_XML_SUBSAMPLING_WIDTH);
820 node_tmp.append_child(pugi::node_pcdata).text() = subsampl_width;
822 node_tmp = node_camera.append_child(LABEL_XML_SUBSAMPLING_HEIGHT);
823 node_tmp.append_child(pugi::node_pcdata).text() = subsampl_height;
824 node_tmp = node_camera.append_child(pugi::node_comment);
825 node_tmp.set_value(
"The full size is the sensor size actually used to "
826 "grab the image. full_width = subsampling_width * "
830 node_tmp = node_camera.append_child(LABEL_XML_FULL_WIDTH);
831 node_tmp.append_child(pugi::node_pcdata).text() = im_width * subsampl_width;
833 node_tmp = node_camera.append_child(LABEL_XML_FULL_HEIGHT);
834 node_tmp.append_child(pugi::node_pcdata).text() = im_height * subsampl_height;
838 node_tmp = node_camera.append_child(pugi::node_comment);
839 node_tmp.set_value(
"Intrinsic camera parameters "
840 "computed for each projection model");
842 back = write_camera(node_camera);
852 int write_camera(pugi::xml_node &node_camera)
854 pugi::xml_node node_model;
855 pugi::xml_node node_tmp;
859 switch (camera.get_projModel()) {
862 node_model = node_camera.append_child(LABEL_XML_MODEL);
864 node_tmp = node_model.append_child(pugi::node_comment);
865 node_tmp.set_value(
"Projection model type");
868 node_tmp = node_model.append_child(LABEL_XML_MODEL_TYPE);
869 node_tmp.append_child(pugi::node_pcdata).set_value(LABEL_XML_MODEL_WITHOUT_DISTORTION);
871 node_tmp = node_model.append_child(pugi::node_comment);
872 node_tmp.set_value(
"Pixel ratio");
874 node_tmp = node_model.append_child(LABEL_XML_PX);
875 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_px();
877 node_tmp = node_model.append_child(LABEL_XML_PY);
878 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_py();
880 node_tmp = node_model.append_child(pugi::node_comment);
881 node_tmp.set_value(
"Principal point");
884 node_tmp = node_model.append_child(LABEL_XML_U0);
885 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_u0();
887 node_tmp = node_model.append_child(LABEL_XML_V0);
888 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_v0();
894 node_model = node_camera.append_child(LABEL_XML_MODEL);
896 node_tmp = node_model.append_child(pugi::node_comment);
897 node_tmp.set_value(
"Projection model type");
899 node_tmp = node_model.append_child(LABEL_XML_MODEL_TYPE);
900 node_tmp.append_child(pugi::node_pcdata).set_value(LABEL_XML_MODEL_WITH_DISTORTION);
902 node_tmp = node_model.append_child(pugi::node_comment);
903 node_tmp.set_value(
"Pixel ratio");
905 node_tmp = node_model.append_child(LABEL_XML_PX);
906 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_px();
908 node_tmp = node_model.append_child(LABEL_XML_PY);
909 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_py();
911 node_tmp = node_model.append_child(pugi::node_comment);
912 node_tmp.set_value(
"Principal point");
914 node_tmp = node_model.append_child(LABEL_XML_U0);
915 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_u0();
917 node_tmp = node_model.append_child(LABEL_XML_V0);
918 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_v0();
921 node_tmp = node_model.append_child(pugi::node_comment);
922 node_tmp.set_value(
"Undistorted to distorted distortion parameter");
923 node_tmp = node_model.append_child(LABEL_XML_KUD);
924 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_kud();
927 node_tmp = node_model.append_child(pugi::node_comment);
928 node_tmp.set_value(
"Distorted to undistorted distortion parameter");
929 node_tmp = node_model.append_child(LABEL_XML_KDU);
930 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_kdu();
936 node_model = node_camera.append_child(LABEL_XML_MODEL);
938 node_tmp = node_model.append_child(pugi::node_comment);
939 node_tmp.set_value(
"Projection model type");
941 node_tmp = node_model.append_child(LABEL_XML_MODEL_TYPE);
942 node_tmp.append_child(pugi::node_pcdata).set_value(LABEL_XML_MODEL_WITH_KANNALA_BRANDT_DISTORTION);
944 node_tmp = node_model.append_child(pugi::node_comment);
945 node_tmp.set_value(
"Pixel ratio");
947 node_tmp = node_model.append_child(LABEL_XML_PX);
948 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_px();
950 node_tmp = node_model.append_child(LABEL_XML_PY);
951 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_py();
953 node_tmp = node_model.append_child(pugi::node_comment);
954 node_tmp.set_value(
"Principal point");
956 node_tmp = node_model.append_child(LABEL_XML_U0);
957 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_u0();
959 node_tmp = node_model.append_child(LABEL_XML_V0);
960 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_v0();
963 std::vector<double> distortion_coefs = camera.getKannalaBrandtDistortionCoefficients();
965 if (distortion_coefs.size() != 5)
966 std::cout <<
"Make sure to have 5 distortion coefficients for Kannala-Brandt distortions." << std::endl;
968 node_tmp = node_model.append_child(pugi::node_comment);
969 node_tmp.set_value(
"Distortion coefficients");
970 node_tmp = node_model.append_child(LABEL_XML_K1);
971 distortion_coefs.size() == 0 ? node_tmp.append_child(pugi::node_pcdata).text() = 0
972 : node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[0];
973 node_tmp = node_model.append_child(LABEL_XML_K2);
974 distortion_coefs.size() <= 1 ? node_tmp.append_child(pugi::node_pcdata).text() = 0
975 : node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[1];
976 node_tmp = node_model.append_child(LABEL_XML_K3);
977 distortion_coefs.size() <= 2 ? node_tmp.append_child(pugi::node_pcdata).text() = 0
978 : node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[2];
979 node_tmp = node_model.append_child(LABEL_XML_K4);
980 distortion_coefs.size() <= 3 ? node_tmp.append_child(pugi::node_pcdata).text() = 0
981 : node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[3];
982 node_tmp = node_model.append_child(LABEL_XML_K5);
983 distortion_coefs.size() <= 4 ? node_tmp.append_child(pugi::node_pcdata).text() = 0
984 : node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[4];
997 pugi::xml_node find_additional_info(
const pugi::xml_node &node_)
1001 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
1002 if (node.type() != pugi::node_element) {
1006 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
1007 prop = CODE_XML_OTHER;
1010 if (prop == CODE_XML_ADDITIONAL_INFO) {
1016 return pugi::xml_node();
1027 vpXmlCodeType val_int = CODE_XML_BAD;
1030 if (!strcmp(str, LABEL_XML_CAMERA)) {
1031 val_int = CODE_XML_CAMERA;
1033 else if (!strcmp(str, LABEL_XML_CAMERA_NAME)) {
1034 val_int = CODE_XML_CAMERA_NAME;
1036 else if (!strcmp(str, LABEL_XML_MODEL)) {
1037 val_int = CODE_XML_MODEL;
1039 else if (!strcmp(str, LABEL_XML_MODEL_TYPE)) {
1040 val_int = CODE_XML_MODEL_TYPE;
1042 else if (!strcmp(str, LABEL_XML_WIDTH)) {
1043 val_int = CODE_XML_WIDTH;
1045 else if (!strcmp(str, LABEL_XML_HEIGHT)) {
1046 val_int = CODE_XML_HEIGHT;
1048 else if (!strcmp(str, LABEL_XML_SUBSAMPLING_WIDTH)) {
1049 val_int = CODE_XML_SUBSAMPLING_WIDTH;
1051 else if (!strcmp(str, LABEL_XML_SUBSAMPLING_HEIGHT)) {
1052 val_int = CODE_XML_SUBSAMPLING_HEIGHT;
1054 else if (!strcmp(str, LABEL_XML_FULL_WIDTH)) {
1055 val_int = CODE_XML_FULL_WIDTH;
1057 else if (!strcmp(str, LABEL_XML_FULL_HEIGHT)) {
1058 val_int = CODE_XML_FULL_HEIGHT;
1060 else if (!strcmp(str, LABEL_XML_U0)) {
1061 val_int = CODE_XML_U0;
1063 else if (!strcmp(str, LABEL_XML_V0)) {
1064 val_int = CODE_XML_V0;
1066 else if (!strcmp(str, LABEL_XML_PX)) {
1067 val_int = CODE_XML_PX;
1069 else if (!strcmp(str, LABEL_XML_PY)) {
1070 val_int = CODE_XML_PY;
1072 else if (!strcmp(str, LABEL_XML_KUD)) {
1073 val_int = CODE_XML_KUD;
1075 else if (!strcmp(str, LABEL_XML_KDU)) {
1076 val_int = CODE_XML_KDU;
1078 else if (!strcmp(str, LABEL_XML_K1)) {
1079 val_int = CODE_XML_K1;
1081 else if (!strcmp(str, LABEL_XML_K2)) {
1082 val_int = CODE_XML_K2;
1084 else if (!strcmp(str, LABEL_XML_K3)) {
1085 val_int = CODE_XML_K3;
1087 else if (!strcmp(str, LABEL_XML_K4)) {
1088 val_int = CODE_XML_K4;
1090 else if (!strcmp(str, LABEL_XML_K5)) {
1091 val_int = CODE_XML_K5;
1093 else if (!strcmp(str, LABEL_XML_ADDITIONAL_INFO)) {
1094 val_int = CODE_XML_ADDITIONAL_INFO;
1097 val_int = CODE_XML_OTHER;
1106 unsigned int getHeight()
const {
return image_height; }
1109 unsigned int getWidth()
const {
return image_width; }
1111 void setCameraName(
const std::string &name) { camera_name = name; }
1112 void setHeight(
unsigned int height) { image_height = height; }
1115 void setWidth(
unsigned int width) { image_width = width; }
1119 std::string camera_name;
1120 unsigned int image_width;
1121 unsigned int image_height;
1122 unsigned int subsampling_width;
1123 unsigned int subsampling_height;
1124 unsigned int full_width;
1125 unsigned int full_height;
1129 static const int allowedPixelDiffOnImageSize = 15;
1154 unsigned int im_height,
bool verbose)
1156 return m_impl->parse(cam, filename, cam_name, projModel, im_width, im_height, verbose);
1204 unsigned int im_width,
unsigned int im_height,
const std::string &additionalInfo,
bool verbose)
1206 return m_impl->save(cam, filename, cam_name, im_width, im_height, additionalInfo, verbose);
1231 #elif !defined(VISP_BUILD_SHARED_LIBS)
1233 void dummy_vpXmlParserCamera() { };
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
vpCameraParametersProjType
@ 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)
vpCameraParametersProjType get_projModel() const
void initProjWithKannalaBrandtDistortion(double px, double py, double u0, double v0, const std::vector< double > &distortion_coefficients)
void setSubsampling_width(unsigned int subsampling)
void setWidth(unsigned int width)
unsigned int getHeight() const
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)
vpCameraParameters getCameraParameters() const
unsigned int getWidth() const
void setSubsampling_height(unsigned int subsampling)
void setCameraName(const std::string &name)
void setHeight(unsigned int height)
unsigned int getSubsampling_height() const
unsigned int getSubsampling_width() const
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)
std::string getCameraName() const