ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
utils.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 // Center and normalize image points.
19 //
20 // The points are transformed in a two-step procedure that is expressed
21 // as a transformation matrix. The matrix of the resulting points is usually
22 // better conditioned than the matrix of the original points.
23 //
24 // Center the image points, such that the new coordinate system has its
25 // origin at the centroid of the image points.
26 //
27 // Normalize the image points, such that the mean distance from the points
28 // to the coordinate system is sqrt(2).
29 //
30 // @param points Image coordinates.
31 // @param normed_points Transformed image coordinates.
32 // @param matrix 3x3 transformation matrix.
33 void CenterAndNormalizeImagePoints(const std::vector<Eigen::Vector2d>& points,
34  std::vector<Eigen::Vector2d>* normed_points,
35  Eigen::Matrix3d* matrix);
36 
37 // Calculate the residuals of a set of corresponding points and a given
38 // fundamental or essential matrix.
39 //
40 // Residuals are defined as the squared Sampson error.
41 //
42 // @param points1 First set of corresponding points as Nx2 matrix.
43 // @param points2 Second set of corresponding points as Nx2 matrix.
44 // @param E 3x3 fundamental or essential matrix.
45 // @param residuals Output vector of residuals.
46 void ComputeSquaredSampsonError(const std::vector<Eigen::Vector2d>& points1,
47  const std::vector<Eigen::Vector2d>& points2,
48  const Eigen::Matrix3d& E,
49  std::vector<double>* residuals);
50 
51 // Calculate the squared reprojection error given a set of 2D-3D point
52 // correspondences and a projection matrix. Returns DBL_MAX if a 3D point is
53 // behind the given camera.
54 //
55 // @param points2D Normalized 2D image points.
56 // @param points3D 3D world points.
57 // @param proj_matrix 3x4 projection matrix.
58 // @param residuals Output vector of residuals.
60  const std::vector<Eigen::Vector2d>& points2D,
61  const std::vector<Eigen::Vector3d>& points3D,
62  const Eigen::Matrix3x4d& proj_matrix,
63  std::vector<double>* residuals);
64 
65 } // namespace colmap
int points
Matrix< double, 3, 4 > Matrix3x4d
Definition: types.h:39
void CenterAndNormalizeImagePoints(const std::vector< Eigen::Vector2d > &points, std::vector< Eigen::Vector2d > *normed_points, Eigen::Matrix3d *matrix)
Definition: utils.cc:38
void ComputeSquaredReprojectionError(const std::vector< Eigen::Vector2d > &points2D, const std::vector< Eigen::Vector3d > &points3D, const Eigen::Matrix3x4d &proj_matrix, std::vector< double > *residuals)
Definition: utils.cc:133
void ComputeSquaredSampsonError(const std::vector< Eigen::Vector2d > &points1, const std::vector< Eigen::Vector2d > &points2, const Eigen::Matrix3d &E, std::vector< double > *residuals)
Definition: utils.cc:87