ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
camera_rig.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 <unordered_map>
11 #include <vector>
12 
13 #include "base/camera.h"
14 #include "base/pose.h"
15 #include "base/reconstruction.h"
16 #include "util/alignment.h"
17 #include "util/types.h"
18 
19 namespace colmap {
20 
21 // This class holds information about the relative configuration of camera rigs.
22 // Camera rigs are composed of multiple cameras with a rigid relative extrinsic
23 // configuration over multiple snapshots. Snapshots are defined as the
24 // collection of images captured simultaneously by all cameras in the rig.
25 class CameraRig {
26 public:
27  CameraRig();
28 
29  // The number of cameras in the rig.
30  size_t NumCameras() const;
31 
32  // The number of snapshots captured by this rig.
33  size_t NumSnapshots() const;
34 
35  // Check whether the given camera is part of the rig.
36  bool HasCamera(const camera_t camera_id) const;
37 
38  // Access the reference camera.
39  camera_t RefCameraId() const;
40  void SetRefCameraId(const camera_t camera_id);
41 
42  // Get the identifiers of the cameras in the rig.
43  std::vector<camera_t> GetCameraIds() const;
44 
45  // Get the snapshots of the camera rig.
46  const std::vector<std::vector<image_t>>& Snapshots() const;
47 
48  // Add a new camera to the rig. The relative pose may contain dummy values
49  // and can then be computed automatically from a given reconstruction using
50  // the method `ComputeRelativePoses`.
51  void AddCamera(const camera_t camera_id,
52  const Eigen::Vector4d& rel_qvec,
53  const Eigen::Vector3d& rel_tvec);
54 
55  // Add the images of a single snapshot to rig. A snapshot consists of the
56  // captured images of all cameras of the rig. All images of a snapshot share
57  // the same global camera rig pose, i.e. all images in the camera rig are
58  // captured simultaneously.
59  void AddSnapshot(const std::vector<image_t>& image_ids);
60 
61  // Check whether the camera rig setup is valid.
62  void Check(const Reconstruction& reconstruction) const;
63 
64  // Get the relative poses of the cameras in the rig.
65  Eigen::Vector4d& RelativeQvec(const camera_t camera_id);
66  const Eigen::Vector4d& RelativeQvec(const camera_t camera_id) const;
67  Eigen::Vector3d& RelativeTvec(const camera_t camera_id);
68  const Eigen::Vector3d& RelativeTvec(const camera_t camera_id) const;
69 
70  // Compute the scaling factor from the reconstruction to the camera rig
71  // dimensions by averaging over the distances between the projection
72  // centers. Note that this assumes that there is at least one camera pair in
73  // the rig with non-zero baseline, otherwise the function returns NaN.
74  double ComputeScale(const Reconstruction& reconstruction) const;
75 
76  // Compute the relative poses in the rig from the reconstruction by
77  // averaging the relative poses over all snapshots. The pose of the
78  // reference camera will be the identity transformation. This assumes that
79  // the camera rig has snapshots that are registered in the reconstruction.
80  bool ComputeRelativePoses(const Reconstruction& reconstruction);
81 
82  // Compute the absolute camera pose of the rig. The absolute camera pose of
83  // the rig is computed as the average of all relative camera poses in the
84  // rig and their corresponding image poses in the reconstruction.
85  void ComputeAbsolutePose(const size_t snapshot_idx,
86  const Reconstruction& reconstruction,
87  Eigen::Vector4d* abs_qvec,
88  Eigen::Vector3d* abs_tvec) const;
89 
90 private:
91  struct RigCamera {
92  Eigen::Vector4d rel_qvec = ComposeIdentityQuaternion();
93  Eigen::Vector3d rel_tvec = Eigen::Vector3d(0, 0, 0);
94  };
95 
96  camera_t ref_camera_id_ = kInvalidCameraId;
97  std::unordered_map<camera_t, RigCamera> rig_cameras_;
98  std::vector<std::vector<image_t>> snapshots_;
99 };
100 
101 } // namespace colmap
TestImageToWorldToImage
void TestImageToWorldToImage(const std::vector< double > params, const double x0, const double y0)
Definition: camera_models_test.cc:53
QtCompat::endl
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718
types.h
colmap::CameraRig::NumSnapshots
size_t NumSnapshots() const
Definition: camera_rig.cc:42
x
normal_z x
Definition: my_point_types.h:165
camera_models.h
colmap::InvertPose
void InvertPose(const Eigen::Vector4d &qvec, const Eigen::Vector3d &tvec, Eigen::Vector4d *inv_qvec, Eigen::Vector3d *inv_tvec)
Definition: pose.cc:192
colmap::CameraModelImageToWorld
void CameraModelImageToWorld(const int model_id, const std::vector< double > &params, const double x, const double y, double *u, double *v)
Definition: camera_models.h:1497
colmap::Image::Tvec
const Eigen::Vector3d & Tvec() const
Definition: image.h:325
colmap::CameraModelParamsInfo
std::string CameraModelParamsInfo(const int model_id)
Definition: camera_models.cc:139
colmap::ExistsCameraModelWithId
bool ExistsCameraModelWithId(const int model_id)
Definition: camera_models.cc:98
alignment.h
colmap::ComposeIdentityQuaternion
Eigen::Vector4d ComposeIdentityQuaternion()
Definition: pose.h:209
TestModel
void TestModel(const std::vector< double > &params)
Definition: camera_models_test.cc:66
colmap::CameraRig::ComputeRelativePoses
bool ComputeRelativePoses(const Reconstruction &reconstruction)
Definition: camera_rig.cc:167
colmap::VectorContainsDuplicateValues
bool VectorContainsDuplicateValues(const std::vector< T > &vector)
Definition: misc.h:143
colmap::CameraRig::HasCamera
bool HasCamera(const camera_t camera_id) const
Definition: camera_rig.cc:44
colmap::ProjectionCenterFromPose
Eigen::Vector3d ProjectionCenterFromPose(const Eigen::Vector4d &qvec, const Eigen::Vector3d &tvec)
Definition: pose.cc:164
colmap::CameraModelFocalLengthIdxs
const std::vector< size_t > & CameraModelFocalLengthIdxs(const int model_id)
Definition: camera_models.cc:156
colmap::CameraModelExtraParamsIdxs
const std::vector< size_t > & CameraModelExtraParamsIdxs(const int model_id)
Definition: camera_models.cc:186
testing.h
colmap::ExistsCameraModelWithName
bool ExistsCameraModelWithName(const std::string &model_name)
Definition: camera_models.cc:94
colmap::Reconstruction
Definition: reconstruction.h:40
colmap::CameraRig::NumCameras
size_t NumCameras() const
Definition: camera_rig.cc:40
colmap::CameraModelIdToName
std::string CameraModelIdToName(const int model_id)
Definition: camera_models.cc:111
colmap::FOVCameraModel::model_id
static const int model_id
Definition: camera_models.h:276
colmap::ConcatenateQuaternions
Eigen::Vector4d ConcatenateQuaternions(const Eigen::Vector4d &qvec1, const Eigen::Vector4d &qvec2)
Definition: pose.cc:97
size
int size
Definition: FileIOFactory.cpp:130
colmap::CameraRig::AddSnapshot
void AddSnapshot(const std::vector< image_t > &image_ids)
Definition: camera_rig.cc:79
y
normal_z y
Definition: my_point_types.h:168
colmap::CameraModelHasBogusParams
bool CameraModelHasBogusParams(const int model_id, const std::vector< double > &params, const size_t width, const size_t height, const double min_focal_length_ratio, const double max_focal_length_ratio, const double max_extra_param)
Definition: camera_models.cc:233
colmap::CameraModelWorldToImage
void CameraModelWorldToImage(const int model_id, const std::vector< double > &params, const double u, const double v, double *x, double *y)
Definition: camera_models.h:1479
e
const double * e
Definition: essential_matrix_poly.h:10
misc.h
colmap::CameraModelPrincipalPointIdxs
const std::vector< size_t > & CameraModelPrincipalPointIdxs(const int model_id)
Definition: camera_models.cc:171
colmap::CameraRig::SetRefCameraId
void SetRefCameraId(const camera_t camera_id)
Definition: camera_rig.cc:50
colmap::CameraModelVerifyParams
bool CameraModelVerifyParams(const int model_id, const std::vector< double > &params)
Definition: camera_models.cc:215
colmap::CameraRig
Definition: camera_rig.h:25
colmap::CameraRig::RelativeQvec
Eigen::Vector4d & RelativeQvec(const camera_t camera_id)
Definition: camera_rig.cc:112
colmap::CameraRig::ComputeScale
double ComputeScale(const Reconstruction &reconstruction) const
Definition: camera_rig.cc:128
colmap::AverageQuaternions
Eigen::Vector4d AverageQuaternions(const std::vector< Eigen::Vector4d > &qvecs, const std::vector< double > &weights)
Definition: pose.cc:118
colmap::CameraRig::Snapshots
const std::vector< std::vector< image_t > > & Snapshots() const
Definition: camera_rig.cc:64
reconstruction.h
colmap::Reconstruction::ExistsCamera
bool ExistsCamera(const camera_t camera_id) const
Definition: reconstruction.h:517
image
std::shared_ptr< core::Tensor > image
Definition: FilamentRenderer.cpp:184
colmap::CameraRig::Check
void Check(const Reconstruction &reconstruction) const
Definition: camera_rig.cc:86
colmap::Image
Definition: image.h:29
colmap::ComputeRelativePose
void ComputeRelativePose(const Eigen::Vector4d &qvec1, const Eigen::Vector3d &tvec1, const Eigen::Vector4d &qvec2, const Eigen::Vector3d &tvec2, Eigen::Vector4d *qvec12, Eigen::Vector3d *tvec12)
Definition: pose.cc:173
colmap::CameraRig::RelativeTvec
Eigen::Vector3d & RelativeTvec(const camera_t camera_id)
Definition: camera_rig.cc:120
camera.h
TestWorldToImageToWorld
void TestWorldToImageToWorld(const std::vector< double > params, const double u0, const double v0)
Definition: camera_models_test.cc:40
colmap::kInvalidCameraId
const camera_t kInvalidCameraId
Definition: types.h:75
colmap::CameraRig::RefCameraId
camera_t RefCameraId() const
Definition: camera_rig.cc:48
colmap::CameraModelImageToWorldThreshold
double CameraModelImageToWorldThreshold(const int model_id, const std::vector< double > &params, const double threshold)
Definition: camera_models.h:1515
pose.h
colmap::CameraModelNameToId
int CameraModelNameToId(const std::string &model_name)
Definition: camera_models.cc:102
colmap::CameraRig::GetCameraIds
std::vector< camera_t > GetCameraIds() const
Definition: camera_rig.cc:55
colmap::CameraModelNumParams
size_t CameraModelNumParams(const int model_id)
Definition: camera_models.cc:201
colmap
Definition: AutomaticReconstructionController.h:17
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(TestSimplePinhole)
Definition: camera_models_test.cc:133
colmap::camera_t
uint32_t camera_t
Definition: types.h:58
colmap::Image::Qvec
const Eigen::Vector4d & Qvec() const
Definition: image.h:301
colmap::CameraRig::CameraRig
CameraRig()
Definition: camera_rig.cc:38
colmap::CameraRig::ComputeAbsolutePose
void ComputeAbsolutePose(const size_t snapshot_idx, const Reconstruction &reconstruction, Eigen::Vector4d *abs_qvec, Eigen::Vector3d *abs_tvec) const
Definition: camera_rig.cc:230
colmap::QuaternionRotatePoint
Eigen::Vector3d QuaternionRotatePoint(const Eigen::Vector4d &qvec, const Eigen::Vector3d &point)
Definition: pose.cc:110
colmap::Reconstruction::ExistsImage
bool ExistsImage(const image_t image_id) const
Definition: reconstruction.h:521
colmap::CameraModelInitializeParams
std::vector< double > CameraModelInitializeParams(const int model_id, const double focal_length, const size_t width, const size_t height)
Definition: camera_models.cc:120
colmap::Reconstruction::Image
const class Image & Image(const image_t image_id) const
Definition: reconstruction.h:454
colmap::CameraRig::AddCamera
void AddCamera(const camera_t camera_id, const Eigen::Vector4d &rel_qvec, const Eigen::Vector3d &rel_tvec)
Definition: camera_rig.cc:68
camera_rig.h