43 #include <visp3/vision/vpXmlConfigParserKeyPoint.h>
46 #if defined(VISP_HAVE_PUGIXML)
47 #include <pugixml.hpp>
49 #include <visp3/core/vpException.h>
52 #ifndef DOXYGEN_SHOULD_SKIP_THIS
53 class vpXmlConfigParserKeyPoint::Impl
57 : m_detectorName(
"ORB"), m_extractorName(
"ORB"), m_matcherName(
"BruteForce-Hamming"),
59 m_nbRansacIterations(200), m_nbRansacMinInlierCount(100), m_ransacConsensusPercentage(20.0),
60 m_ransacReprojectionError(6.0), m_ransacThreshold(0.01), m_useRansacConsensusPercentage(false),
71 m_nodeMap[
"conf"] = conf;
72 m_nodeMap[
"detector"] = detector;
73 m_nodeMap[
"extractor"] = extractor;
74 m_nodeMap[
"matcher"] = matcher;
75 m_nodeMap[
"name"] = name;
76 m_nodeMap[
"matching_method"] = matching_method;
77 m_nodeMap[
"constantFactorDistanceThreshold"] = constant_factor_distance_threshold;
78 m_nodeMap[
"stdDistanceThreshold"] = std_distance_threshold;
79 m_nodeMap[
"ratioDistanceThreshold"] = ratio_distance_threshold;
80 m_nodeMap[
"stdAndRatioDistanceThreshold"] = std_and_ratio_distance_threshold;
81 m_nodeMap[
"noFilterMatching"] = no_filter_matching;
82 m_nodeMap[
"matchingFactorThreshold"] = matching_factor_threshold;
83 m_nodeMap[
"matchingRatioThreshold"] = matching_ratio_threshold;
84 m_nodeMap[
"ransac"] = ransac;
85 m_nodeMap[
"useRansacVVS"] = use_ransac_vvs;
86 m_nodeMap[
"useRansacConsensusPercentage"] = use_ransac_consensus_percentage;
87 m_nodeMap[
"nbRansacIterations"] = nb_ransac_iterations;
88 m_nodeMap[
"ransacReprojectionError"] = ransac_reprojection_error;
89 m_nodeMap[
"nbRansacMinInlierCount"] = nb_ransac_min_inlier_count;
90 m_nodeMap[
"ransacThreshold"] = ransac_threshold;
91 m_nodeMap[
"ransacConsensusPercentage"] = ransac_consensus_percentage;
94 void parse(
const std::string &filename)
96 pugi::xml_document doc;
97 if (!doc.load_file(filename.c_str())) {
101 bool detector_node =
false;
102 bool extractor_node =
false;
103 bool matcher_node =
false;
105 pugi::xml_node root_node = doc.document_element();
106 for (pugi::xml_node dataNode = root_node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
107 if (dataNode.type() == pugi::node_element) {
108 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
109 if (iter_data != m_nodeMap.end()) {
110 switch (iter_data->second) {
112 read_detector(dataNode);
113 detector_node =
true;
117 read_extractor(dataNode);
118 extractor_node =
true;
122 read_matcher(dataNode);
127 read_ransac(dataNode);
137 if (!detector_node) {
138 std::cout <<
"detector: name: " << m_detectorName <<
" (default)" << std::endl;
141 if (!extractor_node) {
142 std::cout <<
"extractor: name: " << m_extractorName <<
" (default)" << std::endl;
146 std::cout <<
"matcher: name: " << m_matcherName <<
" (default)" << std::endl;
155 void read_detector(
const pugi::xml_node &node)
157 bool detector_name_node =
false;
159 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
160 if (dataNode.type() == pugi::node_element) {
161 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
162 if (iter_data != m_nodeMap.end()) {
163 switch (iter_data->second) {
165 m_detectorName = dataNode.text().as_string();
166 detector_name_node =
true;
176 if (!detector_name_node)
177 std::cout <<
"detector : Name : " << m_detectorName <<
" (default)" << std::endl;
179 std::cout <<
"detector : Name : " << m_detectorName << std::endl;
187 void read_extractor(
const pugi::xml_node &node)
189 bool extractor_name_node =
false;
191 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
192 if (dataNode.type() == pugi::node_element) {
193 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
194 if (iter_data != m_nodeMap.end()) {
195 switch (iter_data->second) {
197 m_extractorName = dataNode.text().as_string();
198 extractor_name_node =
true;
208 if (!extractor_name_node)
209 std::cout <<
"extractor : Name : " << m_extractorName <<
" (default)" << std::endl;
211 std::cout <<
"extractor : Name : " << m_extractorName << std::endl;
219 void read_matcher(
const pugi::xml_node &node)
221 bool matcher_name_node =
false;
222 bool matching_method_node =
false;
223 std::string matchingMethodName =
"ratioDistanceThreshold";
224 bool matching_factor_threshold_node =
false;
225 bool matching_ratio_threshold_node =
false;
227 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
228 if (dataNode.type() == pugi::node_element) {
229 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
230 if (iter_data != m_nodeMap.end()) {
231 switch (iter_data->second) {
233 m_matcherName = dataNode.text().as_string();
234 matcher_name_node =
true;
237 case matching_method: {
238 matchingMethodName = dataNode.text().as_string();
240 std::map<std::string, int>::iterator iter_data2 = m_nodeMap.find(matchingMethodName);
241 if (iter_data2 != m_nodeMap.end()) {
242 matching_method_node =
true;
243 switch (iter_data2->second) {
244 case constant_factor_distance_threshold:
248 case std_distance_threshold:
252 case ratio_distance_threshold:
256 case std_and_ratio_distance_threshold:
260 case no_filter_matching:
265 matching_method_node =
false;
272 case matching_factor_threshold:
273 m_matchingFactorThreshold = dataNode.text().as_double();
274 matching_factor_threshold_node =
true;
277 case matching_ratio_threshold:
278 m_matchingRatioThreshold = dataNode.text().as_double();
279 matching_ratio_threshold_node =
true;
289 if (!matcher_name_node)
290 std::cout <<
"matcher : Name : " << m_matcherName <<
" (default)" << std::endl;
292 std::cout <<
"matcher : Name : " << m_matcherName << std::endl;
294 if (!matching_method_node)
295 std::cout <<
"matcher : Filter method : " << matchingMethodName <<
" (default)" << std::endl;
297 std::cout <<
"matcher : Filter method : " << matchingMethodName << std::endl;
299 if (!matching_factor_threshold_node)
300 std::cout <<
"matcher : matching factor threshold : " << m_matchingFactorThreshold <<
" (default)" << std::endl;
302 std::cout <<
"matcher : matching factor threshold : " << m_matchingFactorThreshold << std::endl;
304 if (!matching_ratio_threshold_node)
305 std::cout <<
"matcher : matching ratio threshold : " << m_matchingRatioThreshold <<
" (default)" << std::endl;
307 std::cout <<
"matcher : matching ratio threshold : " << m_matchingRatioThreshold << std::endl;
315 void read_ransac(
const pugi::xml_node &node)
317 bool use_ransac_vvs_node =
false;
318 bool use_ransac_consensus_percentage_node =
false;
319 bool nb_ransac_iterations_node =
false;
320 bool ransac_reprojection_error_node =
false;
321 bool nb_ransac_min_inlier_count_node =
false;
322 bool ransac_threshold_node =
false;
323 bool ransac_consensus_percentage_node =
false;
325 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
326 if (dataNode.type() == pugi::node_element) {
327 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
328 if (iter_data != m_nodeMap.end()) {
329 switch (iter_data->second) {
331 m_useRansacVVS = dataNode.text().as_int() != 0;
332 use_ransac_vvs_node =
true;
335 case use_ransac_consensus_percentage:
336 m_useRansacConsensusPercentage = dataNode.text().as_int() != 0;
337 use_ransac_consensus_percentage_node =
true;
340 case nb_ransac_iterations:
341 m_nbRansacIterations = dataNode.text().as_int();
342 nb_ransac_iterations_node =
true;
345 case ransac_reprojection_error:
346 m_ransacReprojectionError = dataNode.text().as_double();
347 ransac_reprojection_error_node =
true;
350 case nb_ransac_min_inlier_count:
351 m_nbRansacMinInlierCount = dataNode.text().as_int();
352 nb_ransac_min_inlier_count_node =
true;
355 case ransac_threshold:
356 m_ransacThreshold = dataNode.text().as_double();
357 ransac_threshold_node =
true;
360 case ransac_consensus_percentage:
361 m_ransacConsensusPercentage = dataNode.text().as_double();
362 ransac_consensus_percentage_node =
true;
372 if (!use_ransac_vvs_node)
373 std::cout <<
"ransac: use ransac vvs pose estimation: " << m_useRansacVVS <<
" (default)" << std::endl;
375 std::cout <<
"ransac: use ransac vvs pose estimation: " << m_useRansacVVS << std::endl;
377 if (!use_ransac_consensus_percentage_node)
378 std::cout <<
"ransac: use consensus percentage: " << m_useRansacConsensusPercentage <<
" (default)" << std::endl;
380 std::cout <<
"ransac: use consensus percentage: " << m_useRansacConsensusPercentage << std::endl;
382 if (!nb_ransac_iterations_node)
383 std::cout <<
"ransac: nb ransac iterations: " << m_nbRansacIterations <<
" (default)" << std::endl;
385 std::cout <<
"ransac: nb ransac iterations: " << m_nbRansacIterations << std::endl;
387 if (!ransac_reprojection_error_node)
388 std::cout <<
"ransac: ransac reprojection error in pixel (for OpenCV "
390 << m_ransacReprojectionError <<
" (default)" << std::endl;
392 std::cout <<
"ransac: ransac reprojection error in pixel (for OpenCV "
394 << m_ransacReprojectionError << std::endl;
396 if (!nb_ransac_min_inlier_count_node)
397 std::cout <<
"ransac: nb ransac min inlier count: " << m_nbRansacMinInlierCount <<
" (default)" << std::endl;
399 std::cout <<
"ransac: nb ransac min inlier count: " << m_nbRansacMinInlierCount << std::endl;
401 if (!ransac_threshold_node)
402 std::cout <<
"ransac: ransac threshold in meter (for ViSP function): " << m_ransacThreshold <<
" (default)"
405 std::cout <<
"ransac: ransac threshold in meter (for ViSP function): " << m_ransacThreshold << std::endl;
407 if (!ransac_consensus_percentage_node)
408 std::cout <<
"ransac: consensus percentage: " << m_ransacConsensusPercentage <<
" (default)" << std::endl;
410 std::cout <<
"ransac: consensus percentage: " << m_ransacConsensusPercentage << std::endl;
431 enum vpNodeIdentifier
439 constant_factor_distance_threshold,
442 std_distance_threshold,
444 ratio_distance_threshold,
446 std_and_ratio_distance_threshold,
451 matching_factor_threshold,
453 matching_ratio_threshold,
457 use_ransac_consensus_percentage,
460 nb_ransac_iterations,
462 ransac_reprojection_error,
464 nb_ransac_min_inlier_count,
468 ransac_consensus_percentage
473 std::string m_detectorName;
475 std::string m_extractorName;
477 std::string m_matcherName;
479 double m_matchingFactorThreshold;
483 double m_matchingRatioThreshold;
485 int m_nbRansacIterations;
487 int m_nbRansacMinInlierCount;
489 double m_ransacConsensusPercentage;
492 double m_ransacReprojectionError;
495 double m_ransacThreshold;
499 bool m_useRansacConsensusPercentage;
503 std::map<std::string, int> m_nodeMap;
523 return m_impl->getMatchingMethod();
534 return m_impl->getRansacConsensusPercentage();
543 return m_impl->getUseRansacConsensusPercentage();
548 return m_impl->getUseRansacVVSPoseEstimation();
551 #elif !defined(VISP_BUILD_SHARED_LIBS)
553 void dummy_vpXmlConfigParserKeyPoint() { };
error that can be emitted by ViSP classes.
std::string getDetectorName() const
~vpXmlConfigParserKeyPoint()
double getMatchingRatioThreshold() const
std::string getExtractorName() const
void parse(const std::string &filename)
double getRansacReprojectionError() const
bool getUseRansacVVSPoseEstimation() const
double getMatchingFactorThreshold() const
int getNbRansacMinInlierCount() const
bool getUseRansacConsensusPercentage() const
std::string getMatcherName() const
vpXmlConfigParserKeyPoint()
int getNbRansacIterations() const
double getRansacConsensusPercentage() const
@ stdAndRatioDistanceThreshold
@ constantFactorDistanceThreshold
vpMatchingMethodEnum getMatchingMethod() const
double getRansacThreshold() const