00001 // This is gel/mrc/vpgl/algo/vpgl_fm_compute_reg_ransac.h 00002 #ifndef vpgl_fm_compute_reg_ransac_h_ 00003 #define vpgl_fm_compute_reg_ransac_h_ 00004 //: 00005 // \file 00006 // \brief Compute the fundamental matrix from rectified image correspondences. 00007 // 00008 // A robust algorithm for computing the fundamental matrix from lists 00009 // of corresponding points between two rectified images. This assumes the matched 00010 // points lie off of the ground plane. This uses RREL to do the robust computation. 00011 // \author Thomas Pollard 00012 // \date May 08, 2005 00013 // 00014 // Should template this class. 00015 00016 #include <vcl_vector.h> 00017 #include <vgl/vgl_fwd.h> 00018 #include <vnl/vnl_fwd.h> 00019 #include <rrel/rrel_estimation_problem.h> 00020 #include <vpgl/vpgl_reg_fundamental_matrix.h> 00021 00022 class vpgl_fm_compute_reg_ransac_params; 00023 00024 00025 //: This is the main class for computing the fundamental matrix from lists of corresponding points. 00026 class vpgl_fm_compute_reg_ransac 00027 { 00028 public: 00029 vpgl_fm_compute_reg_ransac( vpgl_fm_compute_reg_ransac_params* params){ 00030 params_ = params; } 00031 00032 //: Compute from two sets of corresponding points. 00033 // Put the resulting matrix into fm, return true if successful. 00034 // Points pr are associated with the RHS of the fundamental matrix 00035 // while the points pl are associated with the LHS. 00036 bool compute( const vcl_vector< vgl_point_2d<double> >& pr, 00037 const vcl_vector< vgl_point_2d<double> >& pl, 00038 vpgl_reg_fundamental_matrix<double>& fm ); 00039 00040 //: After "compute" this will have true in the indices determined to be outliers. 00041 vcl_vector<bool> outliers; 00042 00043 protected: 00044 vpgl_fm_compute_reg_ransac_params* params_; 00045 }; 00046 00047 00048 //: Class with parameters for the above class. 00049 class vpgl_fm_compute_reg_ransac_params 00050 { 00051 public: 00052 vpgl_fm_compute_reg_ransac_params(); 00053 00054 double max_outlier_frac; 00055 double desired_prob_good; 00056 int max_pops; 00057 int trace_level; 00058 double residual_thresh; 00059 }; 00060 00061 00062 //: This is a helper class for vpgl_fm_compute_ransac using rrel. 00063 class rrel_fm_reg_problem : public rrel_estimation_problem 00064 { 00065 public: 00066 //: Construct the problem object with two sets of corresponding points. 00067 // Points pr correspond to the RHS of the fundamental matrix, while the 00068 // points pl correspond to the LHS. 00069 rrel_fm_reg_problem( const vcl_vector< vgl_point_2d<double> > & pr, 00070 const vcl_vector< vgl_point_2d<double> > & pl ); 00071 00072 virtual ~rrel_fm_reg_problem() {} 00073 00074 // Total number of correspondences. 00075 unsigned int num_samples() const{ return pr_.size(); } 00076 00077 // The degrees of freedom in the residual. 00078 unsigned int residual_dof() const { return 4; } 00079 00080 // Generate a parameter estimate from a minimal sample. 00081 bool fit_from_minimal_set( const vcl_vector<int>& point_indices, 00082 vnl_vector<double>& params ) const; 00083 00084 // Compute unsigned fit residuals relative to the parameter estimate. 00085 void compute_residuals( const vnl_vector<double>& params, 00086 vcl_vector<double>& residuals ) const; 00087 00088 // Convert a fundamental matrix into a parameter vector. 00089 virtual void fm_to_params( const vpgl_reg_fundamental_matrix<double>& fm, 00090 vnl_vector<double>& p) const; 00091 00092 // Convert a parameter vector into a fundamental matrix. 00093 virtual void params_to_fm( const vnl_vector<double>& p, 00094 vpgl_reg_fundamental_matrix<double>& fm) const; 00095 00096 //: Weighted least squares parameter estimate. 00097 // The normalized covariance is not yet filled in. 00098 bool weighted_least_squares_fit( vnl_vector<double>& params, 00099 vnl_matrix<double>& norm_covar, 00100 const vcl_vector<double>* weights=0 ) const; 00101 00102 // Toggles detailed printing of computations. 00103 bool verbose; 00104 00105 protected: 00106 vcl_vector< vgl_point_2d<double> > pr_; 00107 vcl_vector< vgl_point_2d<double> > pl_; 00108 }; 00109 00110 #endif // vpgl_fm_compute_reg_ransac_h_
1.7.5.1