Go to the documentation of this file.00001
00002 #include "FMatrixComputeMLESAC.h"
00003 #include <mvl/FManifoldProject.h>
00004 #include <mvl/HomgOperator2D.h>
00005 #include <vgl/vgl_homg_point_2d.h>
00006 #include <vgl/vgl_homg_line_2d.h>
00007 #include <vgl/algo/vgl_homg_operators_2d.h>
00008
00009 FMatrixComputeMLESAC::FMatrixComputeMLESAC(bool rank2_truncate, double std)
00010 {
00011 rank2_truncate_ = rank2_truncate,
00012 std_ = std;
00013 inthresh_ = (1.96*std_)*(1.96*std_);
00014 }
00015
00016 FMatrixComputeMLESAC::~FMatrixComputeMLESAC() {}
00017
00018
00019 double FMatrixComputeMLESAC::calculate_term(vcl_vector<double>& residuals, vcl_vector<bool>& inlier_list, int& count)
00020 {
00021 double sse = 0.0;
00022 for (unsigned int i = 0; i < residuals.size(); i++) {
00023 if (residuals[i] < inthresh_) {
00024 inlier_list[i] = true;
00025 sse += residuals[i];
00026 count++;
00027 } else {
00028 inlier_list[i] = false;
00029 sse += inthresh_;
00030 }
00031 }
00032 return sse;
00033 }
00034
00035
00036
00037 double FMatrixComputeMLESAC::calculate_residual(vgl_homg_point_2d<double>& one,
00038 vgl_homg_point_2d<double>& two,
00039 FMatrix* F)
00040 {
00041 vgl_homg_line_2d<double> l1 = F->image2_epipolar_line(one);
00042 vgl_homg_line_2d<double> l2 = F->image1_epipolar_line(two);
00043 return vgl_homg_operators_2d<double>::perp_dist_squared(two, l1)
00044 + vgl_homg_operators_2d<double>::perp_dist_squared(one, l2);
00045 }
00046
00047
00048
00049 double FMatrixComputeMLESAC::calculate_residual(HomgPoint2D& one, HomgPoint2D& two, FMatrix* F)
00050 {
00051
00052
00053
00054
00055 #if 0
00056 double r = 0.0;
00057 vnl_double_3x3 matrix = F->get_matrix();
00058 double const* const* mat = matrix.data_array();
00059
00060 vnl_double_2 p1 = one.get_nonhomogeneous();
00061 vnl_double_2 p2 = two.get_nonhomogeneous();
00062 double a11 = mat[0][0]*p1[0] + mat[1][0]*p1[1] + mat[2][0];
00063 double a12 = mat[0][1]*p1[0] + mat[1][1]*p1[1] + mat[2][1];
00064 double b11 = mat[0][0]*p2[0] + mat[0][1]*p2[1] + mat[0][2];
00065 double b12 = mat[1][0]*p2[0] + mat[1][1]*p2[1] + mat[1][2];
00066 #endif
00067 HomgLine2D l1 = F->image2_epipolar_line(one);
00068 HomgLine2D l2 = F->image1_epipolar_line(two);
00069 double ret = HomgOperator2D::perp_dist_squared(two, l1)
00070 + HomgOperator2D::perp_dist_squared(one, l2);
00071
00072 #if 0
00073 double factor = a11*a11 + a12*a12 + b11*b11 + b12*b12;
00074 if (factor < 0.1)
00075 factor = 0.1;
00076
00077 ret /= factor;
00078
00079 r += ret*b11;
00080 r += ret*b12;
00081 r += ret*a11;
00082 r += ret*a12;
00083 #endif
00084 return ret;
00085 }