8#ifndef META_OCEAN_TEST_TESTGEOMETRY_TEST_JACOBIAN_H
9#define META_OCEAN_TEST_TESTGEOMETRY_TEST_JACOBIAN_H
43 template <
typename T,
typename TScalar,
typename TVariable>
71 template <
typename TAnalyticalDerivative>
72 bool verifyDerivative(
const TVariable& variable,
const size_t parameterIndex,
const TAnalyticalDerivative& analyticalDerivative)
const;
84 virtual T
calculateValue(
const TVariable& variable,
const size_t parameterIndex,
const TScalar offset)
const = 0;
93 template <
typename T,
typename TScalar>
119 template <
typename TAnalyticalDerivative>
120 bool verifyDerivative(
const size_t parameterIndex,
const TAnalyticalDerivative& analyticalDerivative)
const;
131 virtual T
calculateValue(
const size_t parameterIndex,
const TScalar offset)
const = 0;
135 template <
typename T>
139 template <
typename T>
143 template <
typename T>
147 template <
typename T>
151 template <
typename T>
155 template <
typename T>
159 template <
typename T>
163 template <
typename T>
167 template <
typename T>
171 template <
typename T>
175 template <
typename T>
179 template <
typename T>
183 class DerivativeCalculatorSphericalObjectPoint3x3;
186 template <
typename T>
190 template <
typename T>
194 template <
typename T>
198 template <
typename T>
202 class DerivativeCalculatorPinholeCameraJacobian2x8;
205 class DerivativeCalculatorFisheyeCameraJacobian2x12;
208 template <
typename T>
212 template <
typename T>
216 template <
typename T>
220 template <
typename T>
224 class DerivativeCalculatorHomography2x8;
227 class DerivativeCalculatorHomography2x9;
230 class DerivativeCalculatorIdentityHomography2x8;
233 class DerivativeCalculatorIdentityHomography2x9;
236 class DerivativeCalculatorSimilarity2x4;
239 template <
typename T>
258 template <
typename T>
267 template <
typename T>
278 template <
typename T>
296 template <
typename T>
305 template <
typename T>
314 template <
typename T>
351 template <
typename T>
374 template <
typename T>
404 template <
typename T>
413 template <
typename T>
429 template <
typename T>
438 template <
typename T>
446 template <
typename T>
490 template <
typename T>
502 template <
typename T>
503 static bool checkDerivative(
const T& analyticalDerivative,
const T& approximatedDerivative);
512 template <
typename T>
513 static bool checkScalarDerivative(
const T analyticalDerivative,
const T approximatedDerivative);
529 template <
bool tUseBorderDistortionIfOuts
ide>
536 return checkScalarDerivative<float>(analyticalDerivative, approximatedDerivative);
542 return checkScalarDerivative<double>(analyticalDerivative, approximatedDerivative);
548 if (!checkScalarDerivative<float>(analyticalDerivative.
x(), approximatedDerivative.
x()))
553 if (!checkScalarDerivative<float>(analyticalDerivative.
y(), approximatedDerivative.
y()))
564 if (!checkScalarDerivative<double>(analyticalDerivative.
x(), approximatedDerivative.
x()))
569 if (!checkScalarDerivative<double>(analyticalDerivative.
y(), approximatedDerivative.
y()))
580 if (!checkScalarDerivative<float>(analyticalDerivative.
x(), approximatedDerivative.
x()))
585 if (!checkScalarDerivative<float>(analyticalDerivative.
y(), approximatedDerivative.
y()))
590 if (!checkScalarDerivative<float>(analyticalDerivative.
z(), approximatedDerivative.
z()))
601 if (!checkScalarDerivative<double>(analyticalDerivative.
x(), approximatedDerivative.
x()))
606 if (!checkScalarDerivative<double>(analyticalDerivative.
y(), approximatedDerivative.
y()))
611 if (!checkScalarDerivative<double>(analyticalDerivative.
z(), approximatedDerivative.
z()))
622 OCEAN_WARNING_MISSING_IMPLEMENTATION;
629 const double maxAbsValue = std::max(std::abs(analyticalDerivative), std::abs(approximatedDerivative));
630 const double absDiff = std::abs(analyticalDerivative - approximatedDerivative);
634 if (absDiff > T(0.001))
650template <
bool tUseBorderDistortionIfOuts
ide>
653 ocean_assert(jx !=
nullptr && jy !=
nullptr);
654 ocean_assert(flippedCamera_T_world.
isValid());
663 const Vector2 imagePoint(pinholeCamera.
projectToImageIF<tUseBorderDistortionIfOutside>(flippedCamera_T_world, objectPoint, distortImagePoint));
665 for (
unsigned int n = 0u; n < 3u; ++n)
667 Vector3 dObjectPoint(objectPoint);
669 dObjectPoint[n] += eps;
671 const Vector2 dImagePoint(pinholeCamera.
projectToImageIF<tUseBorderDistortionIfOutside>(flippedCamera_T_world, dObjectPoint, distortImagePoint));
673 const Scalar dx = (dImagePoint.
x() - imagePoint.
x()) / eps;
674 const Scalar dy = (dImagePoint.
y() - imagePoint.
y()) / eps;
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
Forward declaration.
Definition TestJacobian.h:180
Forward declaration.
Definition TestJacobian.h:152
Forward declaration.
Definition TestJacobian.h:176
Forward declaration.
Definition TestJacobian.h:148
Forward declaration.
Definition TestJacobian.h:240
Forward declaration.
Definition TestJacobian.h:140
Forward declaration.
Definition TestJacobian.h:209
Forward declaration.
Definition TestJacobian.h:136
Forward declaration.
Definition TestJacobian.h:191
Forward declaration.
Definition TestJacobian.h:195
Forward declaration.
Definition TestJacobian.h:199
Forward declaration.
Definition TestJacobian.h:172
Forward declaration.
Definition TestJacobian.h:144
Forward declaration.
Definition TestJacobian.h:221
Forward declaration.
Definition TestJacobian.h:156
Forward declaration.
Definition TestJacobian.h:213
Forward declaration.
Definition TestJacobian.h:217
Forward declaration.
Definition TestJacobian.h:160
Forward declaration.
Definition TestJacobian.h:187
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.
virtual ~DerivativeCalculatorT()=default
Default constructor.
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