1 // Copyright (c) 2010 libmv authors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 
21 #ifndef LIBMV_CORRESPONDENCE_N_ROBUST_VIEW_MATCHING_INTERFACE_H_
22 #define LIBMV_CORRESPONDENCE_N_ROBUST_VIEW_MATCHING_INTERFACE_H_
23 
24 struct FeatureSet;
25 #include <map>
26 
27 #include "libmv/correspondence/feature.h"
28 #include "libmv/correspondence/matches.h"
29 #include "libmv/correspondence/nViewMatchingInterface.h"
30 
31 namespace libmv {
32 namespace correspondence  {
33 
34 using namespace std;
35 
36 class nRobustViewMatching :public nViewMatchingInterface  {
37 
38   public:
39   nRobustViewMatching();
40   // Constructor (Specify a detector and a describer interface)
41   // The class do not handle memory management over this two parameter.
42   nRobustViewMatching(cv::Ptr<cv::FeatureDetector> pDetector,
43                       cv::Ptr<cv::DescriptorExtractor> pDescriber);
44   //TODO(pmoulon) Add a constructor with a Detector and a Descriptor
45   // Add also a Template function to make the match robust..
~nRobustViewMatching()46   ~nRobustViewMatching(){};
47 
48   /**
49    * Compute the data and store it in the class map<string,T>
50    *
51    * \param[in] filename   The file from which the data will be extracted.
52    *
53    * \return True if success.
54    */
55   bool computeData(const string & filename);
56 
57   /**
58   * Compute the putative match between data computed from element A and B
59   *  Store the match data internally in the class
60   *  map< <string, string> , MatchObject >
61   *
62   * \param[in] The name of the filename A (use computed data for this element)
63   * \param[in] The name of the filename B (use computed data for this element)
64   *
65   * \return True if success.
66   */
67   bool MatchData(const string & dataA, const string & dataB);
68 
69   /**
70   * From a series of element it computes the cross putative match list.
71   *
72   * \param[in] vec_data The data on which we want compute cross matches.
73   *
74   * \return True if success (and any matches was found).
75   */
76   bool computeCrossMatch( const std::vector<string> & vec_data);
77 
78 
79   /**
80   * From a series of element it computes the incremental putative match list.
81   * (only locally, in the relative neighborhood)
82   *
83   * \param[in] vec_data The data on which we want compute matches.
84   *
85   * \return True if success (and any matches was found).
86   */
87   bool computeRelativeMatch( const std::vector<string> & vec_data);
88 
89   /**
90   * Give the posibility to constrain the matches list.
91   *
92   * \param[in] matchIn The input match data between indexA and indexB.
93   * \param[in] dataAindex The reference index for element A.
94   * \param[in] dataBindex The reference index for element B.
95   * \param[out] matchesOut The output match that satisfy the internal constraint.
96   *
97   * \return True if success.
98   */
99   bool computeConstrainMatches(const Matches & matchIn,
100                                int dataAindex,
101                                int dataBindex,
102                                Matches * matchesOut);
103 
104   /// Return pairwise correspondence ( geometrically filtered )
getSharedData()105   const map< pair<string,string>, Matches> & getSharedData() const
106     { return m_sharedData;  }
107   /// Return extracted feature over the given image.
getViewData()108   const map<string,FeatureSet> & getViewData() const
109     { return m_ViewData;  }
110   /// Return detected geometrical consistent matches
getMatches()111   const Matches & getMatches()  const
112     { return m_tracks;  }
113 
114 private :
115   /// Input data names
116   std::vector<string> m_vec_InputNames;
117   /// Data that represent each named element.
118   map<string,FeatureSet> m_ViewData;
119   /// Matches between element named element <A,B>.
120   map< pair<string,string>, Matches> m_sharedData;
121 
122   /// LookUpTable to make the crossCorrespondence easier between tracks
123   ///   and feature.
124   map<const Feature*, int> m_featureToTrackTable;
125 
126   /// Matches between all the view.
127   Matches m_tracks;
128 
129   /// Interface to detect Keypoint.
130   std::shared_ptr<cv::FeatureDetector> m_pDetector;
131   /// Interface to describe Keypoint.
132   std::shared_ptr<cv::DescriptorExtractor> m_pDescriber;
133 };
134 
135 } // using namespace correspondence
136 } // using namespace libmv
137 
138 #endif  // LIBMV_CORRESPONDENCE_N_ROBUST_VIEW_MATCHING_INTERFACE_H_
139