42 #include <visp3/core/vpXmlParserCamera.h>
44 #include <pugixml.hpp>
46 #include <visp3/core/vpDebug.h>
54 #define LABEL_XML_ROOT "root"
55 #define LABEL_XML_CAMERA "camera"
56 #define LABEL_XML_CAMERA_NAME "name"
57 #define LABEL_XML_WIDTH "image_width"
58 #define LABEL_XML_HEIGHT "image_height"
59 #define LABEL_XML_SUBSAMPLING_WIDTH "subsampling_width"
60 #define LABEL_XML_SUBSAMPLING_HEIGHT "subsampling_height"
61 #define LABEL_XML_FULL_WIDTH "full_width"
62 #define LABEL_XML_FULL_HEIGHT "full_height"
63 #define LABEL_XML_MODEL "model"
64 #define LABEL_XML_MODEL_TYPE "type"
65 #define LABEL_XML_U0 "u0"
66 #define LABEL_XML_V0 "v0"
67 #define LABEL_XML_PX "px"
68 #define LABEL_XML_PY "py"
69 #define LABEL_XML_KUD "kud"
70 #define LABEL_XML_KDU "kdu"
71 #define LABEL_XML_K1 "k1"
72 #define LABEL_XML_K2 "k2"
73 #define LABEL_XML_K3 "k3"
74 #define LABEL_XML_K4 "k4"
75 #define LABEL_XML_K5 "k5"
77 #define LABEL_XML_MODEL_WITHOUT_DISTORTION "perspectiveProjWithoutDistortion"
78 #define LABEL_XML_MODEL_WITH_DISTORTION "perspectiveProjWithDistortion"
79 #define LABEL_XML_MODEL_WITH_KANNALA_BRANDT_DISTORTION "ProjWithKannalaBrandtDistortion"
81 #define LABEL_XML_ADDITIONAL_INFO "additional_information"
83 #ifndef DOXYGEN_SHOULD_SKIP_THIS
84 class vpXmlParserCamera::Impl
97 CODE_XML_SUBSAMPLING_WIDTH,
98 CODE_XML_SUBSAMPLING_HEIGHT,
114 CODE_XML_ADDITIONAL_INFO
119 : camera(), camera_name(), image_width(0), image_height(0), subsampling_width(0), subsampling_height(0),
120 full_width(0), full_height(0)
125 unsigned int im_height,
bool verbose)
127 pugi::xml_document doc;
128 if (!doc.load_file(filename.c_str())) {
132 pugi::xml_node node = doc.document_element();
137 int ret = read(node, cam_name, projModel, im_width, im_height, verbose);
161 int read(
const pugi::xml_node &node_,
const std::string &cam_name,
163 unsigned int im_height,
bool verbose,
unsigned int subsampl_width = 0,
unsigned int subsampl_height = 0)
167 unsigned int nbCamera = 0;
169 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
170 if (node.type() != pugi::node_element)
173 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
174 prop = CODE_XML_OTHER;
177 if (prop == CODE_XML_CAMERA) {
178 if (
SEQUENCE_OK == read_camera(node, cam_name, projModel, im_width, im_height, subsampl_width, subsampl_height, verbose))
187 vpCERROR <<
"No camera parameters is available" << std::endl <<
"with your specifications" << std::endl;
189 else if (nbCamera > 1) {
191 vpCERROR << nbCamera <<
" sets of camera parameters are available" << std::endl
192 <<
"with your specifications : " << std::endl
193 <<
"precise your choice..." << std::endl;
216 int read_camera(
const pugi::xml_node &node_,
const std::string &cam_name,
218 unsigned int im_height,
unsigned int subsampl_width,
unsigned int subsampl_height,
bool verbose)
222 std::string camera_name_tmp =
"";
223 unsigned int image_height_tmp = 0;
224 unsigned int image_width_tmp = 0;
225 unsigned int subsampling_width_tmp = 0;
226 unsigned int subsampling_height_tmp = 0;
229 bool same_proj_model =
false;
232 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
233 if (node.type() != pugi::node_element)
236 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
237 prop = CODE_XML_OTHER;
242 case CODE_XML_CAMERA_NAME: {
243 camera_name_tmp = node.text().as_string();
245 std::cout <<
"Found camera with name: \"" << camera_name_tmp <<
"\"" << std::endl;
250 image_width_tmp = node.text().as_uint();
253 case CODE_XML_HEIGHT:
254 image_height_tmp = node.text().as_uint();
256 case CODE_XML_SUBSAMPLING_WIDTH:
257 subsampling_width_tmp = node.text().as_uint();
259 case CODE_XML_SUBSAMPLING_HEIGHT:
260 subsampling_height_tmp = node.text().as_uint();
264 back = read_camera_model(node, cam_tmp_model);
266 cam_tmp = cam_tmp_model;
267 same_proj_model =
true;
271 case CODE_XML_ADDITIONAL_INFO:
276 case CODE_XML_CAMERA:
277 case CODE_XML_FULL_HEIGHT:
278 case CODE_XML_FULL_WIDTH:
279 case CODE_XML_MODEL_TYPE:
299 bool test_subsampling_width =
true;
300 bool test_subsampling_height =
true;
302 if (subsampling_width) {
303 test_subsampling_width = (abs((
int)subsampl_width - (
int)subsampling_width_tmp) <
304 (allowedPixelDiffOnImageSize * (int)(subsampling_width_tmp / subsampling_width)));
306 if (subsampling_height) {
307 test_subsampling_height = (abs((
int)subsampl_height - (
int)subsampling_height_tmp) <
308 (allowedPixelDiffOnImageSize * (int)(subsampling_height_tmp / subsampling_height)));
312 bool same_name = (!cam_name.empty() && (cam_name == camera_name_tmp));
313 bool same_img_size = (abs((
int)im_width - (
int)image_width_tmp) < allowedPixelDiffOnImageSize || im_width == 0) &&
314 (abs((
int)im_height - (
int)image_height_tmp) < allowedPixelDiffOnImageSize || im_height == 0) &&
315 (test_subsampling_width) && (test_subsampling_height);
316 if (same_name && same_img_size && same_proj_model) {
319 camera_name = camera_name_tmp;
320 image_width = image_width_tmp;
321 image_height = image_height_tmp;
322 subsampling_width = subsampling_width_tmp;
323 subsampling_height = subsampling_height_tmp;
324 full_width = subsampling_width_tmp * image_width_tmp;
325 full_height = subsampling_height_tmp * image_height_tmp;
332 if (!((projModelFound ==
true) &&
333 (abs((
int)im_width - (
int)image_width_tmp) < allowedPixelDiffOnImageSize || im_width == 0) &&
334 (abs((
int)im_height - (
int)image_height_tmp) < allowedPixelDiffOnImageSize || im_height == 0) &&
335 (test_subsampling_width) && (test_subsampling_height))) {
337 if (!cam_name.empty() && (cam_name != camera_name_tmp)) {
346 camera_name = camera_name_tmp;
347 image_width = image_width_tmp;
348 image_height = image_height_tmp;
349 subsampling_width = subsampling_width_tmp;
350 subsampling_height = subsampling_height_tmp;
351 full_width = subsampling_width_tmp * image_width_tmp;
352 full_height = subsampling_height_tmp * image_height_tmp;
372 std::string model_type =
"";
373 double u0 = cam_tmp.
get_u0();
374 double v0 = cam_tmp.
get_v0();
375 double px = cam_tmp.
get_px();
376 double py = cam_tmp.
get_py();
377 double kud = cam_tmp.
get_kud();
378 double kdu = cam_tmp.
get_kdu();
379 std::vector<double> distortion_coeffs;
383 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
385 if (node.type() != pugi::node_element)
388 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
389 prop = CODE_XML_OTHER;
394 case CODE_XML_MODEL_TYPE: {
395 model_type = node.text().as_string();
397 validation = validation | 0x01;
400 u0 = node.text().as_double();
402 validation = validation | 0x02;
405 v0 = node.text().as_double();
407 validation = validation | 0x04;
410 px = node.text().as_double();
412 validation = validation | 0x08;
415 py = node.text().as_double();
417 validation = validation | 0x10;
420 kud = node.text().as_double();
422 validation = validation | 0x20;
425 kdu = node.text().as_double();
427 validation = validation | 0x40;
430 distortion_coeffs.push_back(node.text().as_double());
432 validation = validation | 0x20;
435 distortion_coeffs.push_back(node.text().as_double());
437 validation = validation | 0x40;
440 distortion_coeffs.push_back(node.text().as_double());
442 validation = validation | 0x80;
445 distortion_coeffs.push_back(node.text().as_double());
447 validation = validation | 0x100;
450 distortion_coeffs.push_back(node.text().as_double());
452 validation = validation | 0x200;
456 case CODE_XML_CAMERA:
457 case CODE_XML_CAMERA_NAME:
458 case CODE_XML_HEIGHT:
460 case CODE_XML_SUBSAMPLING_WIDTH:
461 case CODE_XML_SUBSAMPLING_HEIGHT:
462 case CODE_XML_FULL_HEIGHT:
463 case CODE_XML_FULL_WIDTH:
465 case CODE_XML_ADDITIONAL_INFO:
472 if (model_type.empty()) {
473 vpERROR_TRACE(
"projection model type doesn't match with any known model !");
477 if (!strcmp(model_type.c_str(), LABEL_XML_MODEL_WITHOUT_DISTORTION)) {
478 if (nb != 5 || validation != 0x001F) {
479 vpCERROR <<
"ERROR in 'model' field:\n";
480 vpCERROR <<
"it must contain 5 parameters\n";
486 else if (!strcmp(model_type.c_str(), LABEL_XML_MODEL_WITH_DISTORTION)) {
487 if (nb != 7 || validation != 0x7F) {
488 vpCERROR <<
"ERROR in 'model' field:\n";
489 vpCERROR <<
"it must contain 7 parameters\n";
495 else if (!strcmp(model_type.c_str(), LABEL_XML_MODEL_WITH_KANNALA_BRANDT_DISTORTION)) {
496 if (nb != 10 || validation != 0x3FF) {
497 vpCERROR <<
"ERROR in 'model' field:\n";
498 vpCERROR <<
"it must contain 10 parameters\n";
500 std::vector<double> fixed_distortion_coeffs;
506 int check = validation / 32;
509 for (
int i = 0; i < 5; i++) {
512 fixed_distortion_coeffs.push_back(0.);
514 fixed_distortion_coeffs.push_back(distortion_coeffs[j++]);
524 vpERROR_TRACE(
"projection model type doesn't match with any known model !");
532 unsigned int im_width,
unsigned int im_height,
const std::string &additionalInfo,
bool verbose)
534 pugi::xml_document doc;
537 if (!doc.load_file(filename.c_str(), pugi::parse_default | pugi::parse_comments)) {
538 node = doc.append_child(pugi::node_declaration);
539 node.append_attribute(
"version") =
"1.0";
540 node = doc.append_child(LABEL_XML_ROOT);
541 pugi::xml_node nodeComment = node.append_child(pugi::node_comment);
542 nodeComment.set_value(
"This file stores intrinsic camera parameters used\n"
543 " in the vpCameraParameters Class of ViSP available\n"
544 " at https://visp.inria.fr/download/ .\n"
545 " It can be read with the parse method of\n"
546 " the vpXmlParserCamera class.");
549 node = doc.document_element();
556 int nbCamera = count(node, cam_name, cam.
get_projModel(), verbose, im_width, im_height);
561 pugi::xml_node nodeCamera = find_camera(node, cam_name, im_width, im_height);
563 write(node, cam_name, im_width, im_height);
566 write_camera(nodeCamera);
569 if (!additionalInfo.empty()) {
571 nodeCamera = find_camera(node, cam_name, im_width, im_height);
574 pugi::xml_node nodeAdditionalInfo = find_additional_info(nodeCamera);
576 if (!nodeAdditionalInfo) {
578 pugi::xml_node node_comment = nodeCamera.append_child(pugi::node_comment);
579 node_comment.set_value(
"Additional information");
581 nodeAdditionalInfo = nodeCamera.append_child(LABEL_XML_ADDITIONAL_INFO);
584 if (nodeAdditionalInfo) {
586 pugi::xml_document tmpDoc;
587 if (tmpDoc.load_string(additionalInfo.c_str())) {
588 for (node = tmpDoc.first_child(); node; node = node.next_sibling()) {
589 nodeAdditionalInfo.append_copy(node);
595 doc.save_file(filename.c_str(), PUGIXML_TEXT(
" "));
618 int count(
const pugi::xml_node &node_,
const std::string &cam_name,
620 unsigned int im_height,
bool verbose,
unsigned int subsampl_width = 0,
unsigned int subsampl_height = 0)
625 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
626 if (node.type() != pugi::node_element)
629 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
630 prop = CODE_XML_OTHER;
633 if (prop == CODE_XML_CAMERA) {
634 if (
SEQUENCE_OK == read_camera(node, cam_name, projModel, im_width, im_height, subsampl_width, subsampl_height, verbose))
658 pugi::xml_node find_camera(
const pugi::xml_node &node_,
const std::string &cam_name,
unsigned int im_width,
659 unsigned int im_height,
unsigned int subsampl_width = 0,
unsigned int subsampl_height = 0)
663 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
664 if (node.type() != pugi::node_element)
667 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
668 prop = CODE_XML_OTHER;
670 if (prop == CODE_XML_CAMERA) {
671 if (
SEQUENCE_OK == read_camera_header(node, cam_name, im_width, im_height, subsampl_width, subsampl_height)) {
676 return pugi::xml_node();
694 int read_camera_header(
const pugi::xml_node &node_,
const std::string &cam_name,
unsigned int im_width,
695 unsigned int im_height,
unsigned int subsampl_width = 0,
unsigned int subsampl_height = 0)
699 std::string camera_name_tmp =
"";
700 unsigned int image_height_tmp = 0;
701 unsigned int image_width_tmp = 0;
702 unsigned int subsampling_width_tmp = 0;
703 unsigned int subsampling_height_tmp = 0;
706 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
707 if (node.type() != pugi::node_element)
709 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
710 prop = CODE_XML_OTHER;
715 case CODE_XML_CAMERA_NAME:
716 camera_name_tmp = node.text().as_string();
720 image_width_tmp = node.text().as_uint();
723 case CODE_XML_HEIGHT:
724 image_height_tmp = node.text().as_uint();
727 case CODE_XML_SUBSAMPLING_WIDTH:
728 subsampling_width_tmp = node.text().as_uint();
731 case CODE_XML_SUBSAMPLING_HEIGHT:
732 subsampling_height_tmp = node.text().as_uint();
738 case CODE_XML_ADDITIONAL_INFO:
743 case CODE_XML_CAMERA:
744 case CODE_XML_FULL_HEIGHT:
745 case CODE_XML_FULL_WIDTH:
746 case CODE_XML_MODEL_TYPE:
758 if (!((cam_name == camera_name_tmp) && (im_width == image_width_tmp || im_width == 0) &&
759 (im_height == image_height_tmp || im_height == 0) &&
760 (subsampl_width == subsampling_width_tmp || subsampl_width == 0) &&
761 (subsampl_height == subsampling_height_tmp || subsampl_height == 0))) {
782 int write(pugi::xml_node &node,
const std::string &cam_name,
unsigned int im_width,
unsigned int im_height,
783 unsigned int subsampl_width = 0,
unsigned int subsampl_height = 0)
788 pugi::xml_node node_camera = node.append_child(LABEL_XML_CAMERA);
790 pugi::xml_node node_tmp;
793 if (!cam_name.empty()) {
794 node_tmp = node_camera.append_child(pugi::node_comment);
795 node_tmp.set_value(
"Name of the camera");
796 node_tmp = node_camera.append_child(LABEL_XML_CAMERA_NAME);
797 node_tmp.append_child(pugi::node_pcdata).set_value(cam_name.c_str());
800 if (im_width != 0 || im_height != 0) {
801 node_tmp = node_camera.append_child(pugi::node_comment);
802 node_tmp.set_value(
"Size of the image on which camera "
803 "calibration was performed");
806 node_tmp = node_camera.append_child(LABEL_XML_WIDTH);
807 node_tmp.append_child(pugi::node_pcdata).text() = im_width;
810 node_tmp = node_camera.append_child(LABEL_XML_HEIGHT);
811 node_tmp.append_child(pugi::node_pcdata).text() = im_height;
812 if (subsampling_width != 0 || subsampling_height != 0) {
813 node_tmp = node_camera.append_child(pugi::node_comment);
814 node_tmp.set_value(
"Subsampling used to obtain the "
815 "current size of the image.");
818 node_tmp = node_camera.append_child(LABEL_XML_SUBSAMPLING_WIDTH);
819 node_tmp.append_child(pugi::node_pcdata).text() = subsampl_width;
821 node_tmp = node_camera.append_child(LABEL_XML_SUBSAMPLING_HEIGHT);
822 node_tmp.append_child(pugi::node_pcdata).text() = subsampl_height;
823 node_tmp = node_camera.append_child(pugi::node_comment);
824 node_tmp.set_value(
"The full size is the sensor size actually used to "
825 "grab the image. full_width = subsampling_width * "
829 node_tmp = node_camera.append_child(LABEL_XML_FULL_WIDTH);
830 node_tmp.append_child(pugi::node_pcdata).text() = im_width * subsampl_width;
832 node_tmp = node_camera.append_child(LABEL_XML_FULL_HEIGHT);
833 node_tmp.append_child(pugi::node_pcdata).text() = im_height * subsampl_height;
837 node_tmp = node_camera.append_child(pugi::node_comment);
838 node_tmp.set_value(
"Intrinsic camera parameters "
839 "computed for each projection model");
841 back = write_camera(node_camera);
851 int write_camera(pugi::xml_node &node_camera)
853 pugi::xml_node node_model;
854 pugi::xml_node node_tmp;
858 switch (camera.get_projModel()) {
861 node_model = node_camera.append_child(LABEL_XML_MODEL);
863 node_tmp = node_model.append_child(pugi::node_comment);
864 node_tmp.set_value(
"Projection model type");
867 node_tmp = node_model.append_child(LABEL_XML_MODEL_TYPE);
868 node_tmp.append_child(pugi::node_pcdata).set_value(LABEL_XML_MODEL_WITHOUT_DISTORTION);
870 node_tmp = node_model.append_child(pugi::node_comment);
871 node_tmp.set_value(
"Pixel ratio");
873 node_tmp = node_model.append_child(LABEL_XML_PX);
874 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_px();
876 node_tmp = node_model.append_child(LABEL_XML_PY);
877 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_py();
879 node_tmp = node_model.append_child(pugi::node_comment);
880 node_tmp.set_value(
"Principal point");
883 node_tmp = node_model.append_child(LABEL_XML_U0);
884 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_u0();
886 node_tmp = node_model.append_child(LABEL_XML_V0);
887 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_v0();
893 node_model = node_camera.append_child(LABEL_XML_MODEL);
895 node_tmp = node_model.append_child(pugi::node_comment);
896 node_tmp.set_value(
"Projection model type");
898 node_tmp = node_model.append_child(LABEL_XML_MODEL_TYPE);
899 node_tmp.append_child(pugi::node_pcdata).set_value(LABEL_XML_MODEL_WITH_DISTORTION);
901 node_tmp = node_model.append_child(pugi::node_comment);
902 node_tmp.set_value(
"Pixel ratio");
904 node_tmp = node_model.append_child(LABEL_XML_PX);
905 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_px();
907 node_tmp = node_model.append_child(LABEL_XML_PY);
908 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_py();
910 node_tmp = node_model.append_child(pugi::node_comment);
911 node_tmp.set_value(
"Principal point");
913 node_tmp = node_model.append_child(LABEL_XML_U0);
914 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_u0();
916 node_tmp = node_model.append_child(LABEL_XML_V0);
917 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_v0();
920 node_tmp = node_model.append_child(pugi::node_comment);
921 node_tmp.set_value(
"Undistorted to distorted distortion parameter");
922 node_tmp = node_model.append_child(LABEL_XML_KUD);
923 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_kud();
926 node_tmp = node_model.append_child(pugi::node_comment);
927 node_tmp.set_value(
"Distorted to undistorted distortion parameter");
928 node_tmp = node_model.append_child(LABEL_XML_KDU);
929 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_kdu();
935 node_model = node_camera.append_child(LABEL_XML_MODEL);
937 node_tmp = node_model.append_child(pugi::node_comment);
938 node_tmp.set_value(
"Projection model type");
940 node_tmp = node_model.append_child(LABEL_XML_MODEL_TYPE);
941 node_tmp.append_child(pugi::node_pcdata).set_value(LABEL_XML_MODEL_WITH_KANNALA_BRANDT_DISTORTION);
943 node_tmp = node_model.append_child(pugi::node_comment);
944 node_tmp.set_value(
"Pixel ratio");
946 node_tmp = node_model.append_child(LABEL_XML_PX);
947 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_px();
949 node_tmp = node_model.append_child(LABEL_XML_PY);
950 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_py();
952 node_tmp = node_model.append_child(pugi::node_comment);
953 node_tmp.set_value(
"Principal point");
955 node_tmp = node_model.append_child(LABEL_XML_U0);
956 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_u0();
958 node_tmp = node_model.append_child(LABEL_XML_V0);
959 node_tmp.append_child(pugi::node_pcdata).text() = camera.get_v0();
962 std::vector<double> distortion_coefs = camera.getKannalaBrandtDistortionCoefficients();
964 if (distortion_coefs.size() != 5)
965 std::cout <<
"Make sure to have 5 distortion coefficients for Kannala-Brandt distortions." << std::endl;
967 node_tmp = node_model.append_child(pugi::node_comment);
968 node_tmp.set_value(
"Distortion coefficients");
969 node_tmp = node_model.append_child(LABEL_XML_K1);
970 distortion_coefs.size() == 0 ? node_tmp.append_child(pugi::node_pcdata).text() = 0
971 : node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[0];
972 node_tmp = node_model.append_child(LABEL_XML_K2);
973 distortion_coefs.size() <= 1 ? node_tmp.append_child(pugi::node_pcdata).text() = 0
974 : node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[1];
975 node_tmp = node_model.append_child(LABEL_XML_K3);
976 distortion_coefs.size() <= 2 ? node_tmp.append_child(pugi::node_pcdata).text() = 0
977 : node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[2];
978 node_tmp = node_model.append_child(LABEL_XML_K4);
979 distortion_coefs.size() <= 3 ? node_tmp.append_child(pugi::node_pcdata).text() = 0
980 : node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[3];
981 node_tmp = node_model.append_child(LABEL_XML_K5);
982 distortion_coefs.size() <= 4 ? node_tmp.append_child(pugi::node_pcdata).text() = 0
983 : node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[4];
996 pugi::xml_node find_additional_info(
const pugi::xml_node &node_)
1000 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
1001 if (node.type() != pugi::node_element) {
1005 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
1006 prop = CODE_XML_OTHER;
1009 if (prop == CODE_XML_ADDITIONAL_INFO) {
1015 return pugi::xml_node();
1026 vpXmlCodeType val_int = CODE_XML_BAD;
1029 if (!strcmp(str, LABEL_XML_CAMERA)) {
1030 val_int = CODE_XML_CAMERA;
1032 else if (!strcmp(str, LABEL_XML_CAMERA_NAME)) {
1033 val_int = CODE_XML_CAMERA_NAME;
1035 else if (!strcmp(str, LABEL_XML_MODEL)) {
1036 val_int = CODE_XML_MODEL;
1038 else if (!strcmp(str, LABEL_XML_MODEL_TYPE)) {
1039 val_int = CODE_XML_MODEL_TYPE;
1041 else if (!strcmp(str, LABEL_XML_WIDTH)) {
1042 val_int = CODE_XML_WIDTH;
1044 else if (!strcmp(str, LABEL_XML_HEIGHT)) {
1045 val_int = CODE_XML_HEIGHT;
1047 else if (!strcmp(str, LABEL_XML_SUBSAMPLING_WIDTH)) {
1048 val_int = CODE_XML_SUBSAMPLING_WIDTH;
1050 else if (!strcmp(str, LABEL_XML_SUBSAMPLING_HEIGHT)) {
1051 val_int = CODE_XML_SUBSAMPLING_HEIGHT;
1053 else if (!strcmp(str, LABEL_XML_FULL_WIDTH)) {
1054 val_int = CODE_XML_FULL_WIDTH;
1056 else if (!strcmp(str, LABEL_XML_FULL_HEIGHT)) {
1057 val_int = CODE_XML_FULL_HEIGHT;
1059 else if (!strcmp(str, LABEL_XML_U0)) {
1060 val_int = CODE_XML_U0;
1062 else if (!strcmp(str, LABEL_XML_V0)) {
1063 val_int = CODE_XML_V0;
1065 else if (!strcmp(str, LABEL_XML_PX)) {
1066 val_int = CODE_XML_PX;
1068 else if (!strcmp(str, LABEL_XML_PY)) {
1069 val_int = CODE_XML_PY;
1071 else if (!strcmp(str, LABEL_XML_KUD)) {
1072 val_int = CODE_XML_KUD;
1074 else if (!strcmp(str, LABEL_XML_KDU)) {
1075 val_int = CODE_XML_KDU;
1077 else if (!strcmp(str, LABEL_XML_K1)) {
1078 val_int = CODE_XML_K1;
1080 else if (!strcmp(str, LABEL_XML_K2)) {
1081 val_int = CODE_XML_K2;
1083 else if (!strcmp(str, LABEL_XML_K3)) {
1084 val_int = CODE_XML_K3;
1086 else if (!strcmp(str, LABEL_XML_K4)) {
1087 val_int = CODE_XML_K4;
1089 else if (!strcmp(str, LABEL_XML_K5)) {
1090 val_int = CODE_XML_K5;
1092 else if (!strcmp(str, LABEL_XML_ADDITIONAL_INFO)) {
1093 val_int = CODE_XML_ADDITIONAL_INFO;
1096 val_int = CODE_XML_OTHER;
1105 unsigned int getHeight()
const {
return image_height; }
1108 unsigned int getWidth()
const {
return image_width; }
1110 void setCameraName(
const std::string &name) { camera_name = name; }
1111 void setHeight(
unsigned int height) { image_height = height; }
1114 void setWidth(
unsigned int width) { image_width = width; }
1118 std::string camera_name;
1119 unsigned int image_width;
1120 unsigned int image_height;
1121 unsigned int subsampling_width;
1122 unsigned int subsampling_height;
1123 unsigned int full_width;
1124 unsigned int full_height;
1128 static const int allowedPixelDiffOnImageSize = 15;
1153 unsigned int im_height,
bool verbose)
1155 return m_impl->parse(cam, filename, cam_name, projModel, im_width, im_height, verbose);
1203 unsigned int im_width,
unsigned int im_height,
const std::string &additionalInfo,
bool verbose)
1205 return m_impl->save(cam, filename, cam_name, im_width, im_height, additionalInfo, verbose);
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