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