Visual Servoing Platform  version 3.6.1 under development (2024-05-18)
testMbtXmlGenericParser.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Test vpMbtXmlGenericParser parse / save.
33  *
34 *****************************************************************************/
35 
42 #include <visp3/core/vpIoTools.h>
43 #include <visp3/mbt/vpMbtXmlGenericParser.h>
44 
45 int main()
46 {
47 #if defined(VISP_HAVE_PUGIXML) && (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
48  std::string visp_images_dir = vpIoTools::getViSPImagesDataPath();
49  if (vpIoTools::checkDirectory(visp_images_dir + "/xml")) {
50  double eps = std::numeric_limits<double>::epsilon();
51  {
52  std::string filename = visp_images_dir + "/xml/chateau.xml";
54  std::cout << "Parse config: " << filename << std::endl;
55  xml.parse(filename);
56 
57  vpMe me_ref;
58  me_ref.setMaskSize(5);
59  me_ref.setMaskNumber(180);
60  me_ref.setRange(8);
61  me_ref.setMu1(0.5);
62  me_ref.setMu2(0.5);
63  me_ref.setSampleStep(5);
64 
65  vpMe me;
66  xml.getEdgeMe(me);
67  // Due to changes in visp-images/xml/chateau.xml where it can be now possible to have a normalized me threshold,
68  // two cases have to be considered depending on visp-images version
71  me_ref.setThreshold(5);
72  }
73  else {
75  me_ref.setThreshold(10000);
76  }
77 
78  if (me.getMaskSize() != me_ref.getMaskSize() || me.getMaskNumber() != me_ref.getMaskNumber() ||
79  me.getRange() != me_ref.getRange() || !vpMath::equal(me.getThreshold(), me_ref.getThreshold(), eps) ||
80  !vpMath::equal(me.getMu1(), me_ref.getMu1(), eps) || !vpMath::equal(me.getMu2(), me_ref.getMu2(), eps) ||
81  !vpMath::equal(me.getSampleStep(), me_ref.getSampleStep(), eps)) {
82  std::cerr << "Issue when parsing xml: " << filename << " (ME)" << std::endl;
83  return EXIT_FAILURE;
84  }
85 
86  if (xml.getKltMaskBorder() != 5 || xml.getKltMaxFeatures() != 10000 || xml.getKltWindowSize() != 5 ||
87  !vpMath::equal(xml.getKltQuality(), 0.01, eps) || !vpMath::equal(xml.getKltMinDistance(), 5.0, eps) ||
88  !vpMath::equal(xml.getKltHarrisParam(), 0.02, eps) || xml.getKltBlockSize() != 3 ||
89  xml.getKltPyramidLevels() != 3) {
90  std::cerr << "Issue when parsing xml: " << filename << " (KLT)" << std::endl;
91  return EXIT_FAILURE;
92  }
93 
94  vpCameraParameters cam_ref;
95  cam_ref.initPersProjWithoutDistortion(615.1674804688, 615.1675415039, 312.1889953613, 243.4373779297);
97  xml.getCameraParameters(cam);
98  if (cam != cam_ref) {
99  std::cerr << "Issue when parsing xml: " << filename << " (cam)" << std::endl;
100  return EXIT_FAILURE;
101  }
102 
103  if (!vpMath::equal(xml.getAngleAppear(), 70.0, eps) || !vpMath::equal(xml.getAngleDisappear(), 80.0, eps) ||
104  !vpMath::equal(xml.getNearClippingDistance(), 0.01, eps) ||
105  !vpMath::equal(xml.getFarClippingDistance(), 2, eps) || !xml.getFovClipping()) {
106  std::cerr << "Issue when parsing xml: " << filename << " (visibility)" << std::endl;
107  return EXIT_FAILURE;
108  }
109  }
110 
111  {
112  std::string filename = visp_images_dir + "/xml/chateau.xml";
114  std::cout << "Parse config: " << filename << std::endl;
115  xml.parse(filename);
116  vpMe me_proj;
117  xml.getProjectionErrorMe(me_proj);
118  if (!vpMath::equal(me_proj.getSampleStep(), 12.0, eps) || xml.getProjectionErrorKernelSize() != 3) {
119  std::cerr << "Issue when parsing xml: " << filename << " (projection error)" << std::endl;
120  return EXIT_FAILURE;
121  }
122  }
123 
124  {
125  std::string filename = visp_images_dir + "/xml/chateau_depth.xml";
127  std::cout << "Parse config: " << filename << std::endl;
128  xml.parse(filename);
129 
130  if (xml.getDepthNormalFeatureEstimationMethod() != 0 || xml.getDepthNormalPclPlaneEstimationMethod() != 2 ||
131  xml.getDepthNormalPclPlaneEstimationRansacMaxIter() != 200 ||
132  !vpMath::equal(xml.getDepthNormalPclPlaneEstimationRansacThreshold(), 0.001, eps) ||
133  xml.getDepthNormalSamplingStepX() != 2 || xml.getDepthNormalSamplingStepY() != 2) {
134  std::cerr << "Issue when parsing xml: " << filename << " (depth normal)" << std::endl;
135  return EXIT_FAILURE;
136  }
137 
138  if (xml.getDepthDenseSamplingStepX() != 4 || xml.getDepthDenseSamplingStepY() != 4) {
139  std::cerr << "Issue when parsing xml: " << filename << " (depth dense)" << std::endl;
140  return EXIT_FAILURE;
141  }
142 
143  vpCameraParameters cam_ref;
144  cam_ref.initPersProjWithoutDistortion(476.0536193848, 476.0534973145, 311.4845581055, 246.2832336426);
145  vpCameraParameters cam;
146  xml.getCameraParameters(cam);
147  if (cam != cam_ref) {
148  std::cerr << "Issue when parsing xml: " << filename << " (cam)" << std::endl;
149  return EXIT_FAILURE;
150  }
151 
152  if (!vpMath::equal(xml.getAngleAppear(), 70.0, eps) || !vpMath::equal(xml.getAngleDisappear(), 80.0, eps) ||
153  !vpMath::equal(xml.getNearClippingDistance(), 0.01, eps) ||
154  !vpMath::equal(xml.getFarClippingDistance(), 2, eps) || !xml.getFovClipping()) {
155  std::cerr << "Issue when parsing xml: " << filename << " (visibility)" << std::endl;
156  return EXIT_FAILURE;
157  }
158  }
159  }
160 #elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
161  std::cout << "Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
162 #elif !(defined(VISP_HAVE_PUGIXML))
163  std::cout << "Cannot run this example: enable pugixml built-in" << std::endl;
164 #endif
165 
166  std::cout << "Test succeed" << std::endl;
167  return EXIT_SUCCESS;
168 }
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
static std::string getViSPImagesDataPath()
Definition: vpIoTools.cpp:1834
static bool checkDirectory(const std::string &dirname)
Definition: vpIoTools.cpp:834
static bool equal(double x, double y, double threshold=0.001)
Definition: vpMath.h:454
Parse an Xml file to extract configuration parameters of a mbtConfig object.
Definition: vpMe.h:124
void setMu1(const double &mu_1)
Definition: vpMe.h:399
vpLikelihoodThresholdType getLikelihoodThresholdType() const
Definition: vpMe.h:341
void setRange(const unsigned int &range)
Definition: vpMe.h:429
void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type)
Definition: vpMe.h:519
void setMaskNumber(const unsigned int &mask_number)
Definition: vpMe.cpp:488
void setThreshold(const double &threshold)
Definition: vpMe.h:480
double getMu1() const
Definition: vpMe.h:254
unsigned int getMaskNumber() const
Definition: vpMe.h:223
void setSampleStep(const double &sample_step)
Definition: vpMe.h:436
double getMu2() const
Definition: vpMe.h:261
double getThreshold() const
Definition: vpMe.h:305
unsigned int getMaskSize() const
Definition: vpMe.h:239
void setMaskSize(const unsigned int &mask_size)
Definition: vpMe.cpp:496
void setMu2(const double &mu_2)
Definition: vpMe.h:406
double getSampleStep() const
Definition: vpMe.h:289
unsigned int getRange() const
Definition: vpMe.h:282
@ NORMALIZED_THRESHOLD
Definition: vpMe.h:135
@ OLD_THRESHOLD
Old likelihood ratio threshold (to be avoided).
Definition: vpMe.h:132