43 #include <visp3/vision/vpXmlConfigParserKeyPoint.h>
46 #if defined(VISP_HAVE_PUGIXML)
47 #include <pugixml.hpp>
49 #include <visp3/core/vpException.h>
51 #ifndef DOXYGEN_SHOULD_SKIP_THIS
52 class vpXmlConfigParserKeyPoint::Impl
56 : m_detectorName(
"ORB"), m_extractorName(
"ORB"), m_matcherName(
"BruteForce-Hamming"),
58 m_nbRansacIterations(200), m_nbRansacMinInlierCount(100), m_ransacConsensusPercentage(20.0),
59 m_ransacReprojectionError(6.0), m_ransacThreshold(0.01), m_useRansacConsensusPercentage(false),
70 m_nodeMap[
"conf"] = conf;
71 m_nodeMap[
"detector"] = detector;
72 m_nodeMap[
"extractor"] = extractor;
73 m_nodeMap[
"matcher"] = matcher;
74 m_nodeMap[
"name"] = name;
75 m_nodeMap[
"matching_method"] = matching_method;
76 m_nodeMap[
"constantFactorDistanceThreshold"] = constant_factor_distance_threshold;
77 m_nodeMap[
"stdDistanceThreshold"] = std_distance_threshold;
78 m_nodeMap[
"ratioDistanceThreshold"] = ratio_distance_threshold;
79 m_nodeMap[
"stdAndRatioDistanceThreshold"] = std_and_ratio_distance_threshold;
80 m_nodeMap[
"noFilterMatching"] = no_filter_matching;
81 m_nodeMap[
"matchingFactorThreshold"] = matching_factor_threshold;
82 m_nodeMap[
"matchingRatioThreshold"] = matching_ratio_threshold;
83 m_nodeMap[
"ransac"] = ransac;
84 m_nodeMap[
"useRansacVVS"] = use_ransac_vvs;
85 m_nodeMap[
"useRansacConsensusPercentage"] = use_ransac_consensus_percentage;
86 m_nodeMap[
"nbRansacIterations"] = nb_ransac_iterations;
87 m_nodeMap[
"ransacReprojectionError"] = ransac_reprojection_error;
88 m_nodeMap[
"nbRansacMinInlierCount"] = nb_ransac_min_inlier_count;
89 m_nodeMap[
"ransacThreshold"] = ransac_threshold;
90 m_nodeMap[
"ransacConsensusPercentage"] = ransac_consensus_percentage;
93 void parse(
const std::string &filename)
95 pugi::xml_document doc;
96 if (!doc.load_file(filename.c_str())) {
100 bool detector_node =
false;
101 bool extractor_node =
false;
102 bool matcher_node =
false;
104 pugi::xml_node root_node = doc.document_element();
105 for (pugi::xml_node dataNode = root_node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
106 if (dataNode.type() == pugi::node_element) {
107 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
108 if (iter_data != m_nodeMap.end()) {
109 switch (iter_data->second) {
111 read_detector(dataNode);
112 detector_node =
true;
116 read_extractor(dataNode);
117 extractor_node =
true;
121 read_matcher(dataNode);
126 read_ransac(dataNode);
136 if (!detector_node) {
137 std::cout <<
"detector: name: " << m_detectorName <<
" (default)" << std::endl;
140 if (!extractor_node) {
141 std::cout <<
"extractor: name: " << m_extractorName <<
" (default)" << std::endl;
145 std::cout <<
"matcher: name: " << m_matcherName <<
" (default)" << std::endl;
154 void read_detector(
const pugi::xml_node &node)
156 bool detector_name_node =
false;
158 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
159 if (dataNode.type() == pugi::node_element) {
160 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
161 if (iter_data != m_nodeMap.end()) {
162 switch (iter_data->second) {
164 m_detectorName = dataNode.text().as_string();
165 detector_name_node =
true;
175 if (!detector_name_node)
176 std::cout <<
"detector : Name : " << m_detectorName <<
" (default)" << std::endl;
178 std::cout <<
"detector : Name : " << m_detectorName << std::endl;
186 void read_extractor(
const pugi::xml_node &node)
188 bool extractor_name_node =
false;
190 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
191 if (dataNode.type() == pugi::node_element) {
192 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
193 if (iter_data != m_nodeMap.end()) {
194 switch (iter_data->second) {
196 m_extractorName = dataNode.text().as_string();
197 extractor_name_node =
true;
207 if (!extractor_name_node)
208 std::cout <<
"extractor : Name : " << m_extractorName <<
" (default)" << std::endl;
210 std::cout <<
"extractor : Name : " << m_extractorName << std::endl;
218 void read_matcher(
const pugi::xml_node &node)
220 bool matcher_name_node =
false;
221 bool matching_method_node =
false;
222 std::string matchingMethodName =
"ratioDistanceThreshold";
223 bool matching_factor_threshold_node =
false;
224 bool matching_ratio_threshold_node =
false;
226 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
227 if (dataNode.type() == pugi::node_element) {
228 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
229 if (iter_data != m_nodeMap.end()) {
230 switch (iter_data->second) {
232 m_matcherName = dataNode.text().as_string();
233 matcher_name_node =
true;
236 case matching_method: {
237 matchingMethodName = dataNode.text().as_string();
239 std::map<std::string, int>::iterator iter_data2 = m_nodeMap.find(matchingMethodName);
240 if (iter_data2 != m_nodeMap.end()) {
241 matching_method_node =
true;
242 switch (iter_data2->second) {
243 case constant_factor_distance_threshold:
247 case std_distance_threshold:
251 case ratio_distance_threshold:
255 case std_and_ratio_distance_threshold:
259 case no_filter_matching:
264 matching_method_node =
false;
271 case matching_factor_threshold:
272 m_matchingFactorThreshold = dataNode.text().as_double();
273 matching_factor_threshold_node =
true;
276 case matching_ratio_threshold:
277 m_matchingRatioThreshold = dataNode.text().as_double();
278 matching_ratio_threshold_node =
true;
288 if (!matcher_name_node)
289 std::cout <<
"matcher : Name : " << m_matcherName <<
" (default)" << std::endl;
291 std::cout <<
"matcher : Name : " << m_matcherName << std::endl;
293 if (!matching_method_node)
294 std::cout <<
"matcher : Filter method : " << matchingMethodName <<
" (default)" << std::endl;
296 std::cout <<
"matcher : Filter method : " << matchingMethodName << std::endl;
298 if (!matching_factor_threshold_node)
299 std::cout <<
"matcher : matching factor threshold : " << m_matchingFactorThreshold <<
" (default)" << std::endl;
301 std::cout <<
"matcher : matching factor threshold : " << m_matchingFactorThreshold << std::endl;
303 if (!matching_ratio_threshold_node)
304 std::cout <<
"matcher : matching ratio threshold : " << m_matchingRatioThreshold <<
" (default)" << std::endl;
306 std::cout <<
"matcher : matching ratio threshold : " << m_matchingRatioThreshold << std::endl;
314 void read_ransac(
const pugi::xml_node &node)
316 bool use_ransac_vvs_node =
false;
317 bool use_ransac_consensus_percentage_node =
false;
318 bool nb_ransac_iterations_node =
false;
319 bool ransac_reprojection_error_node =
false;
320 bool nb_ransac_min_inlier_count_node =
false;
321 bool ransac_threshold_node =
false;
322 bool ransac_consensus_percentage_node =
false;
324 for (pugi::xml_node dataNode = node.first_child(); dataNode; dataNode = dataNode.next_sibling()) {
325 if (dataNode.type() == pugi::node_element) {
326 std::map<std::string, int>::iterator iter_data = m_nodeMap.find(dataNode.name());
327 if (iter_data != m_nodeMap.end()) {
328 switch (iter_data->second) {
330 m_useRansacVVS = dataNode.text().as_int() != 0;
331 use_ransac_vvs_node =
true;
334 case use_ransac_consensus_percentage:
335 m_useRansacConsensusPercentage = dataNode.text().as_int() != 0;
336 use_ransac_consensus_percentage_node =
true;
339 case nb_ransac_iterations:
340 m_nbRansacIterations = dataNode.text().as_int();
341 nb_ransac_iterations_node =
true;
344 case ransac_reprojection_error:
345 m_ransacReprojectionError = dataNode.text().as_double();
346 ransac_reprojection_error_node =
true;
349 case nb_ransac_min_inlier_count:
350 m_nbRansacMinInlierCount = dataNode.text().as_int();
351 nb_ransac_min_inlier_count_node =
true;
354 case ransac_threshold:
355 m_ransacThreshold = dataNode.text().as_double();
356 ransac_threshold_node =
true;
359 case ransac_consensus_percentage:
360 m_ransacConsensusPercentage = dataNode.text().as_double();
361 ransac_consensus_percentage_node =
true;
371 if (!use_ransac_vvs_node)
372 std::cout <<
"ransac: use ransac vvs pose estimation: " << m_useRansacVVS <<
" (default)" << std::endl;
374 std::cout <<
"ransac: use ransac vvs pose estimation: " << m_useRansacVVS << std::endl;
376 if (!use_ransac_consensus_percentage_node)
377 std::cout <<
"ransac: use consensus percentage: " << m_useRansacConsensusPercentage <<
" (default)" << std::endl;
379 std::cout <<
"ransac: use consensus percentage: " << m_useRansacConsensusPercentage << std::endl;
381 if (!nb_ransac_iterations_node)
382 std::cout <<
"ransac: nb ransac iterations: " << m_nbRansacIterations <<
" (default)" << std::endl;
384 std::cout <<
"ransac: nb ransac iterations: " << m_nbRansacIterations << std::endl;
386 if (!ransac_reprojection_error_node)
387 std::cout <<
"ransac: ransac reprojection error in pixel (for OpenCV "
389 << m_ransacReprojectionError <<
" (default)" << std::endl;
391 std::cout <<
"ransac: ransac reprojection error in pixel (for OpenCV "
393 << m_ransacReprojectionError << std::endl;
395 if (!nb_ransac_min_inlier_count_node)
396 std::cout <<
"ransac: nb ransac min inlier count: " << m_nbRansacMinInlierCount <<
" (default)" << std::endl;
398 std::cout <<
"ransac: nb ransac min inlier count: " << m_nbRansacMinInlierCount << std::endl;
400 if (!ransac_threshold_node)
401 std::cout <<
"ransac: ransac threshold in meter (for ViSP function): " << m_ransacThreshold <<
" (default)"
404 std::cout <<
"ransac: ransac threshold in meter (for ViSP function): " << m_ransacThreshold << std::endl;
406 if (!ransac_consensus_percentage_node)
407 std::cout <<
"ransac: consensus percentage: " << m_ransacConsensusPercentage <<
" (default)" << std::endl;
409 std::cout <<
"ransac: consensus percentage: " << m_ransacConsensusPercentage << std::endl;
430 enum vpNodeIdentifier
438 constant_factor_distance_threshold,
441 std_distance_threshold,
443 ratio_distance_threshold,
445 std_and_ratio_distance_threshold,
450 matching_factor_threshold,
452 matching_ratio_threshold,
456 use_ransac_consensus_percentage,
459 nb_ransac_iterations,
461 ransac_reprojection_error,
463 nb_ransac_min_inlier_count,
467 ransac_consensus_percentage
472 std::string m_detectorName;
474 std::string m_extractorName;
476 std::string m_matcherName;
478 double m_matchingFactorThreshold;
482 double m_matchingRatioThreshold;
484 int m_nbRansacIterations;
486 int m_nbRansacMinInlierCount;
488 double m_ransacConsensusPercentage;
491 double m_ransacReprojectionError;
494 double m_ransacThreshold;
498 bool m_useRansacConsensusPercentage;
502 std::map<std::string, int> m_nodeMap;
522 return m_impl->getMatchingMethod();
533 return m_impl->getRansacConsensusPercentage();
542 return m_impl->getUseRansacConsensusPercentage();
547 return m_impl->getUseRansacVVSPoseEstimation();
550 #elif !defined(VISP_BUILD_SHARED_LIBS)
552 void dummy_vpXmlConfigParserKeyPoint() { };
error that can be emitted by ViSP classes.
std::string getDetectorName() const
~vpXmlConfigParserKeyPoint()
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
int getNbRansacIterations() const
double getRansacConsensusPercentage() const
@ stdAndRatioDistanceThreshold
@ constantFactorDistanceThreshold
vpMatchingMethodEnum getMatchingMethod() const
double getRansacThreshold() const
void init(vpImage< unsigned char > &Iinput, vpImage< unsigned char > &IcannyVisp, vpImage< unsigned char > *p_dIx, vpImage< unsigned char > *p_dIy, vpImage< unsigned char > *p_IcannyimgFilter)
Initialize the different displays.