contrib/oxl/mvl/FMatrixCompute7Point.h
Go to the documentation of this file.
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 defence 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 public:
00037   //: Initialize FMatrixCompute7Point object.
00038   //  If precondition = false, points are not conditioned prior to computation.
00039   // If rank2_truncate = false, the resulting solution is not forced to rank 2
00040   // using the vnl_svd<double>.
00041   FMatrixCompute7Point(bool precondition = true, bool rank2_truncate = true);
00042 
00043   // Computations--------------------------------------------------------------
00044 
00045   //: Compute a fundamental matrix for a set of point matches.
00046   // Return false if the calculation fails or there are fewer than seven point
00047   // matches in the list.
00048   //
00049   bool compute(PairMatchSetCorner&, vcl_vector<FMatrix*>&);
00050 
00051   //: Interface to above using arrays of HomgPoint2D.
00052   //  Makes a PairMatchSetCorner, and then calls the compute method above.
00053   bool compute(vcl_vector<HomgPoint2D>&, vcl_vector<HomgPoint2D>&, vcl_vector<FMatrix*>&);
00054 
00055   //: Interface to above using arrays of vgl_homg_point_2d.
00056   //  Makes a PairMatchSetCorner, and then calls the compute method with PairMatchSetCorner argument.
00057   bool compute(vcl_vector<vgl_homg_point_2d<double> >& points1,
00058                vcl_vector<vgl_homg_point_2d<double> >& points2,
00059                vcl_vector<FMatrix*>&);
00060 
00061   //: Interface to above using preconditioned points
00062   bool compute_preconditioned(vcl_vector<HomgPoint2D>&, vcl_vector<HomgPoint2D>&, vcl_vector<FMatrix*>&);
00063 
00064   //: Interface to above using preconditioned points
00065   bool compute_preconditioned(vcl_vector<vgl_homg_point_2d<double> >& points1,
00066                               vcl_vector<vgl_homg_point_2d<double> >& points2,
00067                               vcl_vector<FMatrix*>&);
00068 
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_