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 class DerivativeCalculatorPinholeCameraPoseJacobian2nx6;
146 class DerivativeCalculatorFisheyeCameraPoseJacobian2x6;
149 template <
typename T>
153 class DerivativeCalculatorPoseJacobianDampedDistortion2nx6;
156 class DerivativeCalculatorPoseZoomJacobian2nx7;
159 class DerivativeCalculatorPinholeCameraObjectTransformation2nx6;
162 class DerivativeCalculatorFisheyeCameraObjectTransformation2nx6;
165 class DerivativeCalculatorPinholeCameraPointJacobian2nx3;
168 class DerivativeCalculatorFisheyeCameraPointJacobian2x3;
171 class DerivativeCalculatorAnyCameraPointJacobian2x3;
174 class DerivativeCalculatorSphericalObjectPoint3x3;
177 template <
typename T>
181 class DerivativeCalculatorPinholeCameraDistortionJacobian2x4;
184 class DerivativeCalculatorPinholeCameraJacobian2x6;
187 class DerivativeCalculatorPinholeCameraJacobian2x7;
190 class DerivativeCalculatorPinholeCameraJacobian2x8;
193 class DerivativeCalculatorFisheyeCameraJacobian2x12;
196 class DerivativeCalculatorOrientationPinholeCameraJacobian2x11;
199 class DerivativeCalculatorPosePinholeCameraJacobian2x12;
202 template <
typename T>
206 template <
typename T>
210 class DerivativeCalculatorHomography2x8;
213 class DerivativeCalculatorHomography2x9;
216 class DerivativeCalculatorIdentityHomography2x8;
219 class DerivativeCalculatorIdentityHomography2x9;
222 class DerivativeCalculatorSimilarity2x4;
225 template <
typename T>
244 template <
typename T>
253 template <
typename T>
280 template <
typename T>
352 template <
typename T>
382 template <
typename T>
391 template <
typename T>
414 template <
typename T>
422 template <
typename T>
466 template <
typename T>
478 template <
typename T>
479 static bool checkDerivative(
const T& analyticalDerivative,
const T& approximatedDerivative);
488 template <
typename T>
489 static bool checkScalarDerivative(
const T analyticalDerivative,
const T approximatedDerivative);
505 template <
bool tUseBorderDistortionIfOuts
ide>
512 static constexpr double successThreshold();
518 return checkScalarDerivative<float>(analyticalDerivative, approximatedDerivative);
524 return checkScalarDerivative<double>(analyticalDerivative, approximatedDerivative);
530 if (!checkScalarDerivative<float>(analyticalDerivative.
x(), approximatedDerivative.
x()))
535 if (!checkScalarDerivative<float>(analyticalDerivative.
y(), approximatedDerivative.
y()))
546 if (!checkScalarDerivative<double>(analyticalDerivative.
x(), approximatedDerivative.
x()))
551 if (!checkScalarDerivative<double>(analyticalDerivative.
y(), approximatedDerivative.
y()))
562 if (!checkScalarDerivative<float>(analyticalDerivative.
x(), approximatedDerivative.
x()))
567 if (!checkScalarDerivative<float>(analyticalDerivative.
y(), approximatedDerivative.
y()))
572 if (!checkScalarDerivative<float>(analyticalDerivative.
z(), approximatedDerivative.
z()))
583 if (!checkScalarDerivative<double>(analyticalDerivative.
x(), approximatedDerivative.
x()))
588 if (!checkScalarDerivative<double>(analyticalDerivative.
y(), approximatedDerivative.
y()))
593 if (!checkScalarDerivative<double>(analyticalDerivative.
z(), approximatedDerivative.
z()))
604 OCEAN_WARNING_MISSING_IMPLEMENTATION;
611 const double maxAbsValue = std::max(std::abs(analyticalDerivative), std::abs(approximatedDerivative));
612 const double absDiff = std::abs(analyticalDerivative - approximatedDerivative);
616 if (absDiff > T(0.001))
632template <
bool tUseBorderDistortionIfOuts
ide>
635 ocean_assert(jx !=
nullptr && jy !=
nullptr);
636 ocean_assert(flippedCamera_T_world.
isValid());
645 const Vector2 imagePoint(pinholeCamera.
projectToImageIF<tUseBorderDistortionIfOutside>(flippedCamera_T_world, objectPoint, distortImagePoint));
647 for (
unsigned int n = 0u; n < 3u; ++n)
649 Vector3 dObjectPoint(objectPoint);
651 dObjectPoint[n] += eps;
653 const Vector2 dImagePoint(pinholeCamera.
projectToImageIF<tUseBorderDistortionIfOutside>(flippedCamera_T_world, dObjectPoint, distortImagePoint));
655 const Scalar dx = (dImagePoint.
x() - imagePoint.
x()) / eps;
656 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:150
Forward declaration.
Definition TestJacobian.h:226
Forward declaration.
Definition TestJacobian.h:140
Forward declaration.
Definition TestJacobian.h:136
Forward declaration.
Definition TestJacobian.h:207
Forward declaration.
Definition TestJacobian.h:203
Forward declaration.
Definition TestJacobian.h:178
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 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