Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

brct_epi_reconstructor.h

Go to the documentation of this file.
00001 #ifndef brct_epi_reconstructor_h_
00002 #define brct_epi_reconstructor_h_
00003 
00004 #if defined(_MSC_VER) && ( _MSC_VER > 1000 )
00005 #pragma once
00006 #endif // _MSC_VER > 1000
00007 //:
00008 // \file
00009 // \brief A class to attack structure from motion problem
00010 //
00011 //  Input:
00012 //  -  A set of tracked vdgl_digital_curve(s). Currently these
00013 //     curves are read in from a track file, which is generated by
00014 //     a 2-d tracking algorithm. The tracks are stored in tracks_.
00015 //  -  A timestamp file that gives the observation time for each frame
00016 //     in milliseconds.
00017 //  -  The calibration matrix K_ for the camera.  Currently this
00018 //     matrix is hard-coded in ::init_cam_intrinsic()
00019 //  -  Initial epipole image location e_, a 2-d point.
00020 //
00021 //  Internals:
00022 //   The camera translation is computed from the matched curves and an
00023 //   assumed epipolar geometry.  This class is a heavily modified version
00024 //   of the original Kalman filter class written by Kongbin Kang.
00025 //
00026 // \author J.L. Mundy
00027 // \verbatim
00028 //  Modifications
00029 //   Initial version Dec. 2003
00030 //   The class doe
00031 // \endverbatim
00032 //
00033 //////////////////////////////////////////////////////////////////////
00034 
00035 #include <vcl_vector.h>
00036 #include <vnl/vnl_double_2.h>
00037 #include <vnl/vnl_double_3.h>
00038 #include <vnl/vnl_double_3x3.h>
00039 #include <vnl/vnl_double_3x4.h>
00040 #include <vnl/vnl_vector_fixed.h>
00041 #include <vnl/vnl_matrix_fixed.h>
00042 #include <vnl/vnl_matrix.h>
00043 #include <vdgl/vdgl_digital_curve_sptr.h>
00044 #include <bugl/bugl_gaussian_point_2d.h>
00045 #include <vgl/vgl_point_3d.h>
00046 #include <bugl/bugl_curve_3d.h>
00047 
00048 class brct_epi_reconstructor
00049 {
00050  public:
00051 
00052   //: write result of a frame into a file
00053   void write_results(const char* fname);
00054   vgl_point_2d<double> get_cur_epipole() const;
00055   //: get backprojection for debugging
00056   vcl_vector<vnl_matrix<double> > get_back_projection() const;
00057 
00058   //: predict next curve.
00059   vnl_matrix<double> get_predicted_curve();
00060   vnl_double_3 get_next_motion(vnl_double_3 v);
00061   vcl_vector<vgl_point_2d<double> > get_pre_observes();
00062   vcl_vector<vgl_point_2d<double> > get_cur_observes();
00063   vcl_vector<vgl_point_2d<double> > get_next_observes();
00064   //joe version
00065   vcl_vector<vgl_point_2d<double> > get_joe_pre_observes();
00066   vcl_vector<vgl_point_2d<double> > get_joe_cur_observes();
00067   vcl_vector<vgl_point_2d<double> > get_joe_next_observes();
00068 
00069 
00070   vcl_vector<vgl_point_3d<double> > get_local_pts(); // will be superseded
00071   bugl_curve_3d get_curve_3d();
00072 
00073   //: read all the data including time stamps and  tracks.
00074   void read_data(const char* fname);
00075 
00076   //: read vishual tracker result out of a file
00077   vcl_vector<vdgl_digital_curve_sptr> read_track_file(char* fname);
00078 
00079 
00080   //: initialize the kalman filter states
00081   void init();
00082   void init_epipole(double x, double y);
00083   void inc();
00084   vnl_double_2 projection(const vnl_double_3x4 &P, const vnl_double_3 &X);
00085 
00086   //: constructors
00087   //
00088   brct_epi_reconstructor();
00089   brct_epi_reconstructor(const char* fname);
00090   virtual ~brct_epi_reconstructor();
00091 
00092   //: direct access
00093   void add_track(vcl_vector<vdgl_digital_curve_sptr> const& track);
00094 
00095   //: print track data
00096   void print_track(const int track_index, const int frame);
00097 
00098   //: print motion grouping histogram
00099   void print_motion_array();
00100  protected:
00101   //: read time stamp
00102   vcl_vector<double> read_timestamp_file(char* fname);
00103 
00104   //: if the zero probability returned, the matched point is a outlier
00105   double matched_point_prob(vnl_double_2& z, vnl_double_2& z_pred);
00106 
00107   //: get time interval from ith frame to j-th frame
00108   vnl_matrix_fixed<double, 6, 6> get_transit_matrix(int i, int j);
00109 
00110   //: update the confidence for each 3d point
00111   void update_confidence();
00112 
00113   //: update the matched points in the next frame using closest neighbour.
00114   void update_observes(const vnl_double_3x4 &P, int iframe);
00115   void update_observes_joe(int iframe);
00116   void init_velocity();
00117 
00118   //: set linearized observation matrix
00119   vnl_matrix_fixed<double, 2, 6> get_H_matrix(vnl_double_3x4 &P, vnl_double_3 &Y);
00120 
00121   //: compute projective matrix from predicted position
00122   vnl_double_3x4 get_projective_matrix(const vnl_double_3 &v) const;
00123 
00124   void init_covariant_matrix();
00125   void init_cam_intrinsic();
00126   void init_state_3d_estimation();
00127   void init_transit_matrix();
00128 
00129   //: utility functions
00130   bool match_point(vdgl_digital_curve_sptr const& dc,
00131                    bugl_gaussian_point_2d<double>& p0,
00132                    double grad_angle,
00133                    bugl_gaussian_point_2d<double>& p);
00134 
00135   vcl_vector<bugl_gaussian_point_2d<double> >
00136     get_cur_joe_observes(int frame);
00137  private:
00138    //: position and confidence of feature samples
00139   bugl_curve_3d curve_3d_;
00140 
00141   vcl_vector<double> prob_;
00142 
00143   //: the set of 2-d points in each frame, used for matching
00144   vcl_vector<vcl_vector<bugl_gaussian_point_2d<double> > > observes_;
00145 
00146   //: the set of 2-d points in each frame grouped by tracked curves
00147   vcl_vector<vcl_vector<vcl_vector<bugl_gaussian_point_2d<double> > > > joe_observes_;
00148 
00149   //: the gradient angles corresponding to frame 0 matched tracked curves
00150   vcl_vector<vcl_vector<double> > grad_angles_;
00151 
00152   //: each element represents image capture time for each frame.
00153   vcl_vector<double> time_tick_;
00154 
00155   //: each element of the vector represents a projection of the same 3D curves.
00156   vcl_vector<vcl_vector<vdgl_digital_curve_sptr> > tracks_;
00157 
00158   //: the sequence of translations
00159   vcl_vector<vnl_double_3> motions_;
00160 
00161   //: current frame position in history pool
00162   int cur_pos_;
00163   int queue_size_;
00164   int num_points_;
00165 
00166   //: how much the queue has been used
00167   int memory_size_;
00168 
00169   //: state vector
00170   vnl_vector_fixed<double, 6> X_;
00171 
00172   //: covariant matrix of state vector
00173   vnl_matrix_fixed<double, 6, 6> Q_;
00174 
00175   //: constraint kalman gain matrix
00176   vnl_matrix_fixed<double, 6, 2> G_;
00177 
00178   //: initial covariant matrix of state vector
00179   vnl_matrix_fixed<double, 2, 2> R_;
00180 
00181   //: covariant matrix of 2D projection
00182   vnl_matrix_fixed<double, 6, 6> Q0_;
00183 
00184   //: initial epipole
00185   vnl_double_2* e_;
00186 
00187   //: camera intrinsic parameters
00188   vnl_double_3x3 K_;
00189 
00190   //: used to denote outlier point in image
00191   static const double large_num_;
00192   //: debug flag
00193   bool debug_;
00194 };
00195 
00196 #endif // brct_epi_reconstructor_h_

Generated on Thu Jan 10 14:54:03 2008 for contrib/brl/bmvl/brct by  doxygen 1.4.4