00001
00002
00003 #ifndef _GFM_SIMPLEMATCH_HPP_
00004 #define _GFM_SIMPLEMATCH_HPP_
00005
00006 #include <boost/serialization/nvp.hpp>
00007 #include <boost/serialization/utility.hpp>
00008 #include <boost/serialization/version.hpp>
00009
00010 #include "gfm/Matcher.hpp"
00011 #include "kernel/jafarMacro.hpp"
00012 namespace jafar {
00013 namespace gfm {
00018 class SimpleMatcher : public Matcher {
00019 public:
00026 SimpleMatcher(double good_match_threshold, int search_win_half_width, int search_win_half_height);
00027 public:
00028 virtual jafar::gfm::MatchingResult computeMatch( MatchSourceInfo* refsourceinfo, MatchSourceInfo* matchsourceinfo);
00029 private:
00030 fdetect::InterestFeature* testFor(fdetect::InterestFeature* ip,
00031 fdetect::DetectionResult& points);
00032 private:
00033 double m_zncc_threshold;
00034 int m_search_win_half_width, m_search_win_half_height;
00036 friend class boost::serialization::access;
00037 template<class Archive>
00038 void serialize(Archive &ar, const unsigned int version)
00039 {
00040 ar & BOOST_SERIALIZATION_NVP(m_zncc_threshold);
00041 ar & BOOST_SERIALIZATION_NVP(m_search_win_half_width);
00042 ar & BOOST_SERIALIZATION_NVP(m_search_win_half_height);
00043 }
00044 };
00045 }
00046
00047 namespace gfm_v2 {
00052 template<typename InterestFeatureT>
00053 class SimpleMatcher : public Matcher<InterestFeatureT>
00054 {
00055 public:
00056 typedef jafar::fdetect_v2::DetectionResult< InterestFeatureT > DetectionResult;
00057 typedef gfm_v2::MatchSourceInfo<InterestFeatureT> MatchSourceInfo;
00058 typedef jafar::gfm_v2::MatchingResult<InterestFeatureT> MatchingResult;
00059
00066 SimpleMatcher(double good_match_threshold,
00067 int search_win_half_width,
00068 int search_win_half_height) :
00069 m_zncc_threshold(good_match_threshold),
00070 m_search_win_half_width(search_win_half_width),
00071 m_search_win_half_height(search_win_half_height) { }
00072 public:
00073 virtual MatchingResult computeMatch( MatchSourceInfo* refsourceinfo,
00074 MatchSourceInfo* matchsourceinfo)
00075 {
00076 using namespace fdetect_v2;
00077 DetectionResult points_ref = refsourceinfo->points();
00078 DetectionResult points_match = matchsourceinfo->points();
00079
00080 MatchingResult result(points_ref, points_match);
00081 int eliminated = 0;
00082 for(typename DetectionResult::const_iterator it=points_ref.begin();
00083 it != points_ref.end();
00084 ++it)
00085 {
00086 InterestFeatureT* ip = testFor( *it, points_match);
00087 if(ip)
00088 {
00089 InterestFeatureT* ret = testFor( ip, points_ref);
00090 if(ret == *it)
00091 {
00092 result.addMatch(*it, ip);
00093 } else {
00094 eliminated++;
00095 }
00096 }
00097 }
00098 JFR_DEBUG("Eliminated = " << eliminated);
00099 return result;
00100 }
00101
00102 private:
00103 InterestFeatureT* testFor(InterestFeatureT* ip,
00104 DetectionResult& points)
00105 {
00106 using namespace fdetect_v2;
00107 float startu = ip->u() - m_search_win_half_width;
00108 float endu = ip->u() + m_search_win_half_width;
00109 float startv = ip->v() - m_search_win_half_height;
00110 float endv = ip->v() + m_search_win_half_height;
00111
00112 double bestzncc = 0.;
00113 InterestFeatureT* bestpoint = 0;
00114
00115 for(typename DetectionResult::const_iterator it = points.begin();
00116 it != points.end();
00117 ++it)
00118 {
00119 if( (*it)->u() > startu && (*it)->u() < endu && (*it)->v() > startv && (*it)->v() < endv)
00120 {
00121 double zncc = ((*it)->descriptor()).strongComparison(ip->descriptor(), 0.);
00122 if( zncc > m_zncc_threshold )
00123 {
00124 bestzncc = zncc;
00125 bestpoint = *it;
00126 }
00127 }
00128 }
00129 return bestpoint;
00130 }
00131 double m_zncc_threshold;
00132 int m_search_win_half_width, m_search_win_half_height;
00134 friend class boost::serialization::access;
00135 template<class Archive>
00136 void serialize(Archive &ar, const unsigned int version)
00137 {
00138 ar & BOOST_SERIALIZATION_NVP(m_zncc_threshold);
00139 ar & BOOST_SERIALIZATION_NVP(m_search_win_half_width);
00140 ar & BOOST_SERIALIZATION_NVP(m_search_win_half_height);
00141 }
00142 };
00143 }
00144 }
00145
00146 #endif