48 #include <visp3/vision/vpXmlConfigParserKeyPoint.h> 50 #ifdef VISP_HAVE_PUGIXML 53 #include <pugixml.hpp> 55 #include <visp3/core/vpException.h> 57 #ifndef DOXYGEN_SHOULD_SKIP_THIS 58 class vpXmlConfigParserKeyPoint::Impl
62 m_detectorName(
"ORB"), m_extractorName(
"ORB"), m_matcherName(
"BruteForce-Hamming"), m_matchingFactorThreshold(2.0),
64 m_nbRansacMinInlierCount(100), m_ransacConsensusPercentage(20.0), m_ransacReprojectionError(6.0),
65 m_ransacThreshold(0.01), m_useRansacConsensusPercentage(false), m_useRansacVVS(true)
75 m_nodeMap[
"conf"] = conf;
76 m_nodeMap[
"detector"] = detector;
77 m_nodeMap[
"extractor"] = extractor;
78 m_nodeMap[
"matcher"] = matcher;
79 m_nodeMap[
"name"] = name;
80 m_nodeMap[
"matching_method"] = matching_method;
81 m_nodeMap[
"constantFactorDistanceThreshold"] = constant_factor_distance_threshold;
82 m_nodeMap[
"stdDistanceThreshold"] = std_distance_threshold;
83 m_nodeMap[
"ratioDistanceThreshold"] = ratio_distance_threshold;
84 m_nodeMap[
"stdAndRatioDistanceThreshold"] = std_and_ratio_distance_threshold;
85 m_nodeMap[
"noFilterMatching"] = no_filter_matching;
86 m_nodeMap[
"matchingFactorThreshold"] = matching_factor_threshold;
87 m_nodeMap[
"matchingRatioThreshold"] = matching_ratio_threshold;
88 m_nodeMap[
"ransac"] = ransac;
89 m_nodeMap[
"useRansacVVS"] = use_ransac_vvs;
90 m_nodeMap[
"useRansacConsensusPercentage"] = use_ransac_consensus_percentage;
91 m_nodeMap[
"nbRansacIterations"] = nb_ransac_iterations;
92 m_nodeMap[
"ransacReprojectionError"] = ransac_reprojection_error;
93 m_nodeMap[
"nbRansacMinInlierCount"] = nb_ransac_min_inlier_count;
94 m_nodeMap[
"ransacThreshold"] = ransac_threshold;
95 m_nodeMap[
"ransacConsensusPercentage"] = ransac_consensus_percentage;
98 void parse(
const std::string &filename)
100 pugi::xml_document doc;
101 if (!doc.load_file(filename.c_str())) {
105 bool detector_node =
false;
106 bool extractor_node =
false;
107 bool matcher_node =
false;
109 pugi::xml_node root_node = doc.document_element();
110 for (pugi::xml_node dataNode = root_node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
111 if (dataNode.type() == pugi::node_element) {
112 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
113 if (iter_data != m_nodeMap.end()) {
114 switch (iter_data->second) {
116 read_detector(dataNode);
117 detector_node =
true;
121 read_extractor(dataNode);
122 extractor_node =
true;
126 read_matcher(dataNode);
131 read_ransac(dataNode);
141 if (!detector_node) {
142 std::cout <<
"detector: name: " << m_detectorName <<
" (default)" << std::endl;
145 if (!extractor_node) {
146 std::cout <<
"extractor: name: " << m_extractorName <<
" (default)" << std::endl;
150 std::cout <<
"matcher: name: " << m_matcherName <<
" (default)" << std::endl;
159 void read_detector(
const pugi::xml_node &node)
161 bool detector_name_node =
false;
163 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
164 if (dataNode.type() == pugi::node_element) {
165 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
166 if (iter_data != m_nodeMap.end()) {
167 switch (iter_data->second) {
169 m_detectorName = dataNode.text().as_string();
170 detector_name_node =
true;
180 if (!detector_name_node)
181 std::cout <<
"detector : Name : " << m_detectorName <<
" (default)" << std::endl;
183 std::cout <<
"detector : Name : " << m_detectorName << std::endl;
191 void read_extractor(
const pugi::xml_node &node)
193 bool extractor_name_node =
false;
195 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
196 if (dataNode.type() == pugi::node_element) {
197 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
198 if (iter_data != m_nodeMap.end()) {
199 switch (iter_data->second) {
201 m_extractorName = dataNode.text().as_string();
202 extractor_name_node =
true;
212 if (!extractor_name_node)
213 std::cout <<
"extractor : Name : " << m_extractorName <<
" (default)" << std::endl;
215 std::cout <<
"extractor : Name : " << m_extractorName << std::endl;
223 void read_matcher(
const pugi::xml_node &node)
225 bool matcher_name_node =
false;
226 bool matching_method_node =
false;
227 std::string matchingMethodName =
"ratioDistanceThreshold";
228 bool matching_factor_threshold_node =
false;
229 bool matching_ratio_threshold_node =
false;
231 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
232 if (dataNode.type() == pugi::node_element) {
233 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
234 if (iter_data != m_nodeMap.end()) {
235 switch (iter_data->second) {
237 m_matcherName = dataNode.text().as_string();
238 matcher_name_node =
true;
241 case matching_method: {
242 matchingMethodName = dataNode.text().as_string();
244 std::map<std::string, int>::iterator iter_data2 = m_nodeMap.find(matchingMethodName);
245 if (iter_data2 != m_nodeMap.end()) {
246 matching_method_node =
true;
247 switch (iter_data2->second) {
248 case constant_factor_distance_threshold:
252 case std_distance_threshold:
256 case ratio_distance_threshold:
260 case std_and_ratio_distance_threshold:
264 case no_filter_matching:
269 matching_method_node =
false;
276 case matching_factor_threshold:
277 m_matchingFactorThreshold = dataNode.text().as_double();
278 matching_factor_threshold_node =
true;
281 case matching_ratio_threshold:
282 m_matchingRatioThreshold = dataNode.text().as_double();
283 matching_ratio_threshold_node =
true;
293 if (!matcher_name_node)
294 std::cout <<
"matcher : Name : " << m_matcherName <<
" (default)" << std::endl;
296 std::cout <<
"matcher : Name : " << m_matcherName << std::endl;
298 if (!matching_method_node)
299 std::cout <<
"matcher : Filter method : " << matchingMethodName <<
" (default)" << std::endl;
301 std::cout <<
"matcher : Filter method : " << matchingMethodName << std::endl;
303 if (!matching_factor_threshold_node)
304 std::cout <<
"matcher : matching factor threshold : " << m_matchingFactorThreshold <<
" (default)" << std::endl;
306 std::cout <<
"matcher : matching factor threshold : " << m_matchingFactorThreshold << std::endl;
308 if (!matching_ratio_threshold_node)
309 std::cout <<
"matcher : matching ratio threshold : " << m_matchingRatioThreshold <<
" (default)" << std::endl;
311 std::cout <<
"matcher : matching ratio threshold : " << m_matchingRatioThreshold << std::endl;
319 void read_ransac(
const pugi::xml_node &node)
321 bool use_ransac_vvs_node =
false;
322 bool use_ransac_consensus_percentage_node =
false;
323 bool nb_ransac_iterations_node =
false;
324 bool ransac_reprojection_error_node =
false;
325 bool nb_ransac_min_inlier_count_node =
false;
326 bool ransac_threshold_node =
false;
327 bool ransac_consensus_percentage_node =
false;
329 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
330 if (dataNode.type() == pugi::node_element) {
331 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
332 if (iter_data != m_nodeMap.end()) {
333 switch (iter_data->second) {
335 m_useRansacVVS = dataNode.text().as_int() != 0;
336 use_ransac_vvs_node =
true;
339 case use_ransac_consensus_percentage:
340 m_useRansacConsensusPercentage = dataNode.text().as_int() != 0;
341 use_ransac_consensus_percentage_node =
true;
344 case nb_ransac_iterations:
345 m_nbRansacIterations = dataNode.text().as_int();
346 nb_ransac_iterations_node =
true;
349 case ransac_reprojection_error:
350 m_ransacReprojectionError = dataNode.text().as_double();
351 ransac_reprojection_error_node =
true;
354 case nb_ransac_min_inlier_count:
355 m_nbRansacMinInlierCount = dataNode.text().as_int();
356 nb_ransac_min_inlier_count_node =
true;
359 case ransac_threshold:
360 m_ransacThreshold = dataNode.text().as_double();
361 ransac_threshold_node =
true;
364 case ransac_consensus_percentage:
365 m_ransacConsensusPercentage = dataNode.text().as_double();
366 ransac_consensus_percentage_node =
true;
376 if (!use_ransac_vvs_node)
377 std::cout <<
"ransac: use ransac vvs pose estimation: " << m_useRansacVVS <<
" (default)" << std::endl;
379 std::cout <<
"ransac: use ransac vvs pose estimation: " << m_useRansacVVS << std::endl;
381 if (!use_ransac_consensus_percentage_node)
382 std::cout <<
"ransac: use consensus percentage: " << m_useRansacConsensusPercentage <<
" (default)" << std::endl;
384 std::cout <<
"ransac: use consensus percentage: " << m_useRansacConsensusPercentage << std::endl;
386 if (!nb_ransac_iterations_node)
387 std::cout <<
"ransac: nb ransac iterations: " << m_nbRansacIterations <<
" (default)" << std::endl;
389 std::cout <<
"ransac: nb ransac iterations: " << m_nbRansacIterations << std::endl;
391 if (!ransac_reprojection_error_node)
392 std::cout <<
"ransac: ransac reprojection error in pixel (for OpenCV " 394 << m_ransacReprojectionError <<
" (default)" << std::endl;
396 std::cout <<
"ransac: ransac reprojection error in pixel (for OpenCV " 398 << m_ransacReprojectionError << std::endl;
400 if (!nb_ransac_min_inlier_count_node)
401 std::cout <<
"ransac: nb ransac min inlier count: " << m_nbRansacMinInlierCount <<
" (default)" << std::endl;
403 std::cout <<
"ransac: nb ransac min inlier count: " << m_nbRansacMinInlierCount << std::endl;
405 if (!ransac_threshold_node)
406 std::cout <<
"ransac: ransac threshold in meter (for ViSP function): " << m_ransacThreshold <<
" (default)" 409 std::cout <<
"ransac: ransac threshold in meter (for ViSP function): " << m_ransacThreshold << std::endl;
411 if (!ransac_consensus_percentage_node)
412 std::cout <<
"ransac: consensus percentage: " << m_ransacConsensusPercentage <<
" (default)" << std::endl;
414 std::cout <<
"ransac: consensus percentage: " << m_ransacConsensusPercentage << std::endl;
435 enum vpNodeIdentifier {
442 constant_factor_distance_threshold,
445 std_distance_threshold,
447 ratio_distance_threshold,
449 std_and_ratio_distance_threshold,
454 matching_factor_threshold,
456 matching_ratio_threshold,
460 use_ransac_consensus_percentage,
463 nb_ransac_iterations,
465 ransac_reprojection_error,
467 nb_ransac_min_inlier_count,
471 ransac_consensus_percentage
476 std::string m_detectorName;
478 std::string m_extractorName;
480 std::string m_matcherName;
482 double m_matchingFactorThreshold;
486 double m_matchingRatioThreshold;
488 int m_nbRansacIterations;
490 int m_nbRansacMinInlierCount;
492 double m_ransacConsensusPercentage;
495 double m_ransacReprojectionError;
498 double m_ransacThreshold;
502 bool m_useRansacConsensusPercentage;
506 std::map<std::string, int> m_nodeMap;
508 #endif // DOXYGEN_SHOULD_SKIP_THIS 525 m_impl->parse(filename);
535 return m_impl->getDetectorName();
545 return m_impl->getExtractorName();
555 return m_impl->getMatcherName();
566 return m_impl->getMatchingFactorThreshold();
576 return m_impl->getMatchingMethod();
586 return m_impl->getMatchingRatioThreshold();
596 return m_impl->getNbRansacIterations();
606 return m_impl->getNbRansacMinInlierCount();
616 return m_impl->getRansacConsensusPercentage();
627 return m_impl->getRansacReprojectionError();
637 return m_impl->getRansacThreshold();
648 return m_impl->getUseRansacConsensusPercentage();
659 return m_impl->getUseRansacVVSPoseEstimation();
662 #elif !defined(VISP_BUILD_SHARED_LIBS) 665 void dummy_vpXmlConfigParserKeyPoint(){};
666 #endif //VISP_HAVE_PUGIXML
double getMatchingRatioThreshold() const
int getNbRansacMinInlierCount() const
double getRansacConsensusPercentage() const
vpMatchingMethodEnum getMatchingMethod() const
error that can be emited by ViSP classes.
~vpXmlConfigParserKeyPoint()
std::string getMatcherName() const
double getRansacThreshold() const
std::string getDetectorName() const
vpXmlConfigParserKeyPoint()
std::string getExtractorName() const
double getRansacReprojectionError() const
int getNbRansacIterations() const
bool getUseRansacVVSPoseEstimation() const
double getMatchingFactorThreshold() const
bool getUseRansacConsensusPercentage() const
void parse(const std::string &filename)