Go to the documentation of this file.00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006 #include "HMatrix2DEuclideanCompute.h"
00007
00008 #include <vcl_cassert.h>
00009
00010 #include <vnl/vnl_double_2.h>
00011 #include <vnl/vnl_double_2x2.h>
00012 #include <vnl/vnl_double_3x3.h>
00013 #include <vnl/vnl_transpose.h>
00014 #include <vnl/algo/vnl_svd.h>
00015
00016 #include <mvl/HMatrix2D.h>
00017 #include <mvl/PairMatchSetCorner.h>
00018 #include <mvl/HMatrix2DAffineCompute.h>
00019
00020
00021
00022
00023 HMatrix2DEuclideanCompute::HMatrix2DEuclideanCompute(void) : HMatrix2DCompute() { }
00024
00025 HMatrix2DEuclideanCompute::~HMatrix2DEuclideanCompute() { }
00026
00027
00028
00029
00030 HMatrix2D
00031 HMatrix2DEuclideanCompute::compute(PairMatchSetCorner const& matches)
00032 {
00033 PointArray pts1(matches.count());
00034 PointArray pts2(matches.count());
00035 matches.extract_matches(pts1, pts2);
00036 HMatrix2D H;
00037 tmp_fun(pts1,pts2,&H);
00038 return H;
00039 }
00040
00041 HMatrix2D
00042 HMatrix2DEuclideanCompute::compute(PointArray const& p1,
00043 PointArray const& p2)
00044 {
00045 HMatrix2D H;
00046 tmp_fun(p1,p2,&H);
00047 return H;
00048 }
00049
00050 bool
00051 HMatrix2DEuclideanCompute::compute_p(PointArray const& pts1,
00052 PointArray const& pts2,
00053 HMatrix2D *H)
00054 {
00055 return tmp_fun(pts1,pts2,H);
00056 }
00057
00058 bool
00059 HMatrix2DEuclideanCompute::tmp_fun(PointArray const& pts1,
00060 PointArray const& pts2,
00061 HMatrix2D *H)
00062 {
00063 assert(pts1.size() == pts2.size());
00064
00065 NonHomg p1(pts1);
00066 NonHomg p2(pts2);
00067 vnl_double_2 mn1 = ::mean2(p1);
00068 vnl_double_2 mn2 = ::mean2(p2);
00069 sub_rows(p1,mn1);
00070 sub_rows(p2,mn2);
00071
00072 vnl_double_2x2 scatter = vnl_transpose(p2)*p1;
00073 vnl_svd<double> svd(scatter.as_ref());
00074
00075 vnl_double_2x2 R = svd.U() * vnl_transpose(svd.V());
00076 vnl_double_2 t = mn2 - R * mn1;
00077
00078 vnl_double_3x3 T;
00079 T(0,0) = R(0,0); T(0,1) = R(0,1); T(0,2) = t[0];
00080 T(1,0) = R(1,0); T(1,1) = R(1,1); T(1,2) = t[1];
00081 T(2,0) = 0.0; T(2,1) = 0.0; T(2,2) = 1.0;
00082 H->set(T);
00083 return true;
00084 }