iCub-main
Loading...
Searching...
No Matches
CalibrationTypes.h
Go to the documentation of this file.
1#ifndef ICUB_STEREOCALIB_CALIBRATION_TYPES_H
2#define ICUB_STEREOCALIB_CALIBRATION_TYPES_H
3
4#include <cstddef>
5#include <cstdint>
6#include <cmath>
7#include <string>
8#include <vector>
9
10#include <opencv2/calib3d.hpp>
11#include <opencv2/core.hpp>
12
13namespace stereo_calib
14{
15
16 enum class CameraSide
17 {
18 Left,
19 Right
20 };
21
22 enum class CalibrationMode
23 {
24 MonocularLeft, // validate obs -> calibrate left -> populate result.leftCamera -> no call to stereo calib nor rectification
25 MonocularRight, // validate obs -> calibrate right -> populate result.rightCamera -> no call to stereo calib nor rectification
26 MonocularBoth, // validate obs -> calibrate left and right -> estimate intrinsics -> no estimation of R and T or rectification
27 StereoFull // validate obs -> calibrate left and right -> stereo calib with fixed intrinsics -> stereo rectification -> evaluate rectification quality -> populate result with all fields
28 };
29
31 {
32 int cornersX{0};
33 int cornersY{0};
34
35 // Physical side length of one chessboard square
36 double squareSizeMeters{0.0};
37
38 cv::Size patternSize() const
39 {
40 return cv::Size(cornersX, cornersY);
41 }
42
43 std::size_t cornersCount() const
44 {
45 if(!isValid())
46 {
47 return 0;
48 }
49 return static_cast<std::size_t>(cornersX)*static_cast<std::size_t>(cornersY);
50 }
51
52 bool isValid() const
53 {
54 return (cornersX > 1 && cornersY > 1 && squareSizeMeters > 0.0);
55 }
56
57 std::vector<cv::Point3f> createObjectPoints() const
58 {
59 std::vector<cv::Point3f> points;
60
61 if(!isValid())
62 {
63 return points;
64 }
65
66 points.reserve(cornersCount());
67
68 for (int r = 0; r < cornersY; ++r)
69 {
70 for(int c = 0; c < cornersX; ++c)
71 {
72 points.emplace_back(
73 static_cast<float>(c * squareSizeMeters),
74 static_cast<float>(r * squareSizeMeters),
75 0.0F
76 );
77 }
78 }
79
80 return points;
81 }
82 };
83
85 {
86 cv::Size imageSize;
87
88 std::vector<cv::Point3f> objectPoints;
89 std::vector<cv::Point2f> leftImagePoints;
90 std::vector<cv::Point2f> rightImagePoints;
91
95
96 int64_t leftSequenceNumber {-1};
97 int64_t rightSequenceNumber {-1};
98
99 // Relative filenames of the raw images saved for this accepted
100 // observation. They are intentionally part of the observation so
101 // that the point data and the dataset images can be joined without
102 // relying on directory iteration.
103 std::string leftImageFilename;
105
106 bool isValid() const
107 {
108 if(imageSize.width <= 0 ||
109 imageSize.height <= 0)
110 {
111 return false;
112 }
113
114 if(objectPoints.empty())
115 return false;
116
117 return (objectPoints.size() == leftImagePoints.size() &&
118 objectPoints.size() == rightImagePoints.size() &&
120 }
121 };
122
124 {
126
127 cv::Size imageSize{1920, 1080};
129
131 cv::fisheye::CALIB_USE_INTRINSIC_GUESS |
132 cv::fisheye::CALIB_RECOMPUTE_EXTRINSIC |
133 cv::fisheye::CALIB_CHECK_COND |
134 cv::fisheye::CALIB_FIX_SKEW
135 };
136
138 cv::fisheye::CALIB_FIX_INTRINSIC |
139 cv::fisheye::CALIB_CHECK_COND |
140 cv::fisheye::CALIB_FIX_SKEW
141 };
142
143 cv::TermCriteria criteria{
144 cv::TermCriteria::COUNT |
145 cv::TermCriteria::EPS,
146 100,
147 1e-5
148 };
149
152
153 bool zeroDisparity{true};
154
155 bool isValid() const
156 {
157 return (imageSize.width > 0 &&
158 imageSize.height > 0 &&
159 std::isfinite(rectificationBalance) &&
160 rectificationBalance >= 0.0 &&
161 rectificationBalance <= 1.0 &&
162 std::isfinite(rectificationFovScale) &&
163 rectificationFovScale > 0.0 &&
164 (!(criteria.type & cv::TermCriteria::COUNT) || criteria.maxCount > 0) &&
165 (!(criteria.type & cv::TermCriteria::EPS) ||
166 (std::isfinite(criteria.epsilon) && criteria.epsilon > 0.0)));
167 }
168 };
169
171 {
172 cv::Size imageSize;
173
174 // 3x3 intrinsic camera matrix
175 cv::Mat K;
176
177 // Four fisheye coefficients: k1, k2, k3, k4.
178 // Standardize internally on 4x1 CV_64F matrix
179 cv::Mat D;
180
181 // Board pose for each accepted observation
182 std::vector<cv::Mat> rotationVectors;
183 std::vector<cv::Mat> translationVectors;
184
185 // Optional quality value calculated for each view
186 std::vector<double> perViewRms;
187
188 double rms{-1.0};
189
190 bool isValid() const
191 {
192 return (imageSize.width > 0 &&
193 imageSize.height > 0 &&
194 K.rows == 3 &&
195 K.cols == 3 &&
196 D.total() == 4 &&
197 rms >= 0.0);
198 }
199 };
200
202 {
203 // Transform convention:
204 //
205 // X_right = R * X_left + T
206 //
207 // R: 3x3 rotation matrix
208 // T: 3x1 translation vector.
209 cv::Mat R;
210 cv::Mat T;
211
212 // Optional quality value calculated for each stereo observation
213 std::vector<double> perPairRms;
214
215 double rms{-1.0};
216
217 bool isValid() const
218 {
219 return (R.rows == 3 &&
220 R.cols == 3 &&
221 T.total() == 3 &&
222 rms >= 0.0);
223 }
224 };
225
227 {
229
230 // Rectification rotations.
231 cv::Mat R1;
232 cv::Mat R2;
233
234 // Rectified projection matrices
235 cv::Mat P1;
236 cv::Mat P2;
237
238 // Disparity-to-depth mapping matrix
239 cv::Mat Q;
240
241 double balance{0.0};
242 double fovScale{1.0};
243
244 bool zeroDisparity{true};
245
246 bool isValid() const
247 {
248 return (outputImageSize.width > 0 &&
249 outputImageSize.height > 0 &&
250 R1.rows == 3 &&
251 R1.cols == 3 &&
252 R2.rows == 3 &&
253 R2.cols == 3 &&
254 P1.rows == 3 &&
255 P1.cols == 4 &&
256 P2.rows == 3 &&
257 P2.cols == 4 &&
258 Q.rows == 4 &&
259 Q.cols == 4);
260 }
261 };
262
264 {
265 std::size_t synchronizedPairs{0};
266 std::size_t acceptedObservations{0};
267 std::size_t rejectedDetections{0};
268
271
272 // Baseline expressed in the same unit as StereoCalibrationResult::T.
273 // It is calculated by the calibration engine, not by persistence.
274 double baseline{-1.0};
275
281 };
282
314
315} // namespace stereo_calib
316
317#endif
CameraCalibrationResult leftCamera
StereoCalibrationResult stereo
CameraCalibrationResult rightCamera
CalibrationQualityMetrics quality
std::vector< cv::Point3f > createObjectPoints() const
std::vector< cv::Point2f > leftImagePoints
std::vector< cv::Point3f > objectPoints
std::vector< cv::Point2f > rightImagePoints