11 #include <vnl/algo/vnl_svd.h> 13 # include <vcl_msvc_warnings.h> 28 vnl_matrix<double>& M)
30 int n = static_cast<int>(p1.size());
33 vnl_matrix<double> b(n*3, 1);
36 for (
int i = 0; i < n; i++) {
39 double X1 = hp1.
x(), X2 = hp1.
y(), X3 = hp1.
z();
40 double x1 = hp2.x(), x2 = hp2.y(), x3 = hp2.z();
42 std::cout <<
"X(" << X1 <<
' ' << X2 <<
' ' << X3 <<
'\n';
43 std::cout <<
"x(" << x1 <<
' ' << x2 <<
' ' << x3 <<
'\n';
45 D(row, 0) = X1; D(row, 1) = X2; D(row, 2) = X3; b(row,0) = x1;
46 D(row+1, 3) = X1; D(row+1, 4) = X2; D(row+1, 5) = X3; b(row+1,0) = x2;
47 D(row+2, 6) = X1; D(row+2, 7) = X2; D(row+2, 8) = X3; b(row+2,0) = x3;
52 for(
int r = 0; r<(3*n); ++r){
54 for(
int c = 0; c<9; ++c)
55 std::cout << D[r][c] <<
',';
60 for(
int r = 0; r<(3*n); ++r)
61 std::cout << b[r][0] <<
',';
64 vnl_svd<double> svd(D);
65 std::cout << svd.W() <<
'\n';
67 std::cerr <<
"vgl_h_matrix_3d_compute_linear : design matrix has rank < 9\n" 68 <<
"vgl_h_matrix_3d_compute_linear : probably due to degenerate point configuration\n";
81 assert(points1.size() == points2.size());
82 int n = static_cast<int>(points1.size());
85 std::cerr <<
"vgl_h_matrix_3d_compute_affine: Need at least 4 matches.\n";
86 if (n == 0) std::cerr <<
"Could be std::vector setlength idiosyncrasies!\n";
95 std::vector<vgl_homg_point_3d<double> > tpoints1, tpoints2;
96 for (
int i = 0; i<n; i++)
98 tpoints1.push_back(tr1(points1[i]));
99 tpoints2.push_back(tr2(points2[i]));
101 vnl_matrix<double> M;
105 vnl_matrix_fixed<double, 4, 4> m;
107 m[0][0]=M[0][0]; m[0][1]=M[1][0]; m[0][2] = M[2][0];
108 m[1][0]=M[3][0]; m[1][1]=M[4][0]; m[1][2] = M[5][0];
109 m[2][0]=M[6][0]; m[2][1]=M[7][0]; m[2][2] = M[8][0];
112 for(
unsigned r = 0; r<4; ++r)
113 std::cout << std::setprecision(2) << m[r][0] <<
' ' << m[r][1] <<
' '<< m[r][2] <<
' '<< m[r][3] <<
'\n';
vgl_h_matrix_3d get_inverse() const
Return the inverse homography.
bool rescale_w(Type new_w=Type(1))
constexpr double DEGENERACY_THRESHOLD
bool solve_linear_problem(std::vector< vgl_homg_point_3d< double > > const &p1, std::vector< vgl_homg_point_3d< double > > const &p2, vnl_matrix< double > &M)
Assumes all corresponding points have equal weight.
Represents a homogeneous 3D point.
contains class vgl_h_matrix_3d_compute_affine
bool compute_from_points(std::vector< vgl_homg_point_3d< T > > const &points)
compute the normalizing transform.
constexpr int TM_UNKNOWNS_COUNT
A class to hold a 3-d projective transformation matrix and to perform common operations using it e....
bool compute_p(std::vector< vgl_homg_point_3d< double > > const &points1, std::vector< vgl_homg_point_3d< double > > const &points2, vgl_h_matrix_3d< double > &H) override
compute from matched points.
The similarity transform that normalizes a 3-d point set.