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