48 #include <visp3/vision/vpXmlConfigParserKeyPoint.h> 51 #include <pugixml.hpp> 53 #include <visp3/core/vpException.h> 55 #ifndef DOXYGEN_SHOULD_SKIP_THIS 56 class vpXmlConfigParserKeyPoint::Impl
60 m_detectorName(
"ORB"), m_extractorName(
"ORB"), m_matcherName(
"BruteForce-Hamming"), m_matchingFactorThreshold(2.0),
62 m_nbRansacMinInlierCount(100), m_ransacConsensusPercentage(20.0), m_ransacReprojectionError(6.0),
63 m_ransacThreshold(0.01), m_useRansacConsensusPercentage(false), m_useRansacVVS(true)
73 m_nodeMap[
"conf"] = conf;
74 m_nodeMap[
"detector"] = detector;
75 m_nodeMap[
"extractor"] = extractor;
76 m_nodeMap[
"matcher"] = matcher;
77 m_nodeMap[
"name"] = name;
78 m_nodeMap[
"matching_method"] = matching_method;
79 m_nodeMap[
"constantFactorDistanceThreshold"] = constant_factor_distance_threshold;
80 m_nodeMap[
"stdDistanceThreshold"] = std_distance_threshold;
81 m_nodeMap[
"ratioDistanceThreshold"] = ratio_distance_threshold;
82 m_nodeMap[
"stdAndRatioDistanceThreshold"] = std_and_ratio_distance_threshold;
83 m_nodeMap[
"noFilterMatching"] = no_filter_matching;
84 m_nodeMap[
"matchingFactorThreshold"] = matching_factor_threshold;
85 m_nodeMap[
"matchingRatioThreshold"] = matching_ratio_threshold;
86 m_nodeMap[
"ransac"] = ransac;
87 m_nodeMap[
"useRansacVVS"] = use_ransac_vvs;
88 m_nodeMap[
"useRansacConsensusPercentage"] = use_ransac_consensus_percentage;
89 m_nodeMap[
"nbRansacIterations"] = nb_ransac_iterations;
90 m_nodeMap[
"ransacReprojectionError"] = ransac_reprojection_error;
91 m_nodeMap[
"nbRansacMinInlierCount"] = nb_ransac_min_inlier_count;
92 m_nodeMap[
"ransacThreshold"] = ransac_threshold;
93 m_nodeMap[
"ransacConsensusPercentage"] = ransac_consensus_percentage;
96 void parse(
const std::string &filename)
98 pugi::xml_document doc;
99 if (!doc.load_file(filename.c_str())) {
103 bool detector_node =
false;
104 bool extractor_node =
false;
105 bool matcher_node =
false;
107 pugi::xml_node root_node = doc.document_element();
108 for (pugi::xml_node dataNode = root_node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
109 if (dataNode.type() == pugi::node_element) {
110 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
111 if (iter_data != m_nodeMap.end()) {
112 switch (iter_data->second) {
114 read_detector(dataNode);
115 detector_node =
true;
119 read_extractor(dataNode);
120 extractor_node =
true;
124 read_matcher(dataNode);
129 read_ransac(dataNode);
139 if (!detector_node) {
140 std::cout <<
"detector: name: " << m_detectorName <<
" (default)" << std::endl;
143 if (!extractor_node) {
144 std::cout <<
"extractor: name: " << m_extractorName <<
" (default)" << std::endl;
148 std::cout <<
"matcher: name: " << m_matcherName <<
" (default)" << std::endl;
157 void read_detector(
const pugi::xml_node &node)
159 bool detector_name_node =
false;
161 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
162 if (dataNode.type() == pugi::node_element) {
163 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
164 if (iter_data != m_nodeMap.end()) {
165 switch (iter_data->second) {
167 m_detectorName = dataNode.text().as_string();
168 detector_name_node =
true;
178 if (!detector_name_node)
179 std::cout <<
"detector : Name : " << m_detectorName <<
" (default)" << std::endl;
181 std::cout <<
"detector : Name : " << m_detectorName << std::endl;
189 void read_extractor(
const pugi::xml_node &node)
191 bool extractor_name_node =
false;
193 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
194 if (dataNode.type() == pugi::node_element) {
195 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
196 if (iter_data != m_nodeMap.end()) {
197 switch (iter_data->second) {
199 m_extractorName = dataNode.text().as_string();
200 extractor_name_node =
true;
210 if (!extractor_name_node)
211 std::cout <<
"extractor : Name : " << m_extractorName <<
" (default)" << std::endl;
213 std::cout <<
"extractor : Name : " << m_extractorName << std::endl;
221 void read_matcher(
const pugi::xml_node &node)
223 bool matcher_name_node =
false;
224 bool matching_method_node =
false;
225 std::string matchingMethodName =
"ratioDistanceThreshold";
226 bool matching_factor_threshold_node =
false;
227 bool matching_ratio_threshold_node =
false;
229 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
230 if (dataNode.type() == pugi::node_element) {
231 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
232 if (iter_data != m_nodeMap.end()) {
233 switch (iter_data->second) {
235 m_matcherName = dataNode.text().as_string();
236 matcher_name_node =
true;
239 case matching_method: {
240 matchingMethodName = dataNode.text().as_string();
242 std::map<std::string, int>::iterator iter_data2 = m_nodeMap.find(matchingMethodName);
243 if (iter_data2 != m_nodeMap.end()) {
244 matching_method_node =
true;
245 switch (iter_data2->second) {
246 case constant_factor_distance_threshold:
250 case std_distance_threshold:
254 case ratio_distance_threshold:
258 case std_and_ratio_distance_threshold:
262 case no_filter_matching:
267 matching_method_node =
false;
274 case matching_factor_threshold:
275 m_matchingFactorThreshold = dataNode.text().as_double();
276 matching_factor_threshold_node =
true;
279 case matching_ratio_threshold:
280 m_matchingRatioThreshold = dataNode.text().as_double();
281 matching_ratio_threshold_node =
true;
291 if (!matcher_name_node)
292 std::cout <<
"matcher : Name : " << m_matcherName <<
" (default)" << std::endl;
294 std::cout <<
"matcher : Name : " << m_matcherName << std::endl;
296 if (!matching_method_node)
297 std::cout <<
"matcher : Filter method : " << matchingMethodName <<
" (default)" << std::endl;
299 std::cout <<
"matcher : Filter method : " << matchingMethodName << std::endl;
301 if (!matching_factor_threshold_node)
302 std::cout <<
"matcher : matching factor threshold : " << m_matchingFactorThreshold <<
" (default)" << std::endl;
304 std::cout <<
"matcher : matching factor threshold : " << m_matchingFactorThreshold << std::endl;
306 if (!matching_ratio_threshold_node)
307 std::cout <<
"matcher : matching ratio threshold : " << m_matchingRatioThreshold <<
" (default)" << std::endl;
309 std::cout <<
"matcher : matching ratio threshold : " << m_matchingRatioThreshold << std::endl;
317 void read_ransac(
const pugi::xml_node &node)
319 bool use_ransac_vvs_node =
false;
320 bool use_ransac_consensus_percentage_node =
false;
321 bool nb_ransac_iterations_node =
false;
322 bool ransac_reprojection_error_node =
false;
323 bool nb_ransac_min_inlier_count_node =
false;
324 bool ransac_threshold_node =
false;
325 bool ransac_consensus_percentage_node =
false;
327 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
328 if (dataNode.type() == pugi::node_element) {
329 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
330 if (iter_data != m_nodeMap.end()) {
331 switch (iter_data->second) {
333 m_useRansacVVS = dataNode.text().as_int() != 0;
334 use_ransac_vvs_node =
true;
337 case use_ransac_consensus_percentage:
338 m_useRansacConsensusPercentage = dataNode.text().as_int() != 0;
339 use_ransac_consensus_percentage_node =
true;
342 case nb_ransac_iterations:
343 m_nbRansacIterations = dataNode.text().as_int();
344 nb_ransac_iterations_node =
true;
347 case ransac_reprojection_error:
348 m_ransacReprojectionError = dataNode.text().as_double();
349 ransac_reprojection_error_node =
true;
352 case nb_ransac_min_inlier_count:
353 m_nbRansacMinInlierCount = dataNode.text().as_int();
354 nb_ransac_min_inlier_count_node =
true;
357 case ransac_threshold:
358 m_ransacThreshold = dataNode.text().as_double();
359 ransac_threshold_node =
true;
362 case ransac_consensus_percentage:
363 m_ransacConsensusPercentage = dataNode.text().as_double();
364 ransac_consensus_percentage_node =
true;
374 if (!use_ransac_vvs_node)
375 std::cout <<
"ransac: use ransac vvs pose estimation: " << m_useRansacVVS <<
" (default)" << std::endl;
377 std::cout <<
"ransac: use ransac vvs pose estimation: " << m_useRansacVVS << std::endl;
379 if (!use_ransac_consensus_percentage_node)
380 std::cout <<
"ransac: use consensus percentage: " << m_useRansacConsensusPercentage <<
" (default)" << std::endl;
382 std::cout <<
"ransac: use consensus percentage: " << m_useRansacConsensusPercentage << std::endl;
384 if (!nb_ransac_iterations_node)
385 std::cout <<
"ransac: nb ransac iterations: " << m_nbRansacIterations <<
" (default)" << std::endl;
387 std::cout <<
"ransac: nb ransac iterations: " << m_nbRansacIterations << std::endl;
389 if (!ransac_reprojection_error_node)
390 std::cout <<
"ransac: ransac reprojection error in pixel (for OpenCV " 392 << m_ransacReprojectionError <<
" (default)" << std::endl;
394 std::cout <<
"ransac: ransac reprojection error in pixel (for OpenCV " 396 << m_ransacReprojectionError << std::endl;
398 if (!nb_ransac_min_inlier_count_node)
399 std::cout <<
"ransac: nb ransac min inlier count: " << m_nbRansacMinInlierCount <<
" (default)" << std::endl;
401 std::cout <<
"ransac: nb ransac min inlier count: " << m_nbRansacMinInlierCount << std::endl;
403 if (!ransac_threshold_node)
404 std::cout <<
"ransac: ransac threshold in meter (for ViSP function): " << m_ransacThreshold <<
" (default)" 407 std::cout <<
"ransac: ransac threshold in meter (for ViSP function): " << m_ransacThreshold << std::endl;
409 if (!ransac_consensus_percentage_node)
410 std::cout <<
"ransac: consensus percentage: " << m_ransacConsensusPercentage <<
" (default)" << std::endl;
412 std::cout <<
"ransac: consensus percentage: " << m_ransacConsensusPercentage << std::endl;
433 enum vpNodeIdentifier {
440 constant_factor_distance_threshold,
443 std_distance_threshold,
445 ratio_distance_threshold,
447 std_and_ratio_distance_threshold,
452 matching_factor_threshold,
454 matching_ratio_threshold,
458 use_ransac_consensus_percentage,
461 nb_ransac_iterations,
463 ransac_reprojection_error,
465 nb_ransac_min_inlier_count,
469 ransac_consensus_percentage
474 std::string m_detectorName;
476 std::string m_extractorName;
478 std::string m_matcherName;
480 double m_matchingFactorThreshold;
484 double m_matchingRatioThreshold;
486 int m_nbRansacIterations;
488 int m_nbRansacMinInlierCount;
490 double m_ransacConsensusPercentage;
493 double m_ransacReprojectionError;
496 double m_ransacThreshold;
500 bool m_useRansacConsensusPercentage;
504 std::map<std::string, int> m_nodeMap;
506 #endif // DOXYGEN_SHOULD_SKIP_THIS 523 m_impl->parse(filename);
533 return m_impl->getDetectorName();
543 return m_impl->getExtractorName();
553 return m_impl->getMatcherName();
564 return m_impl->getMatchingFactorThreshold();
574 return m_impl->getMatchingMethod();
584 return m_impl->getMatchingRatioThreshold();
594 return m_impl->getNbRansacIterations();
604 return m_impl->getNbRansacMinInlierCount();
614 return m_impl->getRansacConsensusPercentage();
625 return m_impl->getRansacReprojectionError();
635 return m_impl->getRansacThreshold();
646 return m_impl->getUseRansacConsensusPercentage();
657 return m_impl->getUseRansacVVSPoseEstimation();
std::string getMatcherName() const
double getMatchingFactorThreshold() const
bool getUseRansacVVSPoseEstimation() const
error that can be emited by ViSP classes.
double getRansacConsensusPercentage() const
int getNbRansacMinInlierCount() const
~vpXmlConfigParserKeyPoint()
bool getUseRansacConsensusPercentage() const
vpMatchingMethodEnum getMatchingMethod() const
double getRansacReprojectionError() const
int getNbRansacIterations() const
double getMatchingRatioThreshold() const
std::string getDetectorName() const
vpXmlConfigParserKeyPoint()
double getRansacThreshold() const
std::string getExtractorName() const
void parse(const std::string &filename)