contrib/oxl/mvl/HMatrix2DCompute4Point.cxx
Go to the documentation of this file.
00001 #include "HMatrix2DCompute4Point.h"
00002 
00003 #include <mvl/HMatrix2D.h>
00004 #include <mvl/ProjectiveBasis2D.h>
00005 
00006 //-----------------------------------------------------------------------------
00007 
00008 //:
00009 //  \file
00010 // \brief Compute a plane-plane projectivity using linear least squares.
00011 //
00012 // Returns false if the calculation fails or there are fewer than four point
00013 // matches in the list.
00014 //
00015 
00016 
00017 //-----------------------------------------------------------------------------
00018 //
00019 //: Compute a plane-plane projectivity using 4 point correspondences.
00020 // Returns false if the calculation fails or there are fewer than four point
00021 // matches in the list.
00022 //
00023 // The algorithm determines the transformation $H_i$ from each pointset to the
00024 // canonical projective basis (see the \b ProjectiveBasis2D class), and
00025 // returns the combined transform $H = H_2^{-1} H_1$.
00026 
00027 bool
00028 HMatrix2DCompute4Point::compute_p(PointArray const& points1,
00029                                   PointArray const& points2,
00030                                   HMatrix2D *H)
00031 {
00032   ProjectiveBasis2D basis1(points1);
00033   if ( basis1.collinear() ) return false;
00034   ProjectiveBasis2D basis2(points2);
00035   if ( basis2.collinear() ) return false;
00036 
00037   H->set(basis2.get_T().get_inverse().get_matrix() * basis1.get_T_matrix());
00038   return true;
00039 }