Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
EngineTracking.hpp
00001 /* $Id$ */
00002 
00003 #ifndef _GFM_ENGINETRACKING_HPP_
00004 #define _GFM_ENGINETRACKING_HPP_
00005 
00006 #include "image/Image.hpp"
00007 #include "fdetect/InterestFeature.hpp"
00008 #include "fdetect/DetectionResult.hpp"
00009 #include "fdetect/Detector.hpp"
00010 #include "fdetect/Descriptor.hpp"
00011 #include "gfm/Matcher.hpp"
00012 #include "gfm/MatchingResult.hpp"
00013 
00014 
00015 #include <boost/serialization/nvp.hpp>
00016 #include <boost/serialization/utility.hpp>
00017 #include <boost/serialization/version.hpp>
00018 #include <boost/noncopyable.hpp>
00019 
00020 namespace jafar {
00021   namespace gfm {
00022     // class MatchSourceInfo;
00023     // class DescriptorFactory;
00024     // class Detector;
00025     // class Matcher;
00026     // class MatchingResult;
00031     class EngineTracking: public boost::noncopyable {
00032       public:
00033       EngineTracking(jafar::fdetect::Detector* detector, 
00034                      jafar::gfm::Matcher* matcher, 
00035                      jafar::fdetect::DescriptorFactory* descriptor = 0) : 
00036         m_detector(detector), 
00037         m_descriptorFactory(descriptor), 
00038         m_matcher(matcher), 
00039         m_sourceInfoRef(0) { }
00040         ~EngineTracking();
00041       public:
00042         const jafar::fdetect::DetectionResult& currentPoints() const;
00046       void initTracking(jafar::image::Image const& image_ref, 
00047                         unsigned int id = geom::InterestPoint::NO_ID);
00053       jafar::gfm::MatchingResult nextImage(jafar::image::Image const& image_next, 
00054                                            unsigned int id = geom::InterestPoint::NO_ID);
00055       protected:
00056         inline MatchSourceInfo* sourceInfoRef() const { return m_sourceInfoRef; }
00057         inline Matcher* matcher() { return m_matcher; }
00058         inline fdetect::DescriptorFactory* descriptorFactory() { return m_descriptorFactory; }
00059         inline fdetect::Detector* detector() { return m_detector; }
00060       private:
00061         fdetect::Detector* m_detector;
00062         fdetect::DescriptorFactory* m_descriptorFactory;
00063         Matcher* m_matcher;
00064         MatchSourceInfo* m_sourceInfoRef;
00066       friend class boost::serialization::access;
00067       template<class Archive>
00068       void serialize(Archive &ar, const unsigned int version)
00069       {
00070         ar & BOOST_SERIALIZATION_NVP(m_detector);
00071         ar & BOOST_SERIALIZATION_NVP(m_descriptorFactory);
00072         ar & BOOST_SERIALIZATION_NVP(m_matcher);
00074         //ar & BOOST_SERIALIZATION_NVP(m_sourceInfoRef);
00075       }
00076     };
00077 
00082     class EngineStereoTracking : public EngineTracking {
00083       public:
00084         EngineStereoTracking(jafar::fdetect::Detector* detector,
00085                              jafar::gfm::Matcher* matcher,
00086                              jafar::gfm::Matcher* stereomatcher,
00087                              jafar::fdetect::DescriptorFactory* descriptor = 0);
00088         ~EngineStereoTracking();
00089       public:
00094         jafar::gfm::MatchingResult matchCurrentWith(jafar::image::Image const& image_match );
00095       private:
00096         Matcher* m_stereoMatcher;
00098       friend class boost::serialization::access;
00099       template<class Archive>
00100       void serialize(Archive &ar, const unsigned int version)
00101       {
00102         ar & BOOST_SERIALIZATION_NVP(m_stereoMatcher);
00103       }
00104     };
00105   }
00106 
00107   namespace gfm_v2 {
00112     template<typename InterestFeatureT>
00113     class EngineTracking: public boost::noncopyable {
00114       public:
00121       EngineTracking(jafar::fdetect_v2::Detector<InterestFeatureT>* detector, 
00122                      jafar::gfm_v2::Matcher<InterestFeatureT>* matcher, 
00123                      jafar::fdetect_v2::DescriptorFactory<InterestFeatureT>* descriptor = 0) : 
00124         m_detector(detector), 
00125         m_descriptorFactory(descriptor), 
00126         m_matcher(matcher), 
00127         m_sourceInfoRef(0) { }
00129       ~EngineTracking()
00130       {
00131         delete m_detector;
00132         if(m_descriptorFactory)
00133           delete m_descriptorFactory;
00134         delete m_matcher;
00135         if(m_sourceInfoRef)
00136           delete m_sourceInfoRef;
00137       }
00138 
00140       const jafar::fdetect_v2::DetectionResult<InterestFeatureT>& currentPoints() const
00141       {
00142         return m_sourceInfoRef->points();
00143       }
00144 
00149       void initTracking(jafar::image::Image const& image_ref, 
00150                         unsigned int id = geom::InterestPoint::NO_ID)
00151       {
00152         this->initTracking(image_ref, jafar::image::Image(), id);
00153       }
00154 
00160       void initTracking(jafar::image::Image const& image_ref,
00161                         jafar::image::Image const& mask_ref,
00162                         unsigned int id = geom::InterestPoint::NO_ID)
00163       {
00164         using namespace fdetect_v2;
00165         DetectionResult<InterestFeatureT> points_ref = m_detector->detectIn(image_ref, mask_ref, true);
00166         if(id != geom::InterestPoint::NO_ID) 
00167         {
00168           points_ref.id = id;
00169           for (typename DetectionResult<InterestFeatureT>::iterator it = points_ref.begin();
00170                it != points_ref.end();
00171                ++it)
00172             (*it)->parent_id = id;
00173         }
00174         if(m_descriptorFactory)
00175         {
00176           m_descriptorFactory->createDescriptor(points_ref, image_ref);
00177         }
00178         m_sourceInfoRef = m_matcher->initMatchSourceInfo(points_ref);
00179       }
00180 
00186       void initTracking(fdetect_v2::DetectionResult<InterestFeatureT> &points_ref, 
00187                         unsigned int id = geom::InterestPoint::NO_ID)
00188       {
00189         using namespace fdetect_v2;
00190         if(id != geom::InterestPoint::NO_ID) 
00191         {
00192           points_ref.id = id;
00193           for (typename DetectionResult<InterestFeatureT>::iterator it = points_ref.begin();
00194                it != points_ref.end();
00195                ++it)
00196             (*it)->parent_id = id;
00197         }
00198         m_sourceInfoRef = m_matcher->initMatchSourceInfo(points_ref);
00199       }
00200 
00207       MatchingResult<InterestFeatureT> nextImage(jafar::image::Image const& image_next, 
00208                                            unsigned int id = geom::InterestPoint::NO_ID)
00209       {
00210         return this->nextImage(image_next, jafar::image::Image(), id);
00211       }
00212 
00220       MatchingResult<InterestFeatureT> nextImage(jafar::image::Image const& image_next,
00221                                            jafar::image::Image const& mask_next,
00222                                            unsigned int id = geom::InterestPoint::NO_ID)
00223       {
00224         using namespace fdetect_v2;
00225         DetectionResult<InterestFeatureT> points_match = m_detector->detectIn(image_next, mask_next);
00226         if(id != geom::InterestPoint::NO_ID) 
00227         {
00228           points_match.id = id;
00229           for ( typename DetectionResult<InterestFeatureT>::iterator it = points_match.begin();
00230                 it != points_match.end();
00231                 ++it)
00232             (*it)->parent_id = id;
00233         }
00234         if(m_descriptorFactory)
00235         {
00236           m_descriptorFactory->createDescriptor(points_match, image_next);
00237         }
00238         MatchSourceInfo<InterestFeatureT>* infomatch = m_matcher->initMatchSourceInfo(points_match);
00239         m_sourceInfoRef->reinit();
00240         MatchingResult<InterestFeatureT> result = m_matcher->computeMatch(m_sourceInfoRef, infomatch);
00241         JFR_DEBUG("Found " << result.matches().size() << " matches");
00242         delete m_sourceInfoRef;
00243         m_sourceInfoRef = infomatch;
00244         return result;
00245       }
00246 
00254       MatchingResult<InterestFeatureT> nextImage(fdetect_v2::DetectionResult<InterestFeatureT> &points_next, 
00255                                            unsigned int id = geom::InterestPoint::NO_ID)
00256       {
00257         using namespace fdetect_v2;
00258         if(id != geom::InterestPoint::NO_ID) 
00259         {
00260           points_next.id = id;
00261           for ( typename DetectionResult<InterestFeatureT>::iterator it = points_next.begin();
00262                 it != points_next.end();
00263                 ++it)
00264             (*it)->parent_id = id;
00265         }
00266         MatchSourceInfo<InterestFeatureT>* infomatch = m_matcher->initMatchSourceInfo(points_next);
00267         m_sourceInfoRef->reinit();
00268         MatchingResult<InterestFeatureT> result = m_matcher->computeMatch(m_sourceInfoRef, infomatch);
00269         JFR_DEBUG("Found " << result.matches().size() << " matches");
00270         delete m_sourceInfoRef;
00271         m_sourceInfoRef = infomatch;
00272         return result;
00273       }
00274 
00275       MatchSourceInfo<InterestFeatureT>* sourceInfoRef() const 
00276       { 
00277         return m_sourceInfoRef; 
00278       }
00279 
00280     protected:
00281       Matcher<InterestFeatureT>* matcher() 
00282       { 
00283         return m_matcher; 
00284       }
00285       fdetect_v2::DescriptorFactory<InterestFeatureT>* descriptorFactory() 
00286       { 
00287         return m_descriptorFactory; 
00288       }
00289       fdetect_v2::Detector<InterestFeatureT>* detector() 
00290       { 
00291         return m_detector; 
00292       }
00293     protected:
00294       fdetect_v2::Detector<InterestFeatureT>* m_detector;
00295       fdetect_v2::DescriptorFactory<InterestFeatureT>* m_descriptorFactory;
00296       Matcher<InterestFeatureT>* m_matcher;
00297       MatchSourceInfo<InterestFeatureT>* m_sourceInfoRef;
00298     private:
00300       friend class boost::serialization::access;
00301       template<class Archive>
00302       void serialize(Archive &ar, const unsigned int version)
00303       {
00304         ar & BOOST_SERIALIZATION_NVP(m_detector);
00305         ar & BOOST_SERIALIZATION_NVP(m_descriptorFactory);
00306         ar & BOOST_SERIALIZATION_NVP(m_matcher);
00308         //ar & BOOST_SERIALIZATION_NVP(m_sourceInfoRef);
00309       }
00310     };
00311 
00316     template<typename InterestFeatureT>
00317     class EngineStereoTracking : public EngineTracking<InterestFeatureT> {
00318     public:
00319       EngineStereoTracking(fdetect_v2::Detector<InterestFeatureT>* detector, 
00320                            Matcher<InterestFeatureT>* matcher, 
00321                            Matcher<InterestFeatureT>* stereomatcher, 
00322                            fdetect_v2::DescriptorFactory<InterestFeatureT>* descriptor = 0)
00323         : EngineTracking<InterestFeatureT>(detector, matcher, descriptor), 
00324           m_stereoMatcher(stereomatcher)
00325       { }
00326       ~EngineStereoTracking()
00327       {
00328         delete m_stereoMatcher;
00329       }
00330     public:
00335       MatchingResult<InterestFeatureT> matchCurrentWith(jafar::image::Image const& image_match )
00336       {
00337         using namespace fdetect_v2;
00338         DetectionResult<InterestFeatureT> points_match = this->detector()->detectIn(image_match);
00339         if(this->descriptorFactory())
00340         {
00341           this->descriptorFactory()->createDescriptor(points_match, image_match);
00342         }
00343         MatchSourceInfo<InterestFeatureT>* infomatch = this->matcher()->initMatchSourceInfo(points_match);
00344         this->sourceInfoRef()->reinit();
00345         MatchingResult<InterestFeatureT> result = this->m_stereoMatcher->computeMatch(this->sourceInfoRef(), infomatch);
00346         delete infomatch;
00347         return result;
00348       }
00349 
00350     private:
00351       Matcher<InterestFeatureT>* m_stereoMatcher;
00353       friend class boost::serialization::access;
00354       template<class Archive>
00355       void serialize(Archive &ar, const unsigned int version)
00356       {
00357         ar & BOOST_SERIALIZATION_NVP(m_stereoMatcher);
00358       }
00359     };
00360   }
00361 }
00362 
00363 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:20 for Jafar by doxygen 1.7.6.1
LAAS-CNRS