Go to the documentation of this file.00001
00002 #include "FMatrixComputeRANSAC.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 FMatrixComputeRANSAC::FMatrixComputeRANSAC(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 FMatrixComputeRANSAC::~FMatrixComputeRANSAC() {}
00017
00018 double FMatrixComputeRANSAC::calculate_term(vcl_vector<double>& residuals, vcl_vector<bool>& inlier_list, int& count)
00019 {
00020 count = 0;
00021 for (unsigned int i = 0; i < residuals.size(); i++) {
00022 if (residuals[i] < inthresh_) {
00023 inlier_list[i] = true;
00024 count++;
00025 } else
00026 inlier_list[i] = false;
00027 }
00028 return (double)(residuals.size() - count);
00029 }
00030
00031 double FMatrixComputeRANSAC::calculate_residual(vgl_homg_point_2d<double>& one,
00032 vgl_homg_point_2d<double>& two,
00033 FMatrix* F)
00034 {
00035 vgl_homg_line_2d<double> l1 = F->image2_epipolar_line(one);
00036 vgl_homg_line_2d<double> l2 = F->image1_epipolar_line(two);
00037 return vgl_homg_operators_2d<double>::perp_dist_squared(two, l1)
00038 + vgl_homg_operators_2d<double>::perp_dist_squared(one, l2);
00039 }
00040
00041 double FMatrixComputeRANSAC::calculate_residual(HomgPoint2D& one, HomgPoint2D& two, FMatrix* F)
00042 {
00043 #if 0
00044 double r = 0.0;
00045
00046
00047
00048 vnl_double_3x3 matrix = F->get_matrix();
00049 double const* const* mat = matrix.data_array();
00050
00051 vnl_double_2 p1 = one.get_nonhomogeneous();
00052 vnl_double_2 p2 = two.get_nonhomogeneous();
00053 double a11 = mat[0][0]*p1[0] + mat[1][0]*p1[1] + mat[2][0];
00054 double a12 = mat[0][1]*p1[0] + mat[1][1]*p1[1] + mat[2][1];
00055 double b11 = mat[0][0]*p2[0] + mat[0][1]*p2[1] + mat[0][2];
00056 double b12 = mat[1][0]*p2[0] + mat[1][1]*p2[1] + mat[1][2];
00057 #endif
00058 HomgLine2D l1 = F->image2_epipolar_line(one);
00059 HomgLine2D l2 = F->image1_epipolar_line(two);
00060 double ret = HomgOperator2D::perp_dist_squared(two, l1)
00061 + HomgOperator2D::perp_dist_squared(one, l2);
00062
00063 #if 0
00064 double factor = a11*a11 + a12*a12 + b11*b11 + b12*b12;
00065 if (factor < 0.1)
00066 factor = 0.1;
00067
00068 ret /= factor;
00069
00070 r += ret*b11;
00071 r += ret*b12;
00072 r += ret*a11;
00073 r += ret*a12;
00074 #endif
00075 return ret;
00076 }