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