00001 #ifndef GFM_CAM_SHIFT_TRACKER
00002 #define GFM_CAM_SHIFT_TRACKER
00003
00004 #include "fdetect/RealDescriptor.hpp"
00005 #include "gfm/EngineTracking.hpp"
00006 #include "gfm/DescriptorsBasedMatcher.hpp"
00007 #include "opencv2/video/tracking.hpp"
00008 namespace jafar {
00009 namespace gfm_v2 {
00010
00016 class CamShiftTracker :
00017 public gfm_v2::EngineTracking<fdetect_v2::InterestFeature<fdetect_v2::FloatDescriptor> > {
00018
00019 public:
00020 typedef fdetect_v2::InterestFeature<fdetect_v2::FloatDescriptor> Feature;
00021 typedef Feature::DescriptorType Descriptor;
00022 typedef fdetect_v2::DetectionResult< Feature > DR;
00023 typedef gfm_v2::MatchingResult< Feature > MR;
00024 typedef gfm_v2::MatchSourceInfo< Feature > MatchSourceInfo;
00025 typedef gfm_v2::DescriptorsBasedMatcher< Feature > DescriptorsBasedMatcher;
00031 CamShiftTracker(jafar::fdetect_v2::Detector<Feature>* detector,
00032 size_t ransac_required = 7) :
00033 gfm_v2::EngineTracking<Feature>(detector, new DescriptorsBasedMatcher(2,20,0.8,false), 0), m_ransac_required(ransac_required) { }
00038 void initTracking(jafar::image::Image const& model_image,
00039 unsigned int id = geom::InterestPoint::NO_ID)
00040 {
00041 EngineTracking<Feature>::initTracking(model_image, image::Image(), id);
00042 }
00047 void initTracking(DR &model_points,
00048 unsigned int id = geom::InterestPoint::NO_ID)
00049 {
00050 EngineTracking<Feature>::initTracking(model_points, id);
00051 }
00060 ublas::matrix<float> nextImage(jafar::image::Image const& image_next,
00061 jafar::image::Image const& prior_mask,
00062 cv::RotatedRect *init_region = NULL,
00063 unsigned int id = geom::InterestPoint::NO_ID)
00064 {
00065 JFR_ASSERT(prior_mask.size() == image_next.size(),
00066 "mask and image must be of same size")
00067 DR observed_points = m_detector->detectIn(image_next);
00068 return this->nextImage(observed_points, prior_mask, init_region, id);
00069 }
00070
00071 ublas::matrix<float> nextImage(DR& observed_points,
00072 jafar::image::Image const& prior_mask,
00073 cv::RotatedRect *init_region = NULL,
00074 unsigned int id = geom::InterestPoint::NO_ID);
00076 MR result() { return m_result; }
00077 private:
00079 size_t m_ransac_required;
00081 MR m_result;
00082 inline bool is_valid_homography(const ublas::matrix<float>& h, double det_threshold);
00083 };
00084 }
00085 }
00086
00087 #endif