Ocean
Loading...
Searching...
No Matches
CalibrationBoardDetector.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_CALIBRATION_BOARD_DETECTOR_H
9#define META_OCEAN_CV_CALIBRATION_CALIBRATION_BOARD_DETECTOR_H
10
16
17#include "ocean/base/Frame.h"
18#include "ocean/base/Worker.h"
19
21
22#include <deque>
23
24namespace Ocean
25{
26
27namespace CV
28{
29
30namespace Calibration
31{
32
33/**
34 * This class implements the detector for the calibration board.
35 * @ingroup cvcalibration
36 */
37class OCEAN_CV_CALIBRATION_EXPORT CalibrationBoardDetector
38{
39 protected:
40
41 /**
42 * Definition of a double-ended queue holding indices of continuous lines of marker points.
43 */
44 using ContinuousLineIndices = std::deque<Index32>;
45
46 /**
47 * Definition of a vector holding a binary mask indicating whether a marker point has been used already.
48 */
49 using UsedPoints = std::vector<uint8_t>;
50
51 public:
52
53 /**
54 * Determines the marker candidates based on marker points detected in an image.
55 * @param points The marker points detected in the image, must be valid
56 * @param pointsDistributionArray The distribution array associated with the detected marker points, must be valid
57 * @param maximalDistance The maximal distance between two neighboring marker points, in pixels, with range (0, infinity)
58 * @param maxDistancePercentage The percentage defining the maximal distance between the predicted point and the actual point based on the distance between previous point and predicted point, with range [0, infinity)
59 * @param markerCandidates The resulting marker candidates with valid boarder indices
60 * @return True, if succeeded
61 */
62 static bool determineMarkerCandidates(const Points& points, const Geometry::SpatialDistribution::DistributionArray& pointsDistributionArray, const Scalar maximalDistance, const Scalar maxDistancePercentage, MarkerCandidates& markerCandidates);
63
64 /**
65 * Determines the initial camera field-of-view based on several marker candidates with valid border indices.
66 * Each marker candidate and it's potential 4-neighborhood is checked against several field-of-views.<br>
67 * The field-of-view resulting in the lowest projection error is used.
68 * @param width The width of the image in pixel, with range [1, infinity)
69 * @param height The height of the image in pixel, with range [1, infinity)
70 * @param points The marker points detected in the image, must be valid
71 * @param markerCandidates The marker candidates from which the initial field-of-view will be determined, must have valid border indices, at least one
72 * @param anyCameraType The type of the camera profile to be used, must be valid
73 * @param fovX The resulting initial horizontal field-of-view, in radian, with range [minFovX, maxFovX]
74 * @param minFovX The minimal horizontal field-of-view to be used, in radian, with range (0, maxFovX)
75 * @param maxFovX The maximal horizontal field-of-view to be used, in radian, with range (minFovX, PI)
76 * @param steps The number of steps to be used for the field-of-view search, with range [2, infinity)
77 * @return True, if succeeded
78 */
79 static bool determineInitialCameraFieldOfView(const unsigned int width, const unsigned height, const Points& points, const MarkerCandidates& markerCandidates, const AnyCameraType anyCameraType, Scalar& fovX, const Scalar minFovX = Numeric::deg2rad(20), const Scalar maxFovX = Numeric::deg2rad(175), const size_t steps = 20);
80
81 /**
82 * Determines the camera pose for a marker candidate.
83 * This function is intended for marker candidates with only valid border indices.<br>
84 * The resulting camera pose is the transformation between camera and the marker candidate.<br>
85 * The marker is defined in the xz-plane, the origin is in the center of the marker, and marker points have a distance of 1 to each other.
86 * @param camera The camera profile to be used, must be valid
87 * @param markerCandidate The marker candidate for which the camera pose will be determined, must have valid border indices
88 * @param points The marker points detected in the image
89 * @param markerCandidate_T_camera The resulting camera pose in relation to the marker candidate
90 * @param maximalProjectionError The maximal projection error between the 3D object points and the 2D image points, in pixel, with range [0, infinity)
91 * @return True, if succeeded
92 */
93 static bool determineCameraPoseForMarker(const AnyCamera& camera, const MarkerCandidate& markerCandidate, const Points& points, HomogenousMatrix4& markerCandidate_T_camera, const Scalar maximalProjectionError);
94
95 /**
96 * Determines the remaining unknown point indices of a marker candidate.
97 * This function is intended for marker candidates with only valid border indices.
98 * @param camera The camera profile to be used, must be valid
99 * @param markerCandidate_T_camera The known transformation between camera and the marker candidate, must be valid
100 * @param markerCandidate The marker candidate to update
101 * @param points The marker points detected in the image
102 * @param pointsDistributionArray The distribution array associated with the detected marker points, must be valid
103 * @param maximalProjectionError The maximal projection error between the 3D object points and the 2D image points, in pixel, with range [0, infinity)
104 * @return True, if all remaining (9) point indices could be determined
105 */
106 static bool determineRemainingMarkerPointIndices(const AnyCamera& camera, const HomogenousMatrix4& markerCandidate_T_camera, MarkerCandidate& markerCandidate, const Points& points, const Geometry::SpatialDistribution::DistributionArray& pointsDistributionArray, const Scalar maximalProjectionError);
107
108 /**
109 * Determines the marker candidates most suitable to start the detection of the calibration board.
110 * Marker candidates with most neighbors located in the center of the image are preferred due to fisheye cameras.
111 * @param width The width of the image in pixel, with range [1, infinity)
112 * @param height The height of the image in pixel, with range [1, infinity)
113 * @param markerCandidates The marker candidates from which the best candidates will be determined, at least one
114 * @param points The marker points detected in the image, must be valid
115 * @param bestMarkerCandidateIndices The resulting indices of the best marker candidates, with range [0, markerCandidates.size() - 1]
116 * @return True, if succeeded
117 */
118 static bool determineStartMarkerCandidates(const unsigned int width, const unsigned int height, const MarkerCandidates& markerCandidates, const Points& points, Indices32& bestMarkerCandidateIndices);
119
120 /**
121 * Detects a calibration board in an image.
122 * @param camera The camera profile to be used, must be valid
123 * @param yFrame The image in which the calibration board will be detected, must be valid
124 * @param calibrationBoard The calibration board to be detected, must be valid
125 * @param observation The resulting observation of the calibration board
126 * @param maximalProjectionError The maximal projection error between the 3D object points and the 2D image points, in pixel, with range [0, infinity)
127 * @param worker Optional worker object to distribute the computation
128 * @return True, if succeeded
129 */
130 static bool detectCalibrationBoard(const AnyCamera& camera, const Frame& yFrame, const MetricCalibrationBoard& calibrationBoard, CalibrationBoardObservation& observation, const Scalar maximalProjectionError, Worker* worker = nullptr);
131
132 protected:
133
134 /**
135 * Determines a continuous line of marker points with same sign.
136 * @param pointIndexA The index of the first marker point, located on the line, with range [0, points.size() - 1]
137 * @param pointIndexB The index of the second neighbor marker point, located on the line, with range [0, points.size() - 1]
138 * @param points The marker points detected in the image
139 * @param usedPoints Binary mask indicating whether a marker point has been used already, one for each point, only points not yet used will be used for the determination of the continuous line
140 * @param pointsDistributionArray The distribution array associated with the detected marker points, must be valid
141 * @param lineIndices The resulting indices of the marker points located on the continuous line
142 * @param maxDistancePercentage The percentage defining the maximal distance between the predicted point and the actual point based on the distance between previous point and predicted point, with range [0, infinity)
143 * @return True, if succeeded
144 */
145 static bool determineContinuousLine(const size_t pointIndexA, const size_t pointIndexB, const Points& points, const UsedPoints& usedPoints, const Geometry::SpatialDistribution::DistributionArray& pointsDistributionArray, ContinuousLineIndices& lineIndices, const Scalar maxDistancePercentage);
146
147 /**
148 * Determines a closed rectangle of marker points (the 16 marker points of the border of a marker).
149 * @param lineIndices The indices of the marker points located on a known continuous line with 5 points, will be extended by the remaining 11 points of the rectangle
150 * @param points The marker points detected in the image
151 * @param usedPoints Binary mask indicating whether a marker point has been used already, one for each point, only points not yet used will be used for the determination of the rectangle
152 * @param pointsDistributionArray The distribution array associated with the detected marker points, must be valid
153 * @param maxDistancePercentage The percentage defining the maximal distance between the predicted point and the actual point based on the distance between previous point and predicted point, with range [0, infinity)
154 * @return True, if succeeded
155 */
156 static bool determineClosedRectangle(ContinuousLineIndices& lineIndices, const Points& points, const UsedPoints& usedPoints, const Geometry::SpatialDistribution::DistributionArray& pointsDistributionArray, const Scalar maxDistancePercentage);
157
158 /**
159 * Determines the neighborhood relationship in marker candidates.
160 * @param markerCandidates The marker candidates for which the neighborhood relationship will be determined
161 * @param points The marker points detected in the image
162 * @param maxDistancePercentage The percentage defining the maximal distance between the predicted point and the actual point based on the distance between previous point and predicted point, with range [0, infinity)
163 */
164 static void determineMarkerCandidateNeighborhood(MarkerCandidates& markerCandidates, const Points& points, const Scalar maxDistancePercentage);
165};
166
167}
168
169}
170
171}
172
173#endif // META_OCEAN_CV_CALIBRATION_CALIBRATION_BOARD_DETECTOR_H
This class implements the abstract base class for all AnyCamera objects.
Definition AnyCamera.h:130
This class implements the detector for the calibration board.
Definition CalibrationBoardDetector.h:38
std::vector< uint8_t > UsedPoints
Definition of a vector holding a binary mask indicating whether a marker point has been used already.
Definition CalibrationBoardDetector.h:49
static bool determineCameraPoseForMarker(const AnyCamera &camera, const MarkerCandidate &markerCandidate, const Points &points, HomogenousMatrix4 &markerCandidate_T_camera, const Scalar maximalProjectionError)
Determines the camera pose for a marker candidate.
static bool determineRemainingMarkerPointIndices(const AnyCamera &camera, const HomogenousMatrix4 &markerCandidate_T_camera, MarkerCandidate &markerCandidate, const Points &points, const Geometry::SpatialDistribution::DistributionArray &pointsDistributionArray, const Scalar maximalProjectionError)
Determines the remaining unknown point indices of a marker candidate.
std::deque< Index32 > ContinuousLineIndices
Definition of a double-ended queue holding indices of continuous lines of marker points.
Definition CalibrationBoardDetector.h:44
static void determineMarkerCandidateNeighborhood(MarkerCandidates &markerCandidates, const Points &points, const Scalar maxDistancePercentage)
Determines the neighborhood relationship in marker candidates.
static bool determineClosedRectangle(ContinuousLineIndices &lineIndices, const Points &points, const UsedPoints &usedPoints, const Geometry::SpatialDistribution::DistributionArray &pointsDistributionArray, const Scalar maxDistancePercentage)
Determines a closed rectangle of marker points (the 16 marker points of the border of a marker).
static bool determineInitialCameraFieldOfView(const unsigned int width, const unsigned height, const Points &points, const MarkerCandidates &markerCandidates, const AnyCameraType anyCameraType, Scalar &fovX, const Scalar minFovX=Numeric::deg2rad(20), const Scalar maxFovX=Numeric::deg2rad(175), const size_t steps=20)
Determines the initial camera field-of-view based on several marker candidates with valid border indi...
static bool determineContinuousLine(const size_t pointIndexA, const size_t pointIndexB, const Points &points, const UsedPoints &usedPoints, const Geometry::SpatialDistribution::DistributionArray &pointsDistributionArray, ContinuousLineIndices &lineIndices, const Scalar maxDistancePercentage)
Determines a continuous line of marker points with same sign.
static bool determineStartMarkerCandidates(const unsigned int width, const unsigned int height, const MarkerCandidates &markerCandidates, const Points &points, Indices32 &bestMarkerCandidateIndices)
Determines the marker candidates most suitable to start the detection of the calibration board.
static bool determineMarkerCandidates(const Points &points, const Geometry::SpatialDistribution::DistributionArray &pointsDistributionArray, const Scalar maximalDistance, const Scalar maxDistancePercentage, MarkerCandidates &markerCandidates)
Determines the marker candidates based on marker points detected in an image.
static bool detectCalibrationBoard(const AnyCamera &camera, const Frame &yFrame, const MetricCalibrationBoard &calibrationBoard, CalibrationBoardObservation &observation, const Scalar maximalProjectionError, Worker *worker=nullptr)
Detects a calibration board in an image.
This class implements an observation of a calibration board.
Definition CalibrationBoardObservation.h:45
This class implements a candidate of a marker.
Definition MarkerCandidate.h:48
This class extends the calibration board with metric information.
Definition MetricCalibrationBoard.h:39
This class implements Ocean's image class.
Definition Frame.h:1808
This class implements a distribution array.
Definition SpatialDistribution.h:228
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition Base.h:96
std::vector< Point > Points
Definition of a vector holding points.
Definition cv/calibration/Point.h:31
std::vector< MarkerCandidate > MarkerCandidates
Definition of a vector holding marker candidates.
Definition MarkerCandidate.h:33
float Scalar
Definition of a scalar type.
Definition Math.h:129
AnyCameraType
Definition of individual camera types.
Definition AnyCamera.h:111
The namespace covering the entire Ocean framework.
Definition Accessor.h:15