Visual Servoing Platform version 3.5.0
testMbtXmlGenericParser.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2019 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 http://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/mbt/vpMbtXmlGenericParser.h>
43#include <visp3/core/vpIoTools.h>
44
45int main()
46{
47#if 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 xml.parse(filename);
55
56 vpMe me_ref;
57 me_ref.setMaskSize(5);
58 me_ref.setMaskNumber(180);
59 me_ref.setRange(8);
60 me_ref.setThreshold(10000);
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 if (me.getMaskSize() != me_ref.getMaskSize() ||
68 me.getMaskNumber() != me_ref.getMaskNumber() ||
69 me.getRange() != me_ref.getRange() ||
70 !vpMath::equal(me.getThreshold(), me_ref.getThreshold(), eps) ||
71 !vpMath::equal(me.getMu1(), me_ref.getMu1(), eps) ||
72 !vpMath::equal(me.getMu2(), me_ref.getMu2(), eps) ||
73 !vpMath::equal(me.getSampleStep(), me_ref.getSampleStep(), eps)) {
74 std::cerr << "Issue when parsing xml: " << filename << " (ME)" << std::endl;
75 return EXIT_FAILURE;
76 }
77
78 if (xml.getKltMaskBorder() != 5 ||
79 xml.getKltMaxFeatures() != 10000 ||
80 xml.getKltWindowSize() != 5 ||
81 !vpMath::equal(xml.getKltQuality(), 0.01, eps) ||
82 !vpMath::equal(xml.getKltMinDistance(), 5.0, eps) ||
83 !vpMath::equal(xml.getKltHarrisParam(), 0.02, eps) ||
84 xml.getKltBlockSize() != 3 ||
85 xml.getKltPyramidLevels() != 3) {
86 std::cerr << "Issue when parsing xml: " << filename << " (KLT)" << std::endl;
87 return EXIT_FAILURE;
88 }
89
90 vpCameraParameters cam_ref;
91 cam_ref.initPersProjWithoutDistortion(615.1674804688, 615.1675415039, 312.1889953613, 243.4373779297);
93 xml.getCameraParameters(cam);
94 if (cam != cam_ref) {
95 std::cerr << "Issue when parsing xml: " << filename << " (cam)" << std::endl;
96 return EXIT_FAILURE;
97 }
98
99 if (!vpMath::equal(xml.getAngleAppear(), 70.0, eps) ||
100 !vpMath::equal(xml.getAngleDisappear(), 80.0, eps) ||
101 !vpMath::equal(xml.getNearClippingDistance(), 0.01, eps) ||
102 !vpMath::equal(xml.getFarClippingDistance(), 2, eps) ||
103 !xml.getFovClipping()) {
104 std::cerr << "Issue when parsing xml: " << filename << " (visibility)" << std::endl;
105 return EXIT_FAILURE;
106 }
107 }
108
109 {
110 std::string filename = visp_images_dir + "/xml/chateau.xml";
112 xml.parse(filename);
113 vpMe me_proj;
114 xml.getProjectionErrorMe(me_proj);
115 if (!vpMath::equal(me_proj.getSampleStep(), 12.0, eps) ||
116 xml.getProjectionErrorKernelSize() != 3) {
117 std::cerr << "Issue when parsing xml: " << filename << " (projection error)" << std::endl;
118 return EXIT_FAILURE;
119 }
120 }
121
122 {
123 std::string filename = visp_images_dir + "/xml/chateau_depth.xml";
125 xml.parse(filename);
126
127 if (xml.getDepthNormalFeatureEstimationMethod() != 0 ||
128 xml.getDepthNormalPclPlaneEstimationMethod() != 2 ||
129 xml.getDepthNormalPclPlaneEstimationRansacMaxIter() != 200 ||
130 !vpMath::equal(xml.getDepthNormalPclPlaneEstimationRansacThreshold(), 0.001, eps) ||
131 xml.getDepthNormalSamplingStepX() != 2 ||
132 xml.getDepthNormalSamplingStepY() != 2) {
133 std::cerr << "Issue when parsing xml: " << filename << " (depth normal)" << std::endl;
134 return EXIT_FAILURE;
135 }
136
137 if (xml.getDepthDenseSamplingStepX() != 4 ||
138 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);
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) ||
153 !vpMath::equal(xml.getAngleDisappear(), 80.0, eps) ||
154 !vpMath::equal(xml.getNearClippingDistance(), 0.01, eps) ||
155 !vpMath::equal(xml.getFarClippingDistance(), 2, eps) ||
156 !xml.getFovClipping()) {
157 std::cerr << "Issue when parsing xml: " << filename << " (visibility)" << std::endl;
158 return EXIT_FAILURE;
159 }
160 }
161 }
162#elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
163 std::cout << "Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
164#endif
165
166 return EXIT_SUCCESS;
167}
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
static std::string getViSPImagesDataPath()
Definition: vpIoTools.cpp:1365
static bool checkDirectory(const std::string &dirname)
Definition: vpIoTools.cpp:420
static bool equal(double x, double y, double s=0.001)
Definition: vpMath.h:295
Parse an Xml file to extract configuration parameters of a mbtConfig object.
Definition: vpMe.h:61
void setMu1(const double &mu_1)
Definition: vpMe.h:241
void setSampleStep(const double &s)
Definition: vpMe.h:278
void setRange(const unsigned int &r)
Definition: vpMe.h:271
void setMaskSize(const unsigned int &a)
Definition: vpMe.cpp:459
double getMu1() const
Definition: vpMe.h:155
unsigned int getMaskNumber() const
Definition: vpMe.h:128
double getMu2() const
Definition: vpMe.h:161
double getThreshold() const
Definition: vpMe.h:193
unsigned int getMaskSize() const
Definition: vpMe.h:142
void setMu2(const double &mu_2)
Definition: vpMe.h:248
double getSampleStep() const
Definition: vpMe.h:285
unsigned int getRange() const
Definition: vpMe.h:179
void setMaskNumber(const unsigned int &a)
Definition: vpMe.cpp:452
void setThreshold(const double &t)
Definition: vpMe.h:300