00001 #ifndef FMatrixCompute7Point_h_ 00002 #define FMatrixCompute7Point_h_ 00003 //: 00004 // \file 00005 // \brief SVD 7 Point F Matrix Fit 00006 // 00007 // FMatrixCompute7Point implements the `7-point' estimation 00008 // of the fundamental matrix. 00009 // 00010 // Points are preconditioned as described in [Hartley, ``In defense of 00011 // the 8-point algorithm'', ICCV95], and the resulting F matrix is rank-2 00012 // truncated. The conditioning and truncation are optional and may be 00013 // omitted. 00014 // 00015 // The root finder is adapted from Phil Torr's code for the FMatrix 00016 // which was in turn adapted from numerical recipes in C. 00017 // 00018 // Note: As with any nonrobust algorithm, mismatches in the input data 00019 // may severely effect the result. 00020 // 00021 // \author 00022 // David N. McKinnon, UQ I.R.I.S., 25 Nov 2000 00023 // 00024 // \verbatim 00025 // Modifications 00026 // 22 Oct 2002 - Peter Vanroose - added vgl_homg_point_2d interface 00027 // \endverbatim 00028 // 00029 //----------------------------------------------------------------------------- 00030 #include <mvl/FMatrix.h> 00031 #include <vcl_vector.h> 00032 #include <mvl/PairMatchSetCorner.h> 00033 #include <vgl/vgl_homg_point_2d.h> 00034 00035 class FMatrixCompute7Point 00036 { 00037 public: 00038 //: Initialize FMatrixCompute7Point object. 00039 // If precondition = false, points are not conditioned prior to computation. 00040 // If rank2_truncate = false, the resulting solution is not forced to rank 2 00041 // using the vnl_svd<double>. 00042 FMatrixCompute7Point(bool precondition = true, bool rank2_truncate = true); 00043 00044 // Computations-------------------------------------------------------------- 00045 00046 //: Compute a fundamental matrix for a set of point matches. 00047 // Return false if the calculation fails or there are fewer than seven point 00048 // matches in the list. 00049 // 00050 bool compute(PairMatchSetCorner&, vcl_vector<FMatrix*>&); 00051 00052 //: Interface to above using arrays of HomgPoint2D. 00053 // Makes a PairMatchSetCorner, and then calls the compute method above. 00054 bool compute(vcl_vector<HomgPoint2D>&, vcl_vector<HomgPoint2D>&, vcl_vector<FMatrix*>&); 00055 00056 //: Interface to above using arrays of vgl_homg_point_2d. 00057 // Makes a PairMatchSetCorner, and then calls the compute method with PairMatchSetCorner argument. 00058 bool compute(vcl_vector<vgl_homg_point_2d<double> >& points1, 00059 vcl_vector<vgl_homg_point_2d<double> >& points2, 00060 vcl_vector<FMatrix*>&); 00061 00062 //: Interface to above using preconditioned points 00063 bool compute_preconditioned(vcl_vector<HomgPoint2D>&, vcl_vector<HomgPoint2D>&, vcl_vector<FMatrix*>&); 00064 00065 //: Interface to above using preconditioned points 00066 bool compute_preconditioned(vcl_vector<vgl_homg_point_2d<double> >& points1, 00067 vcl_vector<vgl_homg_point_2d<double> >& points2, 00068 vcl_vector<FMatrix*>&); 00069 protected: 00070 static vcl_vector<double> GetCoef(FMatrix const& F1, FMatrix const& F2); 00071 static vcl_vector<double> solve_quadratic(vcl_vector<double> v); 00072 static vcl_vector<double> solve_cubic(vcl_vector<double> v); 00073 00074 bool precondition_; 00075 bool rank2_truncate_; 00076 }; 00077 00078 #endif // FMatrixCompute7Point_h_