Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
testMbtXmlGenericParser.cpp

Test vpMbtXmlGenericParser parse / save.

/*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact Inria about acquiring a ViSP Professional
* Edition License.
*
* See https://visp.inria.fr for more information.
*
* This software was developed at:
* Inria Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
*
* If you have questions regarding the use of this file, please contact
* Inria at visp@inria.fr
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
* Test vpMbtXmlGenericParser parse / save.
*/
#include <visp3/core/vpIoTools.h>
#include <visp3/mbt/vpMbtXmlGenericParser.h>
int main()
{
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
#if defined(VISP_HAVE_PUGIXML) && (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
std::string visp_images_dir = vpIoTools::getViSPImagesDataPath();
if (vpIoTools::checkDirectory(visp_images_dir + "/xml")) {
double eps = std::numeric_limits<double>::epsilon();
{
std::string filename = visp_images_dir + "/xml/chateau.xml";
std::cout << "Parse config: " << filename << std::endl;
xml.parse(filename);
vpMe me_ref;
me_ref.setMaskSize(5);
me_ref.setMaskNumber(180);
me_ref.setRange(8);
me_ref.setMu1(0.5);
me_ref.setMu2(0.5);
me_ref.setSampleStep(5);
vpMe me;
xml.getEdgeMe(me);
// Due to changes in visp-images/xml/chateau.xml where it can be now possible to have a normalized me threshold,
// two cases have to be considered depending on visp-images version
me_ref.setThreshold(5);
}
else {
me_ref.setThreshold(10000);
}
if (me.getMaskSize() != me_ref.getMaskSize() || me.getMaskNumber() != me_ref.getMaskNumber() ||
me.getRange() != me_ref.getRange() || !vpMath::equal(me.getThreshold(), me_ref.getThreshold(), eps) ||
!vpMath::equal(me.getMu1(), me_ref.getMu1(), eps) || !vpMath::equal(me.getMu2(), me_ref.getMu2(), eps) ||
!vpMath::equal(me.getSampleStep(), me_ref.getSampleStep(), eps)) {
std::cerr << "Issue when parsing xml: " << filename << " (ME)" << std::endl;
return EXIT_FAILURE;
}
if (xml.getKltMaskBorder() != 5 || xml.getKltMaxFeatures() != 10000 || xml.getKltWindowSize() != 5 ||
!vpMath::equal(xml.getKltQuality(), 0.01, eps) || !vpMath::equal(xml.getKltMinDistance(), 5.0, eps) ||
!vpMath::equal(xml.getKltHarrisParam(), 0.02, eps) || xml.getKltBlockSize() != 3 ||
xml.getKltPyramidLevels() != 3) {
std::cerr << "Issue when parsing xml: " << filename << " (KLT)" << std::endl;
return EXIT_FAILURE;
}
cam_ref.initPersProjWithoutDistortion(615.1674804688, 615.1675415039, 312.1889953613, 243.4373779297);
if (cam != cam_ref) {
std::cerr << "Issue when parsing xml: " << filename << " (cam)" << std::endl;
return EXIT_FAILURE;
}
if (!vpMath::equal(xml.getAngleAppear(), 70.0, eps) || !vpMath::equal(xml.getAngleDisappear(), 80.0, eps) ||
!vpMath::equal(xml.getNearClippingDistance(), 0.01, eps) ||
std::cerr << "Issue when parsing xml: " << filename << " (visibility)" << std::endl;
return EXIT_FAILURE;
}
}
{
std::string filename = visp_images_dir + "/xml/chateau.xml";
std::cout << "Parse config: " << filename << std::endl;
xml.parse(filename);
vpMe me_proj;
xml.getProjectionErrorMe(me_proj);
if (!vpMath::equal(me_proj.getSampleStep(), 12.0, eps) || xml.getProjectionErrorKernelSize() != 3) {
std::cerr << "Issue when parsing xml: " << filename << " (projection error)" << std::endl;
return EXIT_FAILURE;
}
}
{
std::string filename = visp_images_dir + "/xml/chateau_depth.xml";
std::cout << "Parse config: " << filename << std::endl;
xml.parse(filename);
std::cerr << "Issue when parsing xml: " << filename << " (depth normal)" << std::endl;
return EXIT_FAILURE;
}
std::cerr << "Issue when parsing xml: " << filename << " (depth dense)" << std::endl;
return EXIT_FAILURE;
}
cam_ref.initPersProjWithoutDistortion(476.0536193848, 476.0534973145, 311.4845581055, 246.2832336426);
if (cam != cam_ref) {
std::cerr << "Issue when parsing xml: " << filename << " (cam)" << std::endl;
return EXIT_FAILURE;
}
if (!vpMath::equal(xml.getAngleAppear(), 70.0, eps) || !vpMath::equal(xml.getAngleDisappear(), 80.0, eps) ||
!vpMath::equal(xml.getNearClippingDistance(), 0.01, eps) ||
std::cerr << "Issue when parsing xml: " << filename << " (visibility)" << std::endl;
return EXIT_FAILURE;
}
}
}
#elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
std::cout << "Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
#elif !(defined(VISP_HAVE_PUGIXML))
std::cout << "Cannot run this example: enable pugixml built-in" << std::endl;
#endif
std::cout << "Test succeed" << std::endl;
return EXIT_SUCCESS;
}
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
static std::string getViSPImagesDataPath()
Definition: vpIoTools.cpp:1053
static bool checkDirectory(const std::string &dirname)
Definition: vpIoTools.cpp:396
static bool equal(double x, double y, double threshold=0.001)
Definition: vpMath.h:459
Parse an Xml file to extract configuration parameters of a mbtConfig object.
int getDepthNormalPclPlaneEstimationRansacMaxIter() const
unsigned int getKltMaxFeatures() const
unsigned int getDepthNormalSamplingStepX() const
unsigned int getProjectionErrorKernelSize() const
unsigned int getKltBlockSize() const
void getCameraParameters(vpCameraParameters &cam) const
unsigned int getDepthNormalSamplingStepY() const
vpMbtFaceDepthNormal::vpFeatureEstimationType getDepthNormalFeatureEstimationMethod() const
void getEdgeMe(vpMe &ecm) const
unsigned int getKltMaskBorder() const
int getDepthNormalPclPlaneEstimationMethod() const
unsigned int getDepthDenseSamplingStepY() const
double getDepthNormalPclPlaneEstimationRansacThreshold() const
void parse(const std::string &filename)
void getProjectionErrorMe(vpMe &me) const
unsigned int getKltPyramidLevels() const
unsigned int getKltWindowSize() const
unsigned int getDepthDenseSamplingStepX() const
Definition: vpMe.h:134
void setMu1(const double &mu_1)
Definition: vpMe.h:385
vpLikelihoodThresholdType getLikelihoodThresholdType() const
Definition: vpMe.h:327
void setRange(const unsigned int &range)
Definition: vpMe.h:415
void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type)
Definition: vpMe.h:505
void setMaskNumber(const unsigned int &mask_number)
Definition: vpMe.cpp:552
void setThreshold(const double &threshold)
Definition: vpMe.h:466
double getMu1() const
Definition: vpMe.h:240
unsigned int getMaskNumber() const
Definition: vpMe.h:209
void setSampleStep(const double &sample_step)
Definition: vpMe.h:422
double getMu2() const
Definition: vpMe.h:247
double getThreshold() const
Definition: vpMe.h:291
unsigned int getMaskSize() const
Definition: vpMe.h:225
void setMaskSize(const unsigned int &mask_size)
Definition: vpMe.cpp:560
void setMu2(const double &mu_2)
Definition: vpMe.h:392
double getSampleStep() const
Definition: vpMe.h:275
unsigned int getRange() const
Definition: vpMe.h:268
@ NORMALIZED_THRESHOLD
Definition: vpMe.h:145
@ OLD_THRESHOLD
Old likelihood ratio threshold (to be avoided).
Definition: vpMe.h:142