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 class DerivativeCalculatorPinholeCameraPoseJacobian2nx6;
144
145 /// Forward declaration.
146 class DerivativeCalculatorFisheyeCameraPoseJacobian2x6;
147
148 /// Forward declaration.
149 template <typename T>
151
152 /// Forward declaration.
153 class DerivativeCalculatorPoseJacobianDampedDistortion2nx6;
154
155 /// Forward declaration.
156 class DerivativeCalculatorPoseZoomJacobian2nx7;
157
158 /// Forward declaration.
159 class DerivativeCalculatorPinholeCameraObjectTransformation2nx6;
160
161 /// Forward declaration.
162 class DerivativeCalculatorFisheyeCameraObjectTransformation2nx6;
163
164 /// Forward declaration.
165 class DerivativeCalculatorPinholeCameraPointJacobian2nx3;
166
167 /// Forward declaration.
168 class DerivativeCalculatorFisheyeCameraPointJacobian2x3;
169
170 /// Forward declaration.
171 class DerivativeCalculatorAnyCameraPointJacobian2x3;
172
173 /// Forward declaration.
174 class DerivativeCalculatorSphericalObjectPoint3x3;
175
176 /// Forward declaration.
177 template <typename T>
179
180 /// Forward declaration.
181 class DerivativeCalculatorPinholeCameraDistortionJacobian2x4;
182
183 /// Forward declaration.
184 class DerivativeCalculatorPinholeCameraJacobian2x6;
185
186 /// Forward declaration.
187 class DerivativeCalculatorPinholeCameraJacobian2x7;
188
189 /// Forward declaration.
190 class DerivativeCalculatorPinholeCameraJacobian2x8;
191
192 /// Forward declaration.
193 class DerivativeCalculatorFisheyeCameraJacobian2x12;
194
195 /// Forward declaration.
196 class DerivativeCalculatorOrientationPinholeCameraJacobian2x11;
197
198 /// Forward declaration.
199 class DerivativeCalculatorPosePinholeCameraJacobian2x12;
200
201 /// Forward declaration.
202 template <typename T>
204
205 /// Forward declaration.
206 template <typename T>
208
209 /// Forward declaration.
210 class DerivativeCalculatorHomography2x8;
211
212 /// Forward declaration.
213 class DerivativeCalculatorHomography2x9;
214
215 /// Forward declaration.
216 class DerivativeCalculatorIdentityHomography2x8;
217
218 /// Forward declaration.
219 class DerivativeCalculatorIdentityHomography2x9;
220
221 /// Forward declaration.
222 class DerivativeCalculatorSimilarity2x4;
223
224 /// Forward declaration.
225 template <typename T>
227
228 public:
229
230 /**
231 * Tests the entire Jacobian functionality.
232 * @param testDuration Number of seconds for each test, with range (0, infinity)
233 * @param selector Selector for individual tests
234 * @return True, if succeeded
235 */
236 static bool test(const double testDuration, const TestSelector& selector);
237
238 /**
239 * Tests the Jacobian for the rotational part of extrinsic camera parameters.
240 * @param testDuration Number of seconds for each test, with range (0, infinity)
241 * @return True, if succeeded
242 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
243 */
244 template <typename T>
245 static bool testOrientationalJacobian2x3(const double testDuration);
246
247 /**
248 * Tests the Jacobian for the orientation of a camera.
249 * @param testDuration Number of seconds for each test, with range (0, infinity)
250 * @return True, if succeeded
251 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
252 */
253 template <typename T>
254 static bool testOrientationJacobian2nx3(const double testDuration);
255
256 /**
257 * Deprecated.
258 *
259 * Tests the Jacobian for the extrinsic camera parameters and a pinhole camera.
260 * @param testDuration Number of seconds for each test, with range (0, infinity)
261 * @return True, if succeeded
262 */
263 static bool testPinholeCameraPoseJacobian2nx6(const double testDuration);
264
265 /**
266 * Deprecated.
267 *
268 * Tests the Jacobian for the extrinsic camera parameters and fisheye camera.
269 * @param testDuration Number of seconds for each test, with range (0, infinity)
270 * @return True, if succeeded
271 */
272 static bool testFisheyeCameraPoseJacobian2x6(const double testDuration);
273
274 /**
275 * Tests the Jacobian for the extrinsic camera parameters and any camera.
276 * @param testDuration Number of seconds for each test, with range (0, infinity)
277 * @return True, if succeeded
278 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
279 */
280 template <typename T>
281 static bool testAnyCameraPoseJacobian2nx6(const double testDuration);
282
283 /**
284 * Tests the Jacobian for the extrinsic camera parameters using a damped distortion.
285 * @param testDuration Number of seconds for each test, with range (0, infinity)
286 * @return True, if succeeded
287 */
288 static bool testPoseJacobianDampedDistortion2nx6(const double testDuration);
289
290 /**
291 * Tests the Jacobian for the extrinsic camera parameters (including the zoom parameter).
292 * @param testDuration Number of seconds for each test, with range (0, infinity)
293 * @return True, if succeeded
294 */
295 static bool testPoseZoomJacobian2nx7(const double testDuration);
296
297 /**
298 * Tests the 2x6 Jacobian for a 6-DOF transformation with fixed camera pose.
299 * @param testDuration Number of seconds for each test, with range (0, infinity)
300 * @return True, if succeeded
301 */
302 static bool testPinholeCameraObjectTransformation2nx6(const double testDuration);
303
304 /**
305 * Tests the 2x6 Jacobian for a 6-DOF transformation with fixed camera pose.
306 * @param testDuration Number of seconds for each test, with range (0, infinity)
307 * @return True, if succeeded
308 */
309 static bool testFisheyeCameraObjectTransformation2nx6(const double testDuration);
310
311 /**
312 * Tests the Jacobian for an 2D image point projection in relation to an object point using a pinhole camera.
313 * @param testDuration Number of seconds for each test, with range (0, infinity)
314 * @return True, if succeeded
315 */
316 static bool testPinholeCameraPointJacobian2nx3(const double testDuration);
317
318 /**
319 * Tests the Jacobian for an 2D image point projection in relation to an object point using a fisheye camera.
320 * @param testDuration Number of seconds for each test, with range (0, infinity)
321 * @return True, if succeeded
322 */
323 static bool testFisheyeCameraPointJacobian2x3(const double testDuration);
324
325 /**
326 * Tests the Jacobian for an 2D image point projection in relation to an object point using any camera.
327 * @param testDuration Number of seconds for each test, with range (0, infinity)
328 * @return True, if succeeded
329 */
330 static bool testAnyCameraPointJacobian2x3(const double testDuration);
331
332 /**
333 * Tests the Jacobian for two 6DOF poses and a set of 3D object points.
334 * @param testDuration Number of seconds for each test, with range (0, infinity)
335 * @return True, if succeeded
336 */
337 static bool testPosesPointsJacobian2nx12(const double testDuration);
338
339 /**
340 * Tests the Jacobian for an exponential map representing a 3D object point.
341 * @param testDuration Number of seconds for each test, with range (0, infinity)
342 * @return True, if succeeded
343 */
344 static bool testSphericalObjectPoint3x3(const double testDuration);
345
346 /**
347 * Tests the Jacobian for an exponential map representing a 3D object point which is projected into the camera frame.
348 * @param testDuration Number of seconds for each test, with range (0, infinity)
349 * @return True, if succeeded
350 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
351 */
352 template <typename T>
353 static bool testSphericalObjectPointOrientation2x3IF(const double testDuration);
354
355 /**
356 * Tests the Jacobian for the radial and tangential distortion camera parameters.
357 * @param testDuration Number of seconds for each test, with range (0, infinity)
358 * @return True, if succeeded
359 */
360 static bool testPinholeCameraDistortionJacobian2x4(const double testDuration);
361
362 /**
363 * Tests the Jacobian for the intrinsic and radial distortion of pinhole camera parameters.
364 * @param testDuration Number of seconds for each test, with range (0, infinity)
365 * @return True, if succeeded
366 */
367 static bool testPinholeCameraJacobian2x6(const double testDuration);
368
369 /**
370 * Tests the Jacobian for the intrinsic and radial and tangential distortion of pinhole camera parameters.
371 * @param testDuration Number of seconds for each test, with range (0, infinity)
372 * @return True, if succeeded
373 */
374 static bool testPinholeCameraJacobian2x7(const double testDuration);
375
376 /**
377 * Tests the Jacobian for the intrinsic, radial and tangential distortion of pinhole camera parameters.
378 * @param testDuration Number of seconds for each test, with range (0, infinity)
379 * @return True, if succeeded
380 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
381 */
382 template <typename T>
383 static bool testPinholeCameraJacobian2x8(const double testDuration);
384
385 /**
386 * Tests the Jacobian for the intrinsic, radial and tangential distortion of fisheye camera parameters.
387 * @param testDuration Number of seconds for each test, with range (0, infinity)
388 * @return True, if succeeded
389 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
390 */
391 template <typename T>
392 static bool testFisheyeCameraJacobian2x12(const double testDuration);
393
394 /**
395 * Tests the Jacobian for the rotational part of the extrinsic camera matrix, intrinsic and radial and tangential camera parameters.
396 * @param testDuration Number of seconds for each test, with range (0, infinity)
397 * @return True, if succeeded
398 */
399 static bool testOrientationPinholeCameraJacobian2x11(const double testDuration);
400
401 /**
402 * Tests the Jacobian for the extrinsic, intrinsic and radial camera parameters for a pinhole camera.
403 * @param testDuration Number of seconds for each test, with range (0, infinity)
404 * @return True, if succeeded
405 */
406 static bool testPosePinholeCameraJacobian2x12(const double testDuration);
407
408 /**
409 * Tests the Jacobian for the extrinsic, intrinsic and radial and tangential distortion camera parameters for a pinhole camera.
410 * @param testDuration Number of seconds for each test, with range (0, infinity)
411 * @return True, if succeeded
412 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
413 */
414 template <typename T>
415 static bool testPosePinholeCameraJacobian2x14(const double testDuration);
416
417 /**
418 * Tests the Jacobian for the extrinsic, intrinsic and radial camera parameters and distortion parameters for a fisheye camera.
419 * @param testDuration Number of seconds for each test, with range (0, infinity)
420 * @return True, if succeeded
421 */
422 template <typename T>
423 static bool testPoseFisheyeCameraJacobian2x18(const double testDuration);
424
425 /**
426 * Tests the 2x8 Jacobian for the homography.
427 * @param testDuration Number of seconds for each test, with range (0, infinity)
428 * @return True, if succeeded
429 */
430 static bool testHomography2x8(const double testDuration);
431
432 /**
433 * Tests the 2x9 Jacobian for the homography.
434 * @param testDuration Number of seconds for each test, with range (0, infinity)
435 * @return True, if succeeded
436 */
437 static bool testHomography2x9(const double testDuration);
438
439 /**
440 * Tests the 2x8 Jacobian for the identity homography.
441 * @param testDuration Number of seconds for each test, with range (0, infinity)
442 * @return True, if succeeded
443 */
444 static bool testIdentityHomography2x8(const double testDuration);
445
446 /**
447 * Tests the 2x9 Jacobian for the identity homography.
448 * @param testDuration Number of seconds for each test, with range (0, infinity)
449 * @return True, if succeeded
450 */
451 static bool testIdentityHomography2x9(const double testDuration);
452
453 /**
454 * Tests the 2x4 Jacobian of a similarity transformation.
455 * @param testDuration Number of seconds for each test, with range (0, infinity)
456 * @return True, if succeeded
457 */
458 static bool testSimilarity2x4(const double testDuration);
459
460 /**
461 * Tests the 2x2 Jacobian of the distortion of a normalized image point for a fisheye camera.
462 * @param testDuration Number of seconds for each test, with range (0, infinity)
463 * @return True, if succeeded
464 * @tparam T the data type of the scalar to be used, 'float', or 'double'
465 */
466 template <typename T>
467 static bool testCalculateFisheyeDistortNormalized2x2(const double testDuration);
468
469 private:
470
471 /**
472 * Checks if an analytical derivative matches an approximated derivative within tolerance.
473 * @param analyticalDerivative The analytical derivative value
474 * @param approximatedDerivative The numerically approximated derivative value
475 * @return True if the derivatives match within tolerance
476 * @tparam T The data type of the derivative
477 */
478 template <typename T>
479 static bool checkDerivative(const T& analyticalDerivative, const T& approximatedDerivative);
480
481 /**
482 * Checks if an analytical derivative matches an approximated derivative within tolerance.
483 * @param analyticalDerivative The analytical derivative value
484 * @param approximatedDerivative The numerically approximated derivative value
485 * @return True if the derivatives match within tolerance
486 * @tparam T The data type of the scalar, either 'float' or 'double'
487 */
488 template <typename T>
489 static bool checkScalarDerivative(const T analyticalDerivative, const T approximatedDerivative);
490
491 /**
492 * Calculates the two Jacobian rows for a given pose and dynamic object point.
493 * The derivatives are calculated for the 3D object point only.<br>
494 * The resulting Jacobian rows have the following form:<br>
495 * | dfx / dX, dfx / dY, dfx / dZ |<br>
496 * | dfy / dX, dfy / dY, dfy / dZ |<br>
497 * @param jx First row position of the jacobian, with 3 column entries receiving the point derivatives
498 * @param jy Second row position of the jacobian, with 3 column entries receiving the point derivatives
499 * @param pinholeCamera The pinhole camera to determine the Jacobian values for
500 * @param flippedCamera_T_world Pose to determine the Jacobian for (inverted and flipped)
501 * @param objectPoint 3D object point to determine the Jacobian for
502 * @param distortImagePoint True, to force the distortion of the image point using the distortion parameters of this camera object
503 * @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
504 */
505 template <bool tUseBorderDistortionIfOutside>
506 static void calculatePointJacobian2x3(Scalar* jx, Scalar* jy, const PinholeCamera& pinholeCamera, const HomogenousMatrix4& flippedCamera_T_world, const Vector3& objectPoint, const bool distortImagePoint);
507
508 /**
509 * Returns the minimal threshold necessary to succeed a verification.
510 * @return The necessary success rate, in percent, with range [0, 1]
511 */
512 static constexpr double successThreshold();
513};
514
515template <>
516inline bool TestJacobian::checkDerivative(const float& analyticalDerivative, const float& approximatedDerivative)
517{
518 return checkScalarDerivative<float>(analyticalDerivative, approximatedDerivative);
519}
520
521template <>
522inline bool TestJacobian::checkDerivative(const double& analyticalDerivative, const double& approximatedDerivative)
523{
524 return checkScalarDerivative<double>(analyticalDerivative, approximatedDerivative);
525}
526
527template <>
528inline bool TestJacobian::checkDerivative(const VectorF2& analyticalDerivative, const VectorF2& approximatedDerivative)
529{
530 if (!checkScalarDerivative<float>(analyticalDerivative.x(), approximatedDerivative.x()))
531 {
532 return false;
533 }
534
535 if (!checkScalarDerivative<float>(analyticalDerivative.y(), approximatedDerivative.y()))
536 {
537 return false;
538 }
539
540 return true;
541}
542
543template <>
544inline bool TestJacobian::checkDerivative(const VectorD2& analyticalDerivative, const VectorD2& approximatedDerivative)
545{
546 if (!checkScalarDerivative<double>(analyticalDerivative.x(), approximatedDerivative.x()))
547 {
548 return false;
549 }
550
551 if (!checkScalarDerivative<double>(analyticalDerivative.y(), approximatedDerivative.y()))
552 {
553 return false;
554 }
555
556 return true;
557}
558
559template <>
560inline bool TestJacobian::checkDerivative(const VectorF3& analyticalDerivative, const VectorF3& approximatedDerivative)
561{
562 if (!checkScalarDerivative<float>(analyticalDerivative.x(), approximatedDerivative.x()))
563 {
564 return false;
565 }
566
567 if (!checkScalarDerivative<float>(analyticalDerivative.y(), approximatedDerivative.y()))
568 {
569 return false;
570 }
571
572 if (!checkScalarDerivative<float>(analyticalDerivative.z(), approximatedDerivative.z()))
573 {
574 return false;
575 }
576
577 return true;
578}
579
580template <>
581inline bool TestJacobian::checkDerivative(const VectorD3& analyticalDerivative, const VectorD3& approximatedDerivative)
582{
583 if (!checkScalarDerivative<double>(analyticalDerivative.x(), approximatedDerivative.x()))
584 {
585 return false;
586 }
587
588 if (!checkScalarDerivative<double>(analyticalDerivative.y(), approximatedDerivative.y()))
589 {
590 return false;
591 }
592
593 if (!checkScalarDerivative<double>(analyticalDerivative.z(), approximatedDerivative.z()))
594 {
595 return false;
596 }
597
598 return true;
599}
600
601template <typename T>
602inline bool TestJacobian::checkDerivative(const T& /*analyticalDerivative*/, const T& /*approximatedDerivative*/)
603{
604 OCEAN_WARNING_MISSING_IMPLEMENTATION;
605 return false;
606}
607
608template <typename T>
609bool TestJacobian::checkScalarDerivative(const T analyticalDerivative, const T approximatedDerivative)
610{
611 const double maxAbsValue = std::max(std::abs(analyticalDerivative), std::abs(approximatedDerivative));
612 const double absDiff = std::abs(analyticalDerivative - approximatedDerivative);
613
614 if (NumericT<T>::isEqualEps(analyticalDerivative) || NumericT<T>::isEqualEps(approximatedDerivative))
615 {
616 if (absDiff > T(0.001))
617 {
618 return false;
619 }
620 }
621 else
622 {
623 if (NumericT<T>::isNotEqualEps(T(maxAbsValue)) && T(absDiff / maxAbsValue) > T(0.05))
624 {
625 return false;
626 }
627 }
628
629 return true;
630}
631
632template <bool tUseBorderDistortionIfOutside>
633void TestJacobian::calculatePointJacobian2x3(Scalar* jx, Scalar* jy, const PinholeCamera& pinholeCamera, const HomogenousMatrix4& flippedCamera_T_world, const Vector3& objectPoint, const bool distortImagePoint)
634{
635 ocean_assert(jx != nullptr && jy != nullptr);
636 ocean_assert(flippedCamera_T_world.isValid());
637
638 /**
639 * | dfx / dX, dfx / dY, dfx / dZ |<br>
640 * | dfy / dX, dfy / dY, dfy / dZ |<br>
641 */
642
643 const Scalar eps = Numeric::weakEps();
644
645 const Vector2 imagePoint(pinholeCamera.projectToImageIF<tUseBorderDistortionIfOutside>(flippedCamera_T_world, objectPoint, distortImagePoint));
646
647 for (unsigned int n = 0u; n < 3u; ++n)
648 {
649 Vector3 dObjectPoint(objectPoint);
650
651 dObjectPoint[n] += eps;
652
653 const Vector2 dImagePoint(pinholeCamera.projectToImageIF<tUseBorderDistortionIfOutside>(flippedCamera_T_world, dObjectPoint, distortImagePoint));
654
655 const Scalar dx = (dImagePoint.x() - imagePoint.x()) / eps;
656 const Scalar dy = (dImagePoint.y() - imagePoint.y()) / eps;
657
658 jx[n] = dx;
659 jy[n] = dy;
660 }
661}
662
664{
665 return 0.99;
666}
667
668}
669
670}
671
672}
673
674#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 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:633
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:602
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 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:609
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 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:663
static bool testPoseJacobianDampedDistortion2nx6(const double testDuration)
Tests the Jacobian for the extrinsic camera parameters using a damped distortion.
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