23 if (points.size() < 4)
24 throw std::invalid_argument(
"At least 4 matches required");
27 std::vector<double> A(2 * points.size() * 9);
28 for (std::size_t i = 0; i < points.size(); ++i)
30 std::size_t
const row1 = 9 * i;
31 std::size_t
const row2 = 9 * (i + points.size());
36 A[row1 + 3] = match.
p1[0];
37 A[row1 + 4] = match.
p1[1];
39 A[row1 + 6] = -match.
p1[0] * match.
p2[1];
40 A[row1 + 7] = -match.
p1[1] * match.
p2[1];
41 A[row1 + 8] = -match.
p2[1];
42 A[row2 + 0] = -match.
p1[0];
43 A[row2 + 1] = -match.
p1[1];
48 A[row2 + 6] = match.
p1[0] * match.
p2[0];
49 A[row2 + 7] = match.
p1[1] * match.
p2[0];
50 A[row2 + 8] = match.
p2[0];
55 math::matrix_svd<double>(&A[0], 2 * points.size(),
56 9,
nullptr,
nullptr, V.
begin());
59 for (
int i = 0; i < 9; ++i)
60 (*result)[i] = V[i * 9 + 8];
81 double error = (p1 - result).square_norm();
83 result = homography * p1;
85 error += (result - p2).square_norm();
Matrix< T, N, N > matrix_inverse(Matrix< T, N, N > const &mat)
Calculates the inverse of the given matrix.
bool homography_dlt(Correspondences2D2D const &points, HomographyMatrix *result)
Direct linear transformation algorithm to compute the homography matrix from image correspondences.
std::vector< Correspondence2D2D > Correspondences2D2D
double symmetric_transfer_error(HomographyMatrix const &homography, Correspondence2D2D const &match)
Computes the symmetric transfer error for an image correspondence given the homography matrix between...
#define SFM_NAMESPACE_END
#define SFM_NAMESPACE_BEGIN
Two image coordinates which correspond to each other in terms of observing the same point in the scen...