Ocean
Loading...
Searching...
No Matches
TestJacobian.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_TEST_TESTGEOMETRY_TEST_JACOBIAN_H
9#define META_OCEAN_TEST_TESTGEOMETRY_TEST_JACOBIAN_H
10
12
14
17
18namespace Ocean
19{
20
21namespace Test
22{
23
24namespace TestGeometry
25{
26
27/**
28 * This class implements Jacobian tests.
29 * @ingroup testgeometry
30 */
31class OCEAN_TEST_GEOMETRY_EXPORT TestJacobian : protected Geometry::Jacobian
32{
33 protected:
34
35 /**
36 * Base class for calculating numerical derivatives using central finite differences.
37 * @tparam T The data type of the derivative
38 * @tparam TScalar The scalar type for epsilon, either 'float' or 'double'
39 * @tparam TVariable The data type of a variable object which can change while while everything else is constant
40 */
41 template <typename T, typename TScalar, typename TVariable>
43 {
44 public:
45
46 /**
47 * Default constructor.
48 */
49 virtual ~DerivativeCalculatorT() = default;
50
51 /**
52 * Calculates the numerical derivative using central finite differences: f'(x) ≈ [f(x + epsilon) - f(x - epsilon)] / (2 * epsilon)
53 * @param variable The variable to calculate the derivative for
54 * @param parameterIndex The index of the parameter to perturb
55 * @param epsilon The epsilon value to use for the finite difference calculation
56 * @return The calculated derivative
57 */
58 T calculateDerivative(const TVariable& variable, const size_t parameterIndex, const TScalar epsilon = NumericT<TScalar>::weakEps() * TScalar(0.05)) const;
59
60 /**
61 * Verifies an analytical derivative by comparing it with a numerical approximation.
62 * Tests multiple epsilon values to find one that produces a match within tolerance.
63 * @param variable The variable to calculate the derivative for
64 * @param parameterIndex The index of the parameter to verify
65 * @param analyticalDerivative The analytical derivative to verify
66 * @return True if the analytical derivative matches the numerical approximation within tolerance
67 * @tparam TAnalyticalDerivative The type of the analytical derivative (e.g., Vector2, Vector3)
68 */
69 template <typename TAnalyticalDerivative>
70 bool verifyDerivative(const TVariable& variable, const size_t parameterIndex, const TAnalyticalDerivative& analyticalDerivative) const;
71
72 protected:
73
74 /**
75 * Calculates the function value with an offset applied to a specific parameter.
76 * Must be implemented by derived classes.
77 * @param variable The variable to evaluate
78 * @param parameterIndex The index of the parameter to perturb
79 * @param offset The offset to apply
80 * @return The calculated function value
81 */
82 virtual T calculateValue(const TVariable& variable, const size_t parameterIndex, const TScalar offset) const = 0;
83 };
84
85 /**
86 * Base class for calculating numerical derivatives using central finite differences.
87 * This class is a specialization of DerivativeCalculatorT without a variable object.
88 * @tparam T The result type (e.g., VectorT2<Scalar>, VectorT3<Scalar>)
89 * @tparam TScalar The scalar type for epsilon, either 'float' or 'double'
90 */
91 template <typename T, typename TScalar>
92 class DerivativeCalculatorT<T, TScalar, void>
93 {
94 public:
95
96 /**
97 * Default constructor.
98 */
99 virtual ~DerivativeCalculatorT() = default;
100
101 /**
102 * Calculates the numerical derivative using central finite differences: f'(x) ≈ [f(x + epsilon) - f(x - epsilon)] / (2 * epsilon)
103 * @param parameterIndex The index of the parameter to perturb
104 * @param epsilon The epsilon value to use for the finite difference calculation
105 * @return The calculated derivative
106 */
107 T calculateDerivative(const size_t parameterIndex, const TScalar epsilon = NumericT<TScalar>::weakEps() * TScalar(0.05)) const;
108
109 /**
110 * Verifies an analytical derivative by comparing it with a numerical approximation.
111 * Tests multiple epsilon values to find one that produces a match within tolerance.
112 * @param parameterIndex The index of the parameter to verify
113 * @param analyticalDerivative The analytical derivative to verify
114 * @return True if the analytical derivative matches the numerical approximation within tolerance
115 * @tparam TAnalyticalDerivative The type of the analytical derivative (e.g., Vector2, Vector3)
116 */
117 template <typename TAnalyticalDerivative>
118 bool verifyDerivative(const size_t parameterIndex, const TAnalyticalDerivative& analyticalDerivative) const;
119
120 protected:
121
122 /**
123 * Calculates the function value with an offset applied to a specific parameter.
124 * Must be implemented by derived classes.
125 * @param parameterIndex The index of the parameter to perturb
126 * @param offset The offset to apply
127 * @return The calculated function value
128 */
129 virtual T calculateValue(const size_t parameterIndex, const TScalar offset) const = 0;
130 };
131
132 /// Forward declaration.
133 template <typename T>
135
136 /// Forward declaration.
137 template <typename T>
139
140 /// Forward declaration.
141 class DerivativeCalculatorPinholeCameraPoseJacobian2nx6;
142
143 /// Forward declaration.
144 class DerivativeCalculatorFisheyeCameraPoseJacobian2x6;
145
146 /// Forward declaration.
147 template <typename T>
149
150 /// Forward declaration.
151 class DerivativeCalculatorPoseJacobianDampedDistortion2nx6;
152
153 /// Forward declaration.
154 class DerivativeCalculatorPoseZoomJacobian2nx7;
155
156 /// Forward declaration.
157 class DerivativeCalculatorPinholeCameraObjectTransformation2nx6;
158
159 /// Forward declaration.
160 class DerivativeCalculatorFisheyeCameraObjectTransformation2nx6;
161
162 /// Forward declaration.
163 class DerivativeCalculatorPinholeCameraPointJacobian2nx3;
164
165 /// Forward declaration.
166 class DerivativeCalculatorFisheyeCameraPointJacobian2x3;
167
168 /// Forward declaration.
169 class DerivativeCalculatorAnyCameraPointJacobian2x3;
170
171 /// Forward declaration.
172 class DerivativeCalculatorSphericalObjectPoint3x3;
173
174 /// Forward declaration.
175 template <typename T>
177
178 /// Forward declaration.
179 class DerivativeCalculatorPinholeCameraDistortionJacobian2x4;
180
181 /// Forward declaration.
182 class DerivativeCalculatorPinholeCameraJacobian2x6;
183
184 /// Forward declaration.
185 class DerivativeCalculatorPinholeCameraJacobian2x7;
186
187 /// Forward declaration.
188 class DerivativeCalculatorPinholeCameraJacobian2x8;
189
190 /// Forward declaration.
191 class DerivativeCalculatorFisheyeCameraJacobian2x12;
192
193 /// Forward declaration.
194 class DerivativeCalculatorOrientationPinholeCameraJacobian2x11;
195
196 /// Forward declaration.
197 class DerivativeCalculatorPosePinholeCameraJacobian2x12;
198
199 /// Forward declaration.
200 template <typename T>
202
203 /// Forward declaration.
204 template <typename T>
206
207 /// Forward declaration.
208 class DerivativeCalculatorHomography2x8;
209
210 /// Forward declaration.
211 class DerivativeCalculatorHomography2x9;
212
213 /// Forward declaration.
214 class DerivativeCalculatorIdentityHomography2x8;
215
216 /// Forward declaration.
217 class DerivativeCalculatorIdentityHomography2x9;
218
219 /// Forward declaration.
220 class DerivativeCalculatorSimilarity2x4;
221
222 /// Forward declaration.
223 template <typename T>
225
226 public:
227
228 /**
229 * Tests the entire Jacobian functionality.
230 * @param testDuration Number of seconds for each test, with range (0, infinity)
231 * @return True, if succeeded
232 */
233 static bool test(const double testDuration);
234
235 /**
236 * Tests the Jacobian for the rotational part of extrinsic camera parameters.
237 * @param testDuration Number of seconds for each test, with range (0, infinity)
238 * @return True, if succeeded
239 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
240 */
241 template <typename T>
242 static bool testOrientationalJacobian2x3(const double testDuration);
243
244 /**
245 * Tests the Jacobian for the orientation of a camera.
246 * @param testDuration Number of seconds for each test, with range (0, infinity)
247 * @return True, if succeeded
248 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
249 */
250 template <typename T>
251 static bool testOrientationJacobian2nx3(const double testDuration);
252
253 /**
254 * Deprecated.
255 *
256 * Tests the Jacobian for the extrinsic camera parameters and a pinhole camera.
257 * @param testDuration Number of seconds for each test, with range (0, infinity)
258 * @return True, if succeeded
259 */
260 static bool testPinholeCameraPoseJacobian2nx6(const double testDuration);
261
262 /**
263 * Deprecated.
264 *
265 * Tests the Jacobian for the extrinsic camera parameters and fisheye camera.
266 * @param testDuration Number of seconds for each test, with range (0, infinity)
267 * @return True, if succeeded
268 */
269 static bool testFisheyeCameraPoseJacobian2x6(const double testDuration);
270
271 /**
272 * Tests the Jacobian for the extrinsic camera parameters and any camera.
273 * @param testDuration Number of seconds for each test, with range (0, infinity)
274 * @return True, if succeeded
275 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
276 */
277 template <typename T>
278 static bool testAnyCameraPoseJacobian2nx6(const double testDuration);
279
280 /**
281 * Tests the Jacobian for the extrinsic camera parameters using a damped distortion.
282 * @param testDuration Number of seconds for each test, with range (0, infinity)
283 * @return True, if succeeded
284 */
285 static bool testPoseJacobianDampedDistortion2nx6(const double testDuration);
286
287 /**
288 * Tests the Jacobian for the extrinsic camera parameters (including the zoom parameter).
289 * @param testDuration Number of seconds for each test, with range (0, infinity)
290 * @return True, if succeeded
291 */
292 static bool testPoseZoomJacobian2nx7(const double testDuration);
293
294 /**
295 * Tests the 2x6 Jacobian for a 6-DOF transformation with fixed camera pose.
296 * @param testDuration Number of seconds for each test, with range (0, infinity)
297 * @return True, if succeeded
298 */
299 static bool testPinholeCameraObjectTransformation2nx6(const double testDuration);
300
301 /**
302 * Tests the 2x6 Jacobian for a 6-DOF transformation with fixed camera pose.
303 * @param testDuration Number of seconds for each test, with range (0, infinity)
304 * @return True, if succeeded
305 */
306 static bool testFisheyeCameraObjectTransformation2nx6(const double testDuration);
307
308 /**
309 * Tests the Jacobian for an 2D image point projection in relation to an object point using a pinhole camera.
310 * @param testDuration Number of seconds for each test, with range (0, infinity)
311 * @return True, if succeeded
312 */
313 static bool testPinholeCameraPointJacobian2nx3(const double testDuration);
314
315 /**
316 * Tests the Jacobian for an 2D image point projection in relation to an object point using a fisheye camera.
317 * @param testDuration Number of seconds for each test, with range (0, infinity)
318 * @return True, if succeeded
319 */
320 static bool testFisheyeCameraPointJacobian2x3(const double testDuration);
321
322 /**
323 * Tests the Jacobian for an 2D image point projection in relation to an object point using any camera.
324 * @param testDuration Number of seconds for each test, with range (0, infinity)
325 * @return True, if succeeded
326 */
327 static bool testAnyCameraPointJacobian2x3(const double testDuration);
328
329 /**
330 * Tests the Jacobian for two 6DOF poses and a set of 3D object points.
331 * @param testDuration Number of seconds for each test, with range (0, infinity)
332 * @return True, if succeeded
333 */
334 static bool testPosesPointsJacobian2nx12(const double testDuration);
335
336 /**
337 * Tests the Jacobian for an exponential map representing a 3D object point.
338 * @param testDuration Number of seconds for each test, with range (0, infinity)
339 * @return True, if succeeded
340 */
341 static bool testSphericalObjectPoint3x3(const double testDuration);
342
343 /**
344 * Tests the Jacobian for an exponential map representing a 3D object point which is projected into the camera frame.
345 * @param testDuration Number of seconds for each test, with range (0, infinity)
346 * @return True, if succeeded
347 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
348 */
349 template <typename T>
350 static bool testSphericalObjectPointOrientation2x3IF(const double testDuration);
351
352 /**
353 * Tests the Jacobian for the radial and tangential distortion camera parameters.
354 * @param testDuration Number of seconds for each test, with range (0, infinity)
355 * @return True, if succeeded
356 */
357 static bool testPinholeCameraDistortionJacobian2x4(const double testDuration);
358
359 /**
360 * Tests the Jacobian for the intrinsic and radial distortion of pinhole camera parameters.
361 * @param testDuration Number of seconds for each test, with range (0, infinity)
362 * @return True, if succeeded
363 */
364 static bool testPinholeCameraJacobian2x6(const double testDuration);
365
366 /**
367 * Tests the Jacobian for the intrinsic and radial and tangential distortion of pinhole camera parameters.
368 * @param testDuration Number of seconds for each test, with range (0, infinity)
369 * @return True, if succeeded
370 */
371 static bool testPinholeCameraJacobian2x7(const double testDuration);
372
373 /**
374 * Tests the Jacobian for the intrinsic, radial and tangential distortion of pinhole camera parameters.
375 * @param testDuration Number of seconds for each test, with range (0, infinity)
376 * @return True, if succeeded
377 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
378 */
379 template <typename T>
380 static bool testPinholeCameraJacobian2x8(const double testDuration);
381
382 /**
383 * Tests the Jacobian for the intrinsic, radial and tangential distortion of fisheye camera parameters.
384 * @param testDuration Number of seconds for each test, with range (0, infinity)
385 * @return True, if succeeded
386 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
387 */
388 template <typename T>
389 static bool testFisheyeCameraJacobian2x12(const double testDuration);
390
391 /**
392 * Tests the Jacobian for the rotational part of the extrinsic camera matrix, intrinsic and radial and tangential camera parameters.
393 * @param testDuration Number of seconds for each test, with range (0, infinity)
394 * @return True, if succeeded
395 */
396 static bool testOrientationPinholeCameraJacobian2x11(const double testDuration);
397
398 /**
399 * Tests the Jacobian for the extrinsic, intrinsic and radial camera parameters for a pinhole camera.
400 * @param testDuration Number of seconds for each test, with range (0, infinity)
401 * @return True, if succeeded
402 */
403 static bool testPosePinholeCameraJacobian2x12(const double testDuration);
404
405 /**
406 * Tests the Jacobian for the extrinsic, intrinsic and radial and tangential distortion camera parameters for a pinhole camera.
407 * @param testDuration Number of seconds for each test, with range (0, infinity)
408 * @return True, if succeeded
409 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
410 */
411 template <typename T>
412 static bool testPosePinholeCameraJacobian2x14(const double testDuration);
413
414 /**
415 * Tests the Jacobian for the extrinsic, intrinsic and radial camera parameters and distortion parameters for a fisheye camera.
416 * @param testDuration Number of seconds for each test, with range (0, infinity)
417 * @return True, if succeeded
418 */
419 template <typename T>
420 static bool testPoseFisheyeCameraJacobian2x18(const double testDuration);
421
422 /**
423 * Tests the 2x8 Jacobian for the homography.
424 * @param testDuration Number of seconds for each test, with range (0, infinity)
425 * @return True, if succeeded
426 */
427 static bool testHomography2x8(const double testDuration);
428
429 /**
430 * Tests the 2x9 Jacobian for the homography.
431 * @param testDuration Number of seconds for each test, with range (0, infinity)
432 * @return True, if succeeded
433 */
434 static bool testHomography2x9(const double testDuration);
435
436 /**
437 * Tests the 2x8 Jacobian for the identity homography.
438 * @param testDuration Number of seconds for each test, with range (0, infinity)
439 * @return True, if succeeded
440 */
441 static bool testIdentityHomography2x8(const double testDuration);
442
443 /**
444 * Tests the 2x9 Jacobian for the identity homography.
445 * @param testDuration Number of seconds for each test, with range (0, infinity)
446 * @return True, if succeeded
447 */
448 static bool testIdentityHomography2x9(const double testDuration);
449
450 /**
451 * Tests the 2x4 Jacobian of a similarity transformation.
452 * @param testDuration Number of seconds for each test, with range (0, infinity)
453 * @return True, if succeeded
454 */
455 static bool testSimilarity2x4(const double testDuration);
456
457 /**
458 * Tests the 2x2 Jacobian of the distortion of a normalized image point for a fisheye camera.
459 * @param testDuration Number of seconds for each test, with range (0, infinity)
460 * @return True, if succeeded
461 * @tparam T the data type of the scalar to be used, 'float', or 'double'
462 */
463 template <typename T>
464 static bool testCalculateFisheyeDistortNormalized2x2(const double testDuration);
465
466 private:
467
468 /**
469 * Checks if an analytical derivative matches an approximated derivative within tolerance.
470 * @param analyticalDerivative The analytical derivative value
471 * @param approximatedDerivative The numerically approximated derivative value
472 * @return True if the derivatives match within tolerance
473 * @tparam T The data type of the derivative
474 */
475 template <typename T>
476 static bool checkDerivative(const T& analyticalDerivative, const T& approximatedDerivative);
477
478 /**
479 * Checks if an analytical derivative matches an approximated derivative within tolerance.
480 * @param analyticalDerivative The analytical derivative value
481 * @param approximatedDerivative The numerically approximated derivative value
482 * @return True if the derivatives match within tolerance
483 * @tparam T The data type of the scalar, either 'float' or 'double'
484 */
485 template <typename T>
486 static bool checkScalarDerivative(const T analyticalDerivative, const T approximatedDerivative);
487
488 /**
489 * Calculates the two Jacobian rows for a given pose and dynamic object point.
490 * The derivatives are calculated for the 3D object point only.<br>
491 * The resulting Jacobian rows have the following form:<br>
492 * | dfx / dX, dfx / dY, dfx / dZ |<br>
493 * | dfy / dX, dfy / dY, dfy / dZ |<br>
494 * @param jx First row position of the jacobian, with 3 column entries receiving the point derivatives
495 * @param jy Second row position of the jacobian, with 3 column entries receiving the point derivatives
496 * @param pinholeCamera The pinhole camera to determine the Jacobian values for
497 * @param flippedCamera_T_world Pose to determine the Jacobian for (inverted and flipped)
498 * @param objectPoint 3D object point to determine the Jacobian for
499 * @param distortImagePoint True, to force the distortion of the image point using the distortion parameters of this camera object
500 * @tparam tUseBorderDistortionIfOutside True, to apply the distortion from the nearest point lying on the frame border if the point lies outside the visible camera area; False to apply the distortion from the given position
501 */
502 template <bool tUseBorderDistortionIfOutside>
503 static void calculatePointJacobian2x3(Scalar* jx, Scalar* jy, const PinholeCamera& pinholeCamera, const HomogenousMatrix4& flippedCamera_T_world, const Vector3& objectPoint, const bool distortImagePoint);
504
505 /**
506 * Returns the minimal threshold necessary to succeed a verification.
507 * @return The necessary success rate, in percent, with range [0, 1]
508 */
509 static constexpr double successThreshold();
510};
511
512template <>
513inline bool TestJacobian::checkDerivative(const float& analyticalDerivative, const float& approximatedDerivative)
514{
515 return checkScalarDerivative<float>(analyticalDerivative, approximatedDerivative);
516}
517
518template <>
519inline bool TestJacobian::checkDerivative(const double& analyticalDerivative, const double& approximatedDerivative)
520{
521 return checkScalarDerivative<double>(analyticalDerivative, approximatedDerivative);
522}
523
524template <>
525inline bool TestJacobian::checkDerivative(const VectorF2& analyticalDerivative, const VectorF2& approximatedDerivative)
526{
527 if (!checkScalarDerivative<float>(analyticalDerivative.x(), approximatedDerivative.x()))
528 {
529 return false;
530 }
531
532 if (!checkScalarDerivative<float>(analyticalDerivative.y(), approximatedDerivative.y()))
533 {
534 return false;
535 }
536
537 return true;
538}
539
540template <>
541inline bool TestJacobian::checkDerivative(const VectorD2& analyticalDerivative, const VectorD2& approximatedDerivative)
542{
543 if (!checkScalarDerivative<double>(analyticalDerivative.x(), approximatedDerivative.x()))
544 {
545 return false;
546 }
547
548 if (!checkScalarDerivative<double>(analyticalDerivative.y(), approximatedDerivative.y()))
549 {
550 return false;
551 }
552
553 return true;
554}
555
556template <>
557inline bool TestJacobian::checkDerivative(const VectorF3& analyticalDerivative, const VectorF3& approximatedDerivative)
558{
559 if (!checkScalarDerivative<float>(analyticalDerivative.x(), approximatedDerivative.x()))
560 {
561 return false;
562 }
563
564 if (!checkScalarDerivative<float>(analyticalDerivative.y(), approximatedDerivative.y()))
565 {
566 return false;
567 }
568
569 if (!checkScalarDerivative<float>(analyticalDerivative.z(), approximatedDerivative.z()))
570 {
571 return false;
572 }
573
574 return true;
575}
576
577template <>
578inline bool TestJacobian::checkDerivative(const VectorD3& analyticalDerivative, const VectorD3& approximatedDerivative)
579{
580 if (!checkScalarDerivative<double>(analyticalDerivative.x(), approximatedDerivative.x()))
581 {
582 return false;
583 }
584
585 if (!checkScalarDerivative<double>(analyticalDerivative.y(), approximatedDerivative.y()))
586 {
587 return false;
588 }
589
590 if (!checkScalarDerivative<double>(analyticalDerivative.z(), approximatedDerivative.z()))
591 {
592 return false;
593 }
594
595 return true;
596}
597
598template <typename T>
599inline bool TestJacobian::checkDerivative(const T& /*analyticalDerivative*/, const T& /*approximatedDerivative*/)
600{
601 OCEAN_WARNING_MISSING_IMPLEMENTATION;
602 return false;
603}
604
605template <typename T>
606bool TestJacobian::checkScalarDerivative(const T analyticalDerivative, const T approximatedDerivative)
607{
608 const double maxAbsValue = std::max(std::abs(analyticalDerivative), std::abs(approximatedDerivative));
609 const double absDiff = std::abs(analyticalDerivative - approximatedDerivative);
610
611 if (NumericT<T>::isEqualEps(analyticalDerivative) || NumericT<T>::isEqualEps(approximatedDerivative))
612 {
613 if (absDiff > T(0.001))
614 {
615 return false;
616 }
617 }
618 else
619 {
620 if (NumericT<T>::isNotEqualEps(T(maxAbsValue)) && T(absDiff / maxAbsValue) > T(0.05))
621 {
622 return false;
623 }
624 }
625
626 return true;
627}
628
629template <bool tUseBorderDistortionIfOutside>
630void TestJacobian::calculatePointJacobian2x3(Scalar* jx, Scalar* jy, const PinholeCamera& pinholeCamera, const HomogenousMatrix4& flippedCamera_T_world, const Vector3& objectPoint, const bool distortImagePoint)
631{
632 ocean_assert(jx != nullptr && jy != nullptr);
633 ocean_assert(flippedCamera_T_world.isValid());
634
635 /**
636 * | dfx / dX, dfx / dY, dfx / dZ |<br>
637 * | dfy / dX, dfy / dY, dfy / dZ |<br>
638 */
639
640 const Scalar eps = Numeric::weakEps();
641
642 const Vector2 imagePoint(pinholeCamera.projectToImageIF<tUseBorderDistortionIfOutside>(flippedCamera_T_world, objectPoint, distortImagePoint));
643
644 for (unsigned int n = 0u; n < 3u; ++n)
645 {
646 Vector3 dObjectPoint(objectPoint);
647
648 dObjectPoint[n] += eps;
649
650 const Vector2 dImagePoint(pinholeCamera.projectToImageIF<tUseBorderDistortionIfOutside>(flippedCamera_T_world, dObjectPoint, distortImagePoint));
651
652 const Scalar dx = (dImagePoint.x() - imagePoint.x()) / eps;
653 const Scalar dy = (dImagePoint.y() - imagePoint.y()) / eps;
654
655 jx[n] = dx;
656 jy[n] = dy;
657 }
658}
659
661{
662 return 0.99;
663}
664
665}
666
667}
668
669}
670
671#endif // META_OCEAN_TEST_TESTGEOMETRY_TEST_JACOBIAN_H
This class implements function to calculate the jacobian matrices for geometry functions.
Definition Jacobian.h:37
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1806
This class provides basic numeric functionalities.
Definition Numeric.h:57
static constexpr T weakEps()
Returns a weak epsilon.
VectorT2< T > projectToImageIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const VectorT3< T > &objectPoint, const bool distortImagePoint, const T zoom=T(1)) const
Projects a 3D object point to the 2D image plane of the camera by a given inverse camera pose.
Definition PinholeCamera.h:2006
virtual T calculateValue(const size_t parameterIndex, const TScalar offset) const =0
Calculates the function value with an offset applied to a specific parameter.
T calculateDerivative(const size_t parameterIndex, const TScalar epsilon=NumericT< TScalar >::weakEps() *TScalar(0.05)) const
Calculates the numerical derivative using central finite differences: f'(x) ≈ [f(x + epsilon) - f(x -...
bool verifyDerivative(const size_t parameterIndex, const TAnalyticalDerivative &analyticalDerivative) const
Verifies an analytical derivative by comparing it with a numerical approximation.
Base class for calculating numerical derivatives using central finite differences.
Definition TestJacobian.h:43
T calculateDerivative(const TVariable &variable, const size_t parameterIndex, const TScalar epsilon=NumericT< TScalar >::weakEps() *TScalar(0.05)) const
Calculates the numerical derivative using central finite differences: f'(x) ≈ [f(x + epsilon) - f(x -...
bool verifyDerivative(const TVariable &variable, const size_t parameterIndex, const TAnalyticalDerivative &analyticalDerivative) const
Verifies an analytical derivative by comparing it with a numerical approximation.
virtual ~DerivativeCalculatorT()=default
Default constructor.
virtual T calculateValue(const TVariable &variable, const size_t parameterIndex, const TScalar offset) const =0
Calculates the function value with an offset applied to a specific parameter.
This class implements Jacobian tests.
Definition TestJacobian.h:32
static bool testIdentityHomography2x8(const double testDuration)
Tests the 2x8 Jacobian for the identity homography.
static bool testOrientationPinholeCameraJacobian2x11(const double testDuration)
Tests the Jacobian for the rotational part of the extrinsic camera matrix, intrinsic and radial and t...
static bool testSphericalObjectPointOrientation2x3IF(const double testDuration)
Tests the Jacobian for an exponential map representing a 3D object point which is projected into the ...
static bool testPinholeCameraObjectTransformation2nx6(const double testDuration)
Tests the 2x6 Jacobian for a 6-DOF transformation with fixed camera pose.
static void calculatePointJacobian2x3(Scalar *jx, Scalar *jy, const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &flippedCamera_T_world, const Vector3 &objectPoint, const bool distortImagePoint)
Calculates the two Jacobian rows for a given pose and dynamic object point.
Definition TestJacobian.h:630
static bool testPosePinholeCameraJacobian2x14(const double testDuration)
Tests the Jacobian for the extrinsic, intrinsic and radial and tangential distortion camera parameter...
static bool testPosesPointsJacobian2nx12(const double testDuration)
Tests the Jacobian for two 6DOF poses and a set of 3D object points.
static bool testAnyCameraPoseJacobian2nx6(const double testDuration)
Tests the Jacobian for the extrinsic camera parameters and any camera.
static bool testFisheyeCameraPointJacobian2x3(const double testDuration)
Tests the Jacobian for an 2D image point projection in relation to an object point using a fisheye ca...
static bool testCalculateFisheyeDistortNormalized2x2(const double testDuration)
Tests the 2x2 Jacobian of the distortion of a normalized image point for a fisheye camera.
static bool testHomography2x9(const double testDuration)
Tests the 2x9 Jacobian for the homography.
static bool checkDerivative(const T &analyticalDerivative, const T &approximatedDerivative)
Checks if an analytical derivative matches an approximated derivative within tolerance.
Definition TestJacobian.h:599
static bool testPoseZoomJacobian2nx7(const double testDuration)
Tests the Jacobian for the extrinsic camera parameters (including the zoom parameter).
static bool testSphericalObjectPoint3x3(const double testDuration)
Tests the Jacobian for an exponential map representing a 3D object point.
static bool testHomography2x8(const double testDuration)
Tests the 2x8 Jacobian for the homography.
static bool testAnyCameraPointJacobian2x3(const double testDuration)
Tests the Jacobian for an 2D image point projection in relation to an object point using any camera.
static bool testSimilarity2x4(const double testDuration)
Tests the 2x4 Jacobian of a similarity transformation.
static bool test(const double testDuration)
Tests the entire Jacobian functionality.
static bool testPoseFisheyeCameraJacobian2x18(const double testDuration)
Tests the Jacobian for the extrinsic, intrinsic and radial camera parameters and distortion parameter...
static bool testPinholeCameraDistortionJacobian2x4(const double testDuration)
Tests the Jacobian for the radial and tangential distortion camera parameters.
static bool testFisheyeCameraJacobian2x12(const double testDuration)
Tests the Jacobian for the intrinsic, radial and tangential distortion of fisheye camera parameters.
static bool checkScalarDerivative(const T analyticalDerivative, const T approximatedDerivative)
Checks if an analytical derivative matches an approximated derivative within tolerance.
Definition TestJacobian.h:606
static bool testPinholeCameraJacobian2x7(const double testDuration)
Tests the Jacobian for the intrinsic and radial and tangential distortion of pinhole camera parameter...
static bool testPosePinholeCameraJacobian2x12(const double testDuration)
Tests the Jacobian for the extrinsic, intrinsic and radial camera parameters for a pinhole camera.
static bool testFisheyeCameraObjectTransformation2nx6(const double testDuration)
Tests the 2x6 Jacobian for a 6-DOF transformation with fixed camera pose.
static bool testOrientationJacobian2nx3(const double testDuration)
Tests the Jacobian for the orientation of a camera.
static bool testPinholeCameraJacobian2x6(const double testDuration)
Tests the Jacobian for the intrinsic and radial distortion of pinhole camera parameters.
static bool testPinholeCameraJacobian2x8(const double testDuration)
Tests the Jacobian for the intrinsic, radial and tangential distortion of pinhole camera parameters.
static bool testPinholeCameraPointJacobian2nx3(const double testDuration)
Tests the Jacobian for an 2D image point projection in relation to an object point using a pinhole ca...
static bool testIdentityHomography2x9(const double testDuration)
Tests the 2x9 Jacobian for the identity homography.
static bool testFisheyeCameraPoseJacobian2x6(const double testDuration)
Deprecated.
static bool testOrientationalJacobian2x3(const double testDuration)
Tests the Jacobian for the rotational part of extrinsic camera parameters.
static bool testPinholeCameraPoseJacobian2nx6(const double testDuration)
Deprecated.
static constexpr double successThreshold()
Returns the minimal threshold necessary to succeed a verification.
Definition TestJacobian.h:660
static bool testPoseJacobianDampedDistortion2nx6(const double testDuration)
Tests the Jacobian for the extrinsic camera parameters using a damped distortion.
This class implements a vector with two elements.
Definition Vector2.h:96
const T & x() const noexcept
Returns the x value.
Definition Vector2.h:710
const T & y() const noexcept
Returns the y value.
Definition Vector2.h:722
const T & y() const noexcept
Returns the y value.
Definition Vector3.h:824
const T & x() const noexcept
Returns the x value.
Definition Vector3.h:812
const T & z() const noexcept
Returns the z value.
Definition Vector3.h:836
float Scalar
Definition of a scalar type.
Definition Math.h:129
The namespace covering the entire Ocean framework.
Definition Accessor.h:15