ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
homography_matrix.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Eigen/Core>
11 #include <vector>
12 
13 #include "util/alignment.h"
14 #include "util/types.h"
15 
16 namespace colmap {
17 
18 // Direct linear transformation algorithm to compute the homography between
19 // point pairs. This algorithm computes the least squares estimate for
20 // the homography from at least 4 correspondences.
22 public:
23  typedef Eigen::Vector2d X_t;
24  typedef Eigen::Vector2d Y_t;
25  typedef Eigen::Matrix3d M_t;
26 
27  // The minimum number of samples needed to estimate a model.
28  static const int kMinNumSamples = 4;
29 
30  // Estimate the projective transformation (homography).
31  //
32  // The number of corresponding points must be at least 4.
33  //
34  // @param points1 First set of corresponding points.
35  // @param points2 Second set of corresponding points.
36  //
37  // @return 3x3 homogeneous transformation matrix.
38  static std::vector<M_t> Estimate(const std::vector<X_t>& points1,
39  const std::vector<Y_t>& points2);
40 
41  // Calculate the transformation error for each corresponding point pair.
42  //
43  // Residuals are defined as the squared transformation error when
44  // transforming the source to the destination coordinates.
45  //
46  // @param points1 First set of corresponding points.
47  // @param points2 Second set of corresponding points.
48  // @param H 3x3 projective matrix.
49  // @param residuals Output vector of residuals.
50  static void Residuals(const std::vector<X_t>& points1,
51  const std::vector<Y_t>& points2,
52  const M_t& H,
53  std::vector<double>* residuals);
54 };
55 
56 } // namespace colmap
static std::vector< M_t > Estimate(const std::vector< X_t > &points1, const std::vector< Y_t > &points2)
static void Residuals(const std::vector< X_t > &points1, const std::vector< Y_t > &points2, const M_t &H, std::vector< double > *residuals)