contrib/brl/bmvl/brct/kalman_filter.h

Go to the documentation of this file.
00001 //:
00002 // \file
00003 // \author Kongbin Kang
00004 // \brief A class to attack structure from motion problem
00005 //
00006 //////////////////////////////////////////////////////////////////////
00007 
00008 #ifndef brct_kalman_filter_h_
00009 #define brct_kalman_filter_h_
00010 
00011 #if defined(_MSC_VER) && ( _MSC_VER > 1000 )
00012 #pragma once
00013 #endif // _MSC_VER > 1000
00014 
00015 #include <vcl_vector.h>
00016 #include <vnl/vnl_double_2.h>
00017 #include <vnl/vnl_double_3.h>
00018 #include <vnl/vnl_double_3x3.h>
00019 #include <vnl/vnl_double_3x4.h>
00020 #include <vnl/vnl_vector_fixed.h>
00021 #include <vnl/vnl_matrix_fixed.h>
00022 #include <vnl/vnl_matrix.h>
00023 #include <vdgl/vdgl_digital_curve_sptr.h>
00024 #include <bugl/bugl_gaussian_point_2d.h>
00025 #include <vgl/vgl_point_2d.h>
00026 #include <vgl/vgl_point_3d.h>
00027 #include <bugl/bugl_curve_3d.h>
00028 
00029 class kalman_filter
00030 {
00031  public:
00032 
00033   //: get backprojection for debugging
00034   vgl_point_2d<double> get_cur_epipole() const;
00035   vcl_vector<vnl_matrix<double> > get_back_projection() const;
00036 
00037   //: predict next curve.
00038   vnl_matrix<double> get_predicted_curve();
00039   vnl_double_3 get_next_motion(vnl_double_3 v);
00040   vcl_vector<vgl_point_2d<double> > get_pre_observes();
00041   vcl_vector<vgl_point_2d<double> > get_cur_observes();
00042   vcl_vector<vgl_point_2d<double> > get_next_observes();
00043   vcl_vector<vgl_point_3d<double> > get_local_pts(); // will be superseded
00044   bugl_curve_3d get_curve_3d();
00045 
00046   //: read all the data including time stampes, trackers.
00047   void read_data(const char* fname);
00048 
00049   //: read vishual tracker result out of a file
00050   vcl_vector<vdgl_digital_curve_sptr> read_tracker_file(char* fname);
00051 
00052   //: initialize the kalman filter states
00053   void init();
00054   void init_epipole(double x, double y);
00055   void inc();
00056   vnl_double_2 projection(const vnl_double_3x4 &P, const vnl_double_3 &X);
00057 
00058   //: constructors
00059   //
00060   kalman_filter();
00061   kalman_filter(const char* fname);
00062   virtual ~kalman_filter();
00063 
00064  protected:
00065   //: read time stamp
00066   vcl_vector<double> read_timestamp_file(char* fname);
00067 
00068   //: if the zero probability returned, the matched point is a outlier
00069   double matched_point_prob(vnl_double_2& z, vnl_double_2& z_pred);
00070 
00071   //: get time interval from ith frame to j-th frame
00072   vnl_matrix_fixed<double, 6, 6> get_transit_matrix(int i, int j);
00073 
00074   //: update the confidence for each 3d point
00075   void update_confidence();
00076 
00077   //: update the matched points in the next frame using closest neighbour.
00078   void update_observes(const vnl_double_3x4 &P, int iframe);
00079   void init_velocity();
00080 
00081   //: set linearized observation matrix
00082   vnl_matrix_fixed<double, 2, 6> get_H_matrix(vnl_double_3x4 &P, vnl_double_3 &Y);
00083 
00084   //: compute projective matrix from predicted position
00085   vnl_double_3x4 get_projective_matrix(const vnl_double_3 &v) const;
00086 
00087   void init_covariant_matrix();
00088   void init_cam_intrinsic();
00089   void init_state_3d_estimation();
00090   void init_transit_matrix();
00091 
00092  private:
00093    //: position and confidence of feature samples
00094   bugl_curve_3d curve_3d_;
00095 
00096   vcl_vector<double> prob_;
00097 
00098   //: used for matching point
00099   vcl_vector<vcl_vector<bugl_gaussian_point_2d<double> > > observes_;
00100 
00101   //: each element represents shooting times for this frame.
00102   vcl_vector<double> time_tick_;
00103   //: each element of the vector represents a projection of the same 3D curves.
00104   vcl_vector<vcl_vector<vdgl_digital_curve_sptr> > trackers_;
00105 
00106   vcl_vector<vnl_double_3> motions_;
00107   //: current frame position in history pool
00108   int cur_pos_;
00109   int queue_size_;
00110   int num_points_;
00111 
00112   //: how much the queue has been used
00113   int memory_size_;
00114 
00115   //: state vector
00116   vnl_vector_fixed<double, 6> X_;
00117 
00118   //: covariant matrix of state vector
00119   vnl_matrix_fixed<double, 6, 6> Q_;
00120 
00121   //: constraint kalman gain matrix
00122   vnl_matrix_fixed<double, 6, 2> G_;
00123 
00124   //: initial covariant matrix of state vector
00125   vnl_matrix_fixed<double, 2, 2> R_;
00126 
00127   //: covariant matrix of 2D projection
00128   vnl_matrix_fixed<double, 6, 6> Q0_;
00129 
00130   //: initial epipole
00131   vnl_double_2* e_;
00132 
00133   //: camera intrinsic parameters
00134   vnl_double_3x3 K_;
00135 
00136   //: used to denote outlier point in image
00137   static const double large_num_;
00138 };
00139 
00140 #endif // brct_kalman_filter_h_

Generated on Fri Nov 21 05:24:04 2008 for contrib/brl/bmvl/brct by  doxygen 1.5.1