Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
vpXmlConfigParserKeyPoint.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  * XML parser to load configuration for vpKeyPoint class.
33  *
34  * Authors:
35  * Souriya Trinh
36  *
37  *****************************************************************************/
38 
47 #include <iostream>
48 
49 #include <visp3/vision/vpXmlConfigParserKeyPoint.h>
50 
51 #ifdef VISP_HAVE_XML2
52 
54  : m_detectorName("ORB"), m_extractorName("ORB"), m_matcherName("BruteForce-Hamming"), m_matchingFactorThreshold(2.0),
55  m_matchingMethod(ratioDistanceThreshold), m_matchingRatioThreshold(0.85), m_nbRansacIterations(200),
56  m_nbRansacMinInlierCount(100), m_ransacConsensusPercentage(20.0), m_ransacReprojectionError(6.0),
57  m_ransacThreshold(0.01), m_useRansacConsensusPercentage(false), m_useRansacVVS(true)
58 {
59  init();
60 }
61 
65 void vpXmlConfigParserKeyPoint::init()
66 {
67  setMainTag("conf");
68 
69  nodeMap["conf"] = conf;
70  nodeMap["detector"] = detector;
71  nodeMap["extractor"] = extractor;
72  nodeMap["matcher"] = matcher;
73  nodeMap["name"] = name;
74  nodeMap["matching_method"] = matching_method;
75  nodeMap["constantFactorDistanceThreshold"] = constant_factor_distance_threshold;
76  nodeMap["stdDistanceThreshold"] = std_distance_threshold;
77  nodeMap["ratioDistanceThreshold"] = ratio_distance_threshold;
78  nodeMap["stdAndRatioDistanceThreshold"] = std_and_ratio_distance_threshold;
79  nodeMap["noFilterMatching"] = no_filter_matching;
80  nodeMap["matchingFactorThreshold"] = matching_factor_threshold;
81  nodeMap["matchingRatioThreshold"] = matching_ratio_threshold;
82  nodeMap["ransac"] = ransac;
83  nodeMap["useRansacVVS"] = use_ransac_vvs;
84  nodeMap["useRansacConsensusPercentage"] = use_ransac_consensus_percentage;
85  nodeMap["nbRansacIterations"] = nb_ransac_iterations;
86  nodeMap["ransacReprojectionError"] = ransac_reprojection_error;
87  nodeMap["nbRansacMinInlierCount"] = nb_ransac_min_inlier_count;
88  nodeMap["ransacThreshold"] = ransac_threshold;
89  nodeMap["ransacConsensusPercentage"] = ransac_consensus_percentage;
90 }
91 
96 void vpXmlConfigParserKeyPoint::parse(const std::string &filename) { vpXmlParser::parse(filename); }
97 
105 void vpXmlConfigParserKeyPoint::readMainClass(xmlDocPtr doc, xmlNodePtr node)
106 {
107  bool detector_node = false;
108  bool extractor_node = false;
109  bool matcher_node = false;
110 
111  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
112  if (dataNode->type == XML_ELEMENT_NODE) {
113  std::map<std::string, int>::iterator iter_data = this->nodeMap.find((char *)dataNode->name);
114  if (iter_data != nodeMap.end()) {
115  switch (iter_data->second) {
116  case detector:
117  this->read_detector(doc, dataNode);
118  detector_node = true;
119  break;
120 
121  case extractor:
122  this->read_extractor(doc, dataNode);
123  extractor_node = true;
124  break;
125 
126  case matcher:
127  this->read_matcher(doc, dataNode);
128  matcher_node = true;
129  break;
130 
131  case ransac:
132  this->read_ransac(doc, dataNode);
133  break;
134 
135  default:
136  break;
137  }
138  }
139  }
140  }
141 
142  if (!detector_node) {
143  std::cout << "detector: name: " << m_detectorName << " (default)" << std::endl;
144  }
145 
146  if (!extractor_node) {
147  std::cout << "extractor: name: " << m_extractorName << " (default)" << std::endl;
148  }
149 
150  if (!matcher_node) {
151  std::cout << "matcher: name: " << m_matcherName << " (default)" << std::endl;
152  }
153 }
154 
161 void vpXmlConfigParserKeyPoint::read_detector(xmlDocPtr doc, xmlNodePtr node)
162 {
163  bool detector_name_node = false;
164 
165  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
166  if (dataNode->type == XML_ELEMENT_NODE) {
167  std::map<std::string, int>::iterator iter_data = this->nodeMap.find((char *)dataNode->name);
168  if (iter_data != nodeMap.end()) {
169  switch (iter_data->second) {
170  case name:
171  m_detectorName = xmlReadStringChild(doc, dataNode);
172  detector_name_node = true;
173  break;
174 
175  default:
176  break;
177  }
178  }
179  }
180  }
181 
182  if (!detector_name_node)
183  std::cout << "detector : Name : " << m_detectorName << " (default)" << std::endl;
184  else
185  std::cout << "detector : Name : " << m_detectorName << std::endl;
186 }
187 
194 void vpXmlConfigParserKeyPoint::read_extractor(xmlDocPtr doc, xmlNodePtr node)
195 {
196  bool extractor_name_node = false;
197 
198  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
199  if (dataNode->type == XML_ELEMENT_NODE) {
200  std::map<std::string, int>::iterator iter_data = this->nodeMap.find((char *)dataNode->name);
201  if (iter_data != nodeMap.end()) {
202  switch (iter_data->second) {
203  case name:
204  m_extractorName = xmlReadStringChild(doc, dataNode);
205  extractor_name_node = true;
206  break;
207 
208  default:
209  break;
210  }
211  }
212  }
213  }
214 
215  if (!extractor_name_node)
216  std::cout << "extractor : Name : " << m_extractorName << " (default)" << std::endl;
217  else
218  std::cout << "extractor : Name : " << m_extractorName << std::endl;
219 }
220 
227 void vpXmlConfigParserKeyPoint::read_matcher(xmlDocPtr doc, xmlNodePtr node)
228 {
229  bool matcher_name_node = false;
230  bool matching_method_node = false;
231  std::string matchingMethodName = "ratioDistanceThreshold";
232  bool matching_factor_threshold_node = false;
233  bool matching_ratio_threshold_node = false;
234 
235  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
236  if (dataNode->type == XML_ELEMENT_NODE) {
237  std::map<std::string, int>::iterator iter_data = this->nodeMap.find((char *)dataNode->name);
238  if (iter_data != nodeMap.end()) {
239  switch (iter_data->second) {
240  case name:
241  m_matcherName = xmlReadStringChild(doc, dataNode);
242  matcher_name_node = true;
243  break;
244 
245  case matching_method: {
246  matchingMethodName = xmlReadStringChild(doc, dataNode);
247 
248  std::map<std::string, int>::iterator iter_data2 = nodeMap.find(matchingMethodName);
249  if (iter_data2 != nodeMap.end()) {
250  matching_method_node = true;
251  switch (iter_data2->second) {
253  m_matchingMethod = constantFactorDistanceThreshold;
254  break;
255 
257  m_matchingMethod = stdDistanceThreshold;
258  break;
259 
261  m_matchingMethod = ratioDistanceThreshold;
262  break;
263 
265  m_matchingMethod = stdAndRatioDistanceThreshold;
266  break;
267 
268  case no_filter_matching:
269  m_matchingMethod = noFilterMatching;
270  break;
271 
272  default:
273  matching_method_node = false;
274  break;
275  }
276  }
277  break;
278  }
279 
281  m_matchingFactorThreshold = xmlReadDoubleChild(doc, dataNode);
282  matching_factor_threshold_node = true;
283  break;
284 
286  m_matchingRatioThreshold = xmlReadDoubleChild(doc, dataNode);
287  matching_ratio_threshold_node = true;
288  break;
289 
290  default:
291  break;
292  }
293  }
294  }
295  }
296 
297  if (!matcher_name_node)
298  std::cout << "matcher : Name : " << m_matcherName << " (default)" << std::endl;
299  else
300  std::cout << "matcher : Name : " << m_matcherName << std::endl;
301 
302  if (!matching_method_node)
303  std::cout << "matcher : Filter method : " << matchingMethodName << " (default)" << std::endl;
304  else
305  std::cout << "matcher : Filter method : " << matchingMethodName << std::endl;
306 
307  if (!matching_factor_threshold_node)
308  std::cout << "matcher : matching factor threshold : " << m_matchingFactorThreshold << " (default)" << std::endl;
309  else
310  std::cout << "matcher : matching factor threshold : " << m_matchingFactorThreshold << std::endl;
311 
312  if (!matching_ratio_threshold_node)
313  std::cout << "matcher : matching ratio threshold : " << m_matchingRatioThreshold << " (default)" << std::endl;
314  else
315  std::cout << "matcher : matching ratio threshold : " << m_matchingRatioThreshold << std::endl;
316 }
317 
324 void vpXmlConfigParserKeyPoint::read_ransac(xmlDocPtr doc, xmlNodePtr node)
325 {
326  bool use_ransac_vvs_node = false;
327  bool use_ransac_consensus_percentage_node = false;
328  bool nb_ransac_iterations_node = false;
329  bool ransac_reprojection_error_node = false;
330  bool nb_ransac_min_inlier_count_node = false;
331  bool ransac_threshold_node = false;
332  bool ransac_consensus_percentage_node = false;
333 
334  for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
335  if (dataNode->type == XML_ELEMENT_NODE) {
336  std::map<std::string, int>::iterator iter_data = this->nodeMap.find((char *)dataNode->name);
337  if (iter_data != nodeMap.end()) {
338  switch (iter_data->second) {
339  case use_ransac_vvs:
340  m_useRansacVVS = xmlReadIntChild(doc, dataNode) != 0;
341  use_ransac_vvs_node = true;
342  break;
343 
345  m_useRansacConsensusPercentage = xmlReadIntChild(doc, dataNode) != 0;
346  use_ransac_consensus_percentage_node = true;
347  break;
348 
350  m_nbRansacIterations = xmlReadIntChild(doc, dataNode);
351  nb_ransac_iterations_node = true;
352  break;
353 
355  m_ransacReprojectionError = xmlReadDoubleChild(doc, dataNode);
356  ransac_reprojection_error_node = true;
357  break;
358 
360  m_nbRansacMinInlierCount = xmlReadIntChild(doc, dataNode);
361  nb_ransac_min_inlier_count_node = true;
362  break;
363 
364  case ransac_threshold:
365  m_ransacThreshold = xmlReadDoubleChild(doc, dataNode);
366  ransac_threshold_node = true;
367  break;
368 
370  m_ransacConsensusPercentage = xmlReadDoubleChild(doc, dataNode);
371  ransac_consensus_percentage_node = true;
372  break;
373 
374  default:
375  break;
376  }
377  }
378  }
379  }
380 
381  if (!use_ransac_vvs_node)
382  std::cout << "ransac: use ransac vvs pose estimation: " << m_useRansacVVS << " (default)" << std::endl;
383  else
384  std::cout << "ransac: use ransac vvs pose estimation: " << m_useRansacVVS << std::endl;
385 
386  if (!use_ransac_consensus_percentage_node)
387  std::cout << "ransac: use consensus percentage: " << m_useRansacConsensusPercentage << " (default)" << std::endl;
388  else
389  std::cout << "ransac: use consensus percentage: " << m_useRansacConsensusPercentage << std::endl;
390 
391  if (!nb_ransac_iterations_node)
392  std::cout << "ransac: nb ransac iterations: " << m_nbRansacIterations << " (default)" << std::endl;
393  else
394  std::cout << "ransac: nb ransac iterations: " << m_nbRansacIterations << std::endl;
395 
396  if (!ransac_reprojection_error_node)
397  std::cout << "ransac: ransac reprojection error in pixel (for OpenCV "
398  "function): "
399  << m_ransacReprojectionError << " (default)" << std::endl;
400  else
401  std::cout << "ransac: ransac reprojection error in pixel (for OpenCV "
402  "function): "
403  << m_ransacReprojectionError << std::endl;
404 
405  if (!nb_ransac_min_inlier_count_node)
406  std::cout << "ransac: nb ransac min inlier count: " << m_nbRansacMinInlierCount << " (default)" << std::endl;
407  else
408  std::cout << "ransac: nb ransac min inlier count: " << m_nbRansacMinInlierCount << std::endl;
409 
410  if (!ransac_threshold_node)
411  std::cout << "ransac: ransac threshold in meter (for ViSP function): " << m_ransacThreshold << " (default)"
412  << std::endl;
413  else
414  std::cout << "ransac: ransac threshold in meter (for ViSP function): " << m_ransacThreshold << std::endl;
415 
416  if (!ransac_consensus_percentage_node)
417  std::cout << "ransac: consensus percentage: " << m_ransacConsensusPercentage << " (default)" << std::endl;
418  else
419  std::cout << "ransac: consensus percentage: " << m_ransacConsensusPercentage << std::endl;
420 }
421 
422 #elif !defined(VISP_BUILD_SHARED_LIBS)
423 // Work arround to avoid warning:
424 // libvisp_vision.a(vpXmlConfigParserKeyPoint.cpp.o) has no symbols
425 void dummy_vpXmlConfigParserKeyPoint(){};
426 #endif // VISP_HAVE_XML2
void setMainTag(const std::string &tag)
Definition: vpXmlParser.h:295
double xmlReadDoubleChild(xmlDocPtr doc, xmlNodePtr node)
int xmlReadIntChild(xmlDocPtr doc, xmlNodePtr node)
std::string xmlReadStringChild(xmlDocPtr doc, xmlNodePtr node)
std::map< std::string, int > nodeMap
Definition: vpXmlParser.h:226
void parse(const std::string &filename)
void parse(const std::string &filename)