00001
00002
00003
00004
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
00034 vgl_point_2d<double> get_cur_epipole() const;
00035 vcl_vector<vnl_matrix<double> > get_back_projection() const;
00036
00037
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();
00044 bugl_curve_3d get_curve_3d();
00045
00046
00047 void read_data(const char* fname);
00048
00049
00050 vcl_vector<vdgl_digital_curve_sptr> read_tracker_file(char* fname);
00051
00052
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
00059
00060 kalman_filter();
00061 kalman_filter(const char* fname);
00062 virtual ~kalman_filter();
00063
00064 protected:
00065
00066 vcl_vector<double> read_timestamp_file(char* fname);
00067
00068
00069 double matched_point_prob(vnl_double_2& z, vnl_double_2& z_pred);
00070
00071
00072 vnl_matrix_fixed<double, 6, 6> get_transit_matrix(int i, int j);
00073
00074
00075 void update_confidence();
00076
00077
00078 void update_observes(const vnl_double_3x4 &P, int iframe);
00079 void init_velocity();
00080
00081
00082 vnl_matrix_fixed<double, 2, 6> get_H_matrix(vnl_double_3x4 &P, vnl_double_3 &Y);
00083
00084
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
00094 bugl_curve_3d curve_3d_;
00095
00096 vcl_vector<double> prob_;
00097
00098
00099 vcl_vector<vcl_vector<bugl_gaussian_point_2d<double> > > observes_;
00100
00101
00102 vcl_vector<double> time_tick_;
00103
00104 vcl_vector<vcl_vector<vdgl_digital_curve_sptr> > trackers_;
00105
00106 vcl_vector<vnl_double_3> motions_;
00107
00108 int cur_pos_;
00109 int queue_size_;
00110 int num_points_;
00111
00112
00113 int memory_size_;
00114
00115
00116 vnl_vector_fixed<double, 6> X_;
00117
00118
00119 vnl_matrix_fixed<double, 6, 6> Q_;
00120
00121
00122 vnl_matrix_fixed<double, 6, 2> G_;
00123
00124
00125 vnl_matrix_fixed<double, 2, 2> R_;
00126
00127
00128 vnl_matrix_fixed<double, 6, 6> Q0_;
00129
00130
00131 vnl_double_2* e_;
00132
00133
00134 vnl_double_3x3 K_;
00135
00136
00137 static const double large_num_;
00138 };
00139
00140 #endif // brct_kalman_filter_h_