Ocean
Loading...
Searching...
No Matches
CalibrationBoardObservation.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_CV_CALIBRATION_CAMERA_CALIBRATOR_BOARD_OBSERVATION_H
9#define META_OCEAN_CV_CALIBRATION_CAMERA_CALIBRATOR_BOARD_OBSERVATION_H
10
13
15
18#include "ocean/math/Vector2.h"
19#include "ocean/math/Vector3.h"
20
21namespace Ocean
22{
23
24namespace CV
25{
26
27namespace Calibration
28{
29
30/// Forward declaration.
31class CalibrationBoardObservation;
32
33/**
34 * Definition of a vector holding CalibrationBoardObservation objects.
35 * @ingroup cvcalibration
36 */
37using CalibrationBoardObservations = std::vector<CalibrationBoardObservation>;
38
39/**
40 * This class implements an observation of a calibration board.
41 * The observation is mainly defined by 2D/3D correspondences between image points and object points, a camera pose and a camera profile.
42 * @ingroup cvcalibration
43 */
44class OCEAN_CV_CALIBRATION_EXPORT CalibrationBoardObservation
45{
46 protected:
47
48 /**
49 * Definition of an invalid image id.
50 */
51 static constexpr size_t invalidImageId_ = size_t(-1);
52
53 public:
54
55 /**
56 * Default creator for an invalid calibration board observation.
57 */
59
60 /**
61 * Creates a new calibration board observation.
62 * @param imageId The id of the image in which the calibration board has been observed, must be valid
63 * @param camera The camera profile which were used to observe the calibration board, must be valid
64 * @param board_T_camera The camera pose under which the calibration board has been observed, with default camera pointing towards the negative z-space with y-axis upwards, must be valid
65 * @param objectPointIds The ids of all object points which were used to observe the calibration board, at least 4
66 * @param objectPoints The 3D object points which were used to observe the calibration board, one for each object point id
67 * @param imagePoints The 2D image points which were used to observe the calibration board, one for each object point
68 */
69 CalibrationBoardObservation(const size_t imageId, SharedAnyCamera camera, const HomogenousMatrix4& board_T_camera, CalibrationBoard::ObjectPointIds&& objectPointIds, Vectors3&& objectPoints, Vectors2&& imagePoints);
70
71 /**
72 * Creates a new calibration board observation based on a given observation with improved camera profile and camera pose.
73 * @param camera The camera profile which were used to observe the calibration board, must be valid
74 * @param board_T_camera The camera pose under which the calibration board has been observed, with default camera pointing towards the negative z-space with y-axis upwards, must be valid
75 * @param observation The observation providing image id and correspondences
76 */
77 inline CalibrationBoardObservation(SharedAnyCamera camera, const HomogenousMatrix4& board_T_camera, CalibrationBoardObservation&& observation);
78
79 /**
80 * Returns the id of the image in which the calibration board has been observed.
81 * @return The id of the image, with range [0, infinity), an invalid id if the observation is invalid
82 */
83 inline size_t imageId() const;
84
85 /**
86 * Returns the camera profile which were used to observe the calibration board.
87 * @return The camera profile, nullptr if the observation is invalid
88 */
89 inline const SharedAnyCamera& camera() const;
90
91 /**
92 * Returns the camera pose under which the calibration board has been observed.
93 * @return The transformation between camera and calibration board, with default camera pointing towards the negative z-space with y-axis upwards, invalid if the observation is invalid
94 */
95 inline const HomogenousMatrix4& board_T_camera() const;
96
97 /**
98 * Returns the ids of all object points which were used to observe the calibration board.
99 * @return The object point ids
100 */
101 inline const CalibrationBoard::ObjectPointIds& objectPointIds() const;
102
103 /**
104 * Returns the 3D object points which were used to observe the calibration board.
105 * @return The object points, one for each object point id
106 * @see objectPointIds().
107 */
108 inline const Vectors3& objectPoints() const;
109
110 /**
111 * Returns the 2D image points which were used to observe the calibration board.
112 * @return The image points, one for each object point
113 */
114 inline const Vectors2& imagePoints() const;
115
116 /**
117 * Returns the image coverage of this observation.
118 * To calculate the coverage, the image is divided into bins and the number of bins which are covered by the observation is determined.
119 * @return The image coverage, with range [0, 1], -1 if the coverage could not be
120 */
121 float coverage() const;
122
123 /**
124 * Returns the occupancy array of this observation.
125 * @return The occupancy array, invalid if the coverage could not be determined
126 */
127 inline const Geometry::SpatialDistribution::OccupancyArray& occupancyArray() const;
128
129 /**
130 * Adds additional 2D/3D correspondences to this observation.
131 * @param objectPointIds The ids of all object points which were used to observe the calibration board, at least one
132 * @param objectPoints The 3D object points which were used to observe the calibration board, one for each object point id
133 * @param imagePoints The 2D image points which were used to observe the calibration board, one for each object point
134 */
135 void addCorrespondences(const CalibrationBoard::ObjectPointIds& objectPointIds, const Vectors3& objectPoints, const Vectors2& imagePoints);
136
137 /**
138 * Updates the camera profile and the camera pose of this observation.
139 * @param camera The new camera profile of this observation, must be valid
140 * @param board_T_camera The new camera pose of this observation, transforming camera to calibration board, with default camera pointing towards the negative z-space with y-axis upwards, must be valid
141 */
142 inline void updateCamera(const SharedAnyCamera& camera, const HomogenousMatrix4& board_T_camera);
143
144 /**
145 * Returns whether this observation is valid.
146 * @return True, if so
147 */
148 inline bool isValid() const;
149
150 /**
151 * Returns an invalid image id.
152 * @return The invalid image id
153 */
154 static constexpr size_t invalidImageId();
155
156 /**
157 * Compares the coverage of two observations.
158 * @param observationA The first observation to compare
159 * @param observationB The second observation to compare
160 * @return True, if the first observation has a lower coverage than the second observation
161 */
162 static inline bool compareObservations(const CalibrationBoardObservation& observationA, const CalibrationBoardObservation& observationB);
163
164 protected:
165
166 /**
167 * Determines the image coverage of this observation.
168 * To calculate the coverage, the image is divided into bins and the number of bins which are covered by the observation is determined.
169 * @param pixelsPerBin The number of pixels per bin, with range [1, infinity)
170 * @return The image coverage, with range [0, 1]
171 */
172 float determineCoverage(const unsigned int pixelsPerBin) const;
173
174 protected:
175
176 /// The id of the image in which the calibration board has been observed.
177 size_t imageId_ = invalidImageId_;
178
179 /// The camera profile which were used to observe the calibration board.
181
182 /// The camera pose under which the calibration board has been observed, with default camera pointing towards the negative z-space with y-axis upwards.
184
185 /// The ids of all object points which were used to observe the calibration board.
187
188 /// The 3D object points which were used to observe the calibration board.
190
191 /// The 2D image points which were used to observe the calibration board.
193
194 /// The image coverage of this observation, with range [0, 1], -1 if the coverage could not be determined.
195 mutable float coverage_ = -1.0f;
196
197 /// The occupancy array of this observation which is used to determine the image coverage.
199};
200
202 CalibrationBoardObservation(observation.imageId(), std::move(camera), board_T_camera, std::move(observation.objectPointIds_), std::move(observation.objectPoints_), std::move(observation.imagePoints_))
203{
204 // nothing to do here
205}
206
208{
209 return imageId_;
210}
211
213{
214 return camera_;
215}
216
221
226
228{
229 return objectPoints_;
230}
231
233{
234 return imagePoints_;
235}
236
238{
239 if (coverage() < 0.0f)
240 {
241 ocean_assert(false && "This should never happen!");
242 }
243
244 return occupancyArray_;
245}
246
247inline void CalibrationBoardObservation::updateCamera(const SharedAnyCamera& camera, const HomogenousMatrix4& board_T_camera)
248{
249 ocean_assert(camera && camera->isValid());
250 ocean_assert(board_T_camera.isValid());
251
252 camera_ = camera;
254}
255
257{
258 return imageId_ != invalidImageId_ && camera_ && camera_->isValid() && board_T_camera_.isValid() && !objectPointIds_.empty() && objectPointIds_.size() == objectPoints_.size() && objectPoints_.size() == imagePoints_.size();
259}
260
262{
263 return invalidImageId_;
264}
265
267{
268 ocean_assert(observationA.isValid() && observationB.isValid());
269
270 return observationA.coverage() < observationB.coverage();
271}
272
273}
274
275}
276
277}
278
279#endif // META_OCEAN_CV_CALIBRATION_CAMERA_CALIBRATOR_BOARD_OBSERVATION_H
std::vector< ObjectPointId > ObjectPointIds
Definition of a vector holding object point ids.
Definition CalibrationBoard.h:219
This class implements an observation of a calibration board.
Definition CalibrationBoardObservation.h:45
bool isValid() const
Returns whether this observation is valid.
Definition CalibrationBoardObservation.h:256
HomogenousMatrix4 board_T_camera_
The camera pose under which the calibration board has been observed, with default camera pointing tow...
Definition CalibrationBoardObservation.h:183
CalibrationBoardObservation(const size_t imageId, SharedAnyCamera camera, const HomogenousMatrix4 &board_T_camera, CalibrationBoard::ObjectPointIds &&objectPointIds, Vectors3 &&objectPoints, Vectors2 &&imagePoints)
Creates a new calibration board observation.
const HomogenousMatrix4 & board_T_camera() const
Returns the camera pose under which the calibration board has been observed.
Definition CalibrationBoardObservation.h:217
const SharedAnyCamera & camera() const
Returns the camera profile which were used to observe the calibration board.
Definition CalibrationBoardObservation.h:212
Geometry::SpatialDistribution::OccupancyArray occupancyArray_
The occupancy array of this observation which is used to determine the image coverage.
Definition CalibrationBoardObservation.h:198
float coverage() const
Returns the image coverage of this observation.
static constexpr size_t invalidImageId_
Definition of an invalid image id.
Definition CalibrationBoardObservation.h:51
const Geometry::SpatialDistribution::OccupancyArray & occupancyArray() const
Returns the occupancy array of this observation.
Definition CalibrationBoardObservation.h:237
Vectors2 imagePoints_
The 2D image points which were used to observe the calibration board.
Definition CalibrationBoardObservation.h:192
static bool compareObservations(const CalibrationBoardObservation &observationA, const CalibrationBoardObservation &observationB)
Compares the coverage of two observations.
Definition CalibrationBoardObservation.h:266
const Vectors3 & objectPoints() const
Returns the 3D object points which were used to observe the calibration board.
Definition CalibrationBoardObservation.h:227
SharedAnyCamera camera_
The camera profile which were used to observe the calibration board.
Definition CalibrationBoardObservation.h:180
size_t imageId() const
Returns the id of the image in which the calibration board has been observed.
Definition CalibrationBoardObservation.h:207
const CalibrationBoard::ObjectPointIds & objectPointIds() const
Returns the ids of all object points which were used to observe the calibration board.
Definition CalibrationBoardObservation.h:222
Vectors3 objectPoints_
The 3D object points which were used to observe the calibration board.
Definition CalibrationBoardObservation.h:189
CalibrationBoardObservation()=default
Default creator for an invalid calibration board observation.
CalibrationBoard::ObjectPointIds objectPointIds_
The ids of all object points which were used to observe the calibration board.
Definition CalibrationBoardObservation.h:186
void updateCamera(const SharedAnyCamera &camera, const HomogenousMatrix4 &board_T_camera)
Updates the camera profile and the camera pose of this observation.
Definition CalibrationBoardObservation.h:247
float determineCoverage(const unsigned int pixelsPerBin) const
Determines the image coverage of this observation.
size_t imageId_
The id of the image in which the calibration board has been observed.
Definition CalibrationBoardObservation.h:177
static constexpr size_t invalidImageId()
Returns an invalid image id.
Definition CalibrationBoardObservation.h:261
const Vectors2 & imagePoints() const
Returns the 2D image points which were used to observe the calibration board.
Definition CalibrationBoardObservation.h:232
void addCorrespondences(const CalibrationBoard::ObjectPointIds &objectPointIds, const Vectors3 &objectPoints, const Vectors2 &imagePoints)
Adds additional 2D/3D correspondences to this observation.
This class implements an occupancy array.
Definition SpatialDistribution.h:370
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1806
std::vector< CalibrationBoardObservation > CalibrationBoardObservations
Definition of a vector holding CalibrationBoardObservation objects.
Definition CalibrationBoardObservation.h:37
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition AnyCamera.h:60
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition Vector2.h:64
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
The namespace covering the entire Ocean framework.
Definition Accessor.h:15