00001 #ifndef MMVL_MIMAS_HYPOTHESIS_FILTER
00002 #define MMVL_MIMAS_HYPOTHESIS_FILTER
00003
00004 #include <vector>
00005 #include <cassert>
00006 #include <cmath>
00007 #include <iostream>
00008 #include <boost/shared_ptr.hpp>
00009 #include <image.h>
00010
00011 #include "condensation.h"
00012 #include "no_compensation.h"
00013
00014 using std::vector;
00015 using std::cout;
00016 using std::cerr;
00017 using std::endl;
00018 using boost::shared_ptr;
00019
00020 namespace mimas{
00025 namespace hf{
00026 typedef boost::numeric::ublas::vector<float> Point;
00027
00028
00054 template<typename Hypothesis_T, typename Pixel_T>
00055 class hypothesis_filter_data{
00056 public:
00057 image<Pixel_T> image;
00058 std::vector<Hypothesis_T > hypotheses;
00059 };
00060
00061
00133 template <
00134 template <typename> class image_loader_P,
00135 template <typename, typename> class Observer_P,
00136 template<typename, typename> class Analyse_result_T,
00137 typename Hypothesis_T,
00138 template <typename> class Picking_P = condensation,
00139 template <typename> class Compensate_P = no_compensation,
00140 typename Pixel_T = unsigned char
00141 >
00142 class hypothesis_filter:
00143 public hypothesis_filter_data<Hypothesis_T, Pixel_T>,
00144 public image_loader_P<Pixel_T>,
00145 public Observer_P<Hypothesis_T, Pixel_T>,
00146 public Analyse_result_T<Hypothesis_T, Pixel_T>,
00147 public Picking_P<Hypothesis_T>,
00148 public Compensate_P<Hypothesis_T>
00149 {
00150 public:
00152
00153 double max_weight(void);
00154
00160 void track(void)
00161 {
00162 while(true){
00163 try{image_loader_P<Pixel_T>::next();}
00164 catch (mimasexception){return;}
00165
00166 Hypothesis_T estimatedLocation;
00167 filter();
00168 estimatedLocation = Analyse_result_T<Hypothesis_T, Pixel_T>::analyse();
00169
00170 std::cerr<<"estim: "
00171 <<estimatedLocation.x
00172 <<estimatedLocation.y
00173 <<std::endl;
00174
00175 draw(estimatedLocation);
00176 save_location(estimatedLocation);
00177 }
00178 }
00179
00180
00185 void reset(Hypothesis_T &init);
00186
00191 void filter(void);
00192
00194 hypothesis_filter(Hypothesis_T &initial,
00195 int n,
00196 typename image_loader_P<Pixel_T>::set il_param,
00197 typename Observer_P<Hypothesis_T, Pixel_T>::set obs_param,
00198 typename Analyse_result_T<Hypothesis_T, Pixel_T>::set analyse_param)
00199 :image_loader_P<Pixel_T>(hypothesis_filter_data<Hypothesis_T, Pixel_T>::image,il_param),
00200 Observer_P<Hypothesis_T, Pixel_T>(hypothesis_filter_data<Hypothesis_T, Pixel_T>::image, obs_param),
00201 Analyse_result_T<Hypothesis_T, Pixel_T>(hypothesis_filter_data<Hypothesis_T, Pixel_T>::hypotheses, hypothesis_filter_data<Hypothesis_T, Pixel_T>::image, analyse_param),
00202 Picking_P<Hypothesis_T>(hypothesis_filter_data<Hypothesis_T, Pixel_T>::hypotheses),
00203 nb_hypothesis(n)
00204 {
00205 for(int i = 0; i < n; ++i)
00206 hypothesis_filter_data<Hypothesis_T, Pixel_T>::hypotheses.push_back(initial.drift());
00207 };
00208
00209
00210 hypothesis_filter(Hypothesis_T &initial,
00211 int n,
00212 typename image_loader_P<Pixel_T>::set il_param)
00213 :image_loader_P<Pixel_T>(hypothesis_filter_data<Hypothesis_T, Pixel_T>::image,il_param),
00214 Observer_P<Hypothesis_T, Pixel_T>(hypothesis_filter_data<Hypothesis_T, Pixel_T>::image, typename Observer_P<Hypothesis_T, Pixel_T>::set()),
00215 Analyse_result_T<Hypothesis_T, Pixel_T>(hypothesis_filter_data<Hypothesis_T, Pixel_T>::hypotheses, hypothesis_filter_data<Hypothesis_T, Pixel_T>::image, typename Analyse_result_T<Hypothesis_T, Pixel_T>::set()),
00216 Picking_P<Hypothesis_T>(hypothesis_filter_data<Hypothesis_T, Pixel_T>::hypotheses),
00217 nb_hypothesis(n)
00218 {
00219 for(int i = 0; i < n; ++i)
00220 hypothesis_filter_data<Hypothesis_T, Pixel_T>::hypotheses.push_back(initial.drift());
00221 };
00222
00223 ~hypothesis_filter(){}
00224 protected:
00227 int nb_hypothesis;
00228
00229 private:
00230
00231 vector<Hypothesis_T> hypotheses_new;
00232
00233 void reset_hypothesis(const Hypothesis_T & init);
00234 void update(void);
00235 };
00236
00237 #include "hypothesis_filter.tcc"
00238 }
00239 }
00240 #endif
00241
00242
00243
00244
00245
00246
00247
00248
00249