8#ifndef META_OCEAN_TEST_TESTGEOMETRY_TEST_JACOBIAN_H
9#define META_OCEAN_TEST_TESTGEOMETRY_TEST_JACOBIAN_H
41 template <
typename T,
typename TScalar,
typename TVariable>
69 template <
typename TAnalyticalDerivative>
70 bool verifyDerivative(
const TVariable& variable,
const size_t parameterIndex,
const TAnalyticalDerivative& analyticalDerivative)
const;
82 virtual T
calculateValue(
const TVariable& variable,
const size_t parameterIndex,
const TScalar offset)
const = 0;
91 template <
typename T,
typename TScalar>
117 template <
typename TAnalyticalDerivative>
118 bool verifyDerivative(
const size_t parameterIndex,
const TAnalyticalDerivative& analyticalDerivative)
const;
129 virtual T
calculateValue(
const size_t parameterIndex,
const TScalar offset)
const = 0;
133 template <
typename T>
137 template <
typename T>
141 class DerivativeCalculatorPinholeCameraPoseJacobian2nx6;
144 class DerivativeCalculatorFisheyeCameraPoseJacobian2x6;
147 template <
typename T>
151 class DerivativeCalculatorPoseJacobianDampedDistortion2nx6;
154 class DerivativeCalculatorPoseZoomJacobian2nx7;
157 class DerivativeCalculatorPinholeCameraObjectTransformation2nx6;
160 class DerivativeCalculatorFisheyeCameraObjectTransformation2nx6;
163 class DerivativeCalculatorPinholeCameraPointJacobian2nx3;
166 class DerivativeCalculatorFisheyeCameraPointJacobian2x3;
169 class DerivativeCalculatorAnyCameraPointJacobian2x3;
172 class DerivativeCalculatorSphericalObjectPoint3x3;
175 template <
typename T>
179 class DerivativeCalculatorPinholeCameraDistortionJacobian2x4;
182 class DerivativeCalculatorPinholeCameraJacobian2x6;
185 class DerivativeCalculatorPinholeCameraJacobian2x7;
188 class DerivativeCalculatorPinholeCameraJacobian2x8;
191 class DerivativeCalculatorFisheyeCameraJacobian2x12;
194 class DerivativeCalculatorOrientationPinholeCameraJacobian2x11;
197 class DerivativeCalculatorPosePinholeCameraJacobian2x12;
200 template <
typename T>
204 template <
typename T>
208 class DerivativeCalculatorHomography2x8;
211 class DerivativeCalculatorHomography2x9;
214 class DerivativeCalculatorIdentityHomography2x8;
217 class DerivativeCalculatorIdentityHomography2x9;
220 class DerivativeCalculatorSimilarity2x4;
223 template <
typename T>
233 static bool test(
const double testDuration);
241 template <
typename T>
250 template <
typename T>
277 template <
typename T>
349 template <
typename T>
379 template <
typename T>
388 template <
typename T>
411 template <
typename T>
419 template <
typename T>
463 template <
typename T>
475 template <
typename T>
476 static bool checkDerivative(
const T& analyticalDerivative,
const T& approximatedDerivative);
485 template <
typename T>
486 static bool checkScalarDerivative(
const T analyticalDerivative,
const T approximatedDerivative);
502 template <
bool tUseBorderDistortionIfOuts
ide>
509 static constexpr double successThreshold();
515 return checkScalarDerivative<float>(analyticalDerivative, approximatedDerivative);
521 return checkScalarDerivative<double>(analyticalDerivative, approximatedDerivative);
527 if (!checkScalarDerivative<float>(analyticalDerivative.
x(), approximatedDerivative.
x()))
532 if (!checkScalarDerivative<float>(analyticalDerivative.
y(), approximatedDerivative.
y()))
543 if (!checkScalarDerivative<double>(analyticalDerivative.
x(), approximatedDerivative.
x()))
548 if (!checkScalarDerivative<double>(analyticalDerivative.
y(), approximatedDerivative.
y()))
559 if (!checkScalarDerivative<float>(analyticalDerivative.
x(), approximatedDerivative.
x()))
564 if (!checkScalarDerivative<float>(analyticalDerivative.
y(), approximatedDerivative.
y()))
569 if (!checkScalarDerivative<float>(analyticalDerivative.
z(), approximatedDerivative.
z()))
580 if (!checkScalarDerivative<double>(analyticalDerivative.
x(), approximatedDerivative.
x()))
585 if (!checkScalarDerivative<double>(analyticalDerivative.
y(), approximatedDerivative.
y()))
590 if (!checkScalarDerivative<double>(analyticalDerivative.
z(), approximatedDerivative.
z()))
601 OCEAN_WARNING_MISSING_IMPLEMENTATION;
608 const double maxAbsValue = std::max(std::abs(analyticalDerivative), std::abs(approximatedDerivative));
609 const double absDiff = std::abs(analyticalDerivative - approximatedDerivative);
613 if (absDiff > T(0.001))
629template <
bool tUseBorderDistortionIfOuts
ide>
632 ocean_assert(jx !=
nullptr && jy !=
nullptr);
633 ocean_assert(flippedCamera_T_world.
isValid());
642 const Vector2 imagePoint(pinholeCamera.
projectToImageIF<tUseBorderDistortionIfOutside>(flippedCamera_T_world, objectPoint, distortImagePoint));
644 for (
unsigned int n = 0u; n < 3u; ++n)
646 Vector3 dObjectPoint(objectPoint);
648 dObjectPoint[n] += eps;
650 const Vector2 dImagePoint(pinholeCamera.
projectToImageIF<tUseBorderDistortionIfOutside>(flippedCamera_T_world, dObjectPoint, distortImagePoint));
652 const Scalar dx = (dImagePoint.
x() - imagePoint.
x()) / eps;
653 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:148
Forward declaration.
Definition TestJacobian.h:224
Forward declaration.
Definition TestJacobian.h:138
Forward declaration.
Definition TestJacobian.h:134
Forward declaration.
Definition TestJacobian.h:205
Forward declaration.
Definition TestJacobian.h:201
Forward declaration.
Definition TestJacobian.h:176
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:43
T calculateDerivative(const TVariable &variable, const size_t parameterIndex, const TScalar epsilon=NumericT< TScalar >::weakEps() *TScalar(0.05)) const
Calculates the numerical derivative using central finite differences: f'(x) ≈ [f(x + epsilon) - f(x -...
bool verifyDerivative(const TVariable &variable, const size_t parameterIndex, const TAnalyticalDerivative &analyticalDerivative) const
Verifies an analytical derivative by comparing it with a numerical approximation.
virtual ~DerivativeCalculatorT()=default
Default constructor.
virtual T calculateValue(const TVariable &variable, const size_t parameterIndex, const TScalar offset) const =0
Calculates the function value with an offset applied to a specific parameter.
This class implements Jacobian tests.
Definition TestJacobian.h:32
static bool testIdentityHomography2x8(const double testDuration)
Tests the 2x8 Jacobian for the identity homography.
static bool testOrientationPinholeCameraJacobian2x11(const double testDuration)
Tests the Jacobian for the rotational part of the extrinsic camera matrix, intrinsic and radial and t...
static bool testSphericalObjectPointOrientation2x3IF(const double testDuration)
Tests the Jacobian for an exponential map representing a 3D object point which is projected into the ...
static bool testPinholeCameraObjectTransformation2nx6(const double testDuration)
Tests the 2x6 Jacobian for a 6-DOF transformation with fixed camera pose.
static void calculatePointJacobian2x3(Scalar *jx, Scalar *jy, const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &flippedCamera_T_world, const Vector3 &objectPoint, const bool distortImagePoint)
Calculates the two Jacobian rows for a given pose and dynamic object point.
Definition TestJacobian.h:630
static bool testPosePinholeCameraJacobian2x14(const double testDuration)
Tests the Jacobian for the extrinsic, intrinsic and radial and tangential distortion camera parameter...
static bool testPosesPointsJacobian2nx12(const double testDuration)
Tests the Jacobian for two 6DOF poses and a set of 3D object points.
static bool testAnyCameraPoseJacobian2nx6(const double testDuration)
Tests the Jacobian for the extrinsic camera parameters and any camera.
static bool testFisheyeCameraPointJacobian2x3(const double testDuration)
Tests the Jacobian for an 2D image point projection in relation to an object point using a fisheye ca...
static bool testCalculateFisheyeDistortNormalized2x2(const double testDuration)
Tests the 2x2 Jacobian of the distortion of a normalized image point for a fisheye camera.
static bool testHomography2x9(const double testDuration)
Tests the 2x9 Jacobian for the homography.
static bool checkDerivative(const T &analyticalDerivative, const T &approximatedDerivative)
Checks if an analytical derivative matches an approximated derivative within tolerance.
Definition TestJacobian.h:599
static bool testPoseZoomJacobian2nx7(const double testDuration)
Tests the Jacobian for the extrinsic camera parameters (including the zoom parameter).
static bool testSphericalObjectPoint3x3(const double testDuration)
Tests the Jacobian for an exponential map representing a 3D object point.
static bool testHomography2x8(const double testDuration)
Tests the 2x8 Jacobian for the homography.
static bool testAnyCameraPointJacobian2x3(const double testDuration)
Tests the Jacobian for an 2D image point projection in relation to an object point using any camera.
static bool testSimilarity2x4(const double testDuration)
Tests the 2x4 Jacobian of a similarity transformation.
static bool test(const double testDuration)
Tests the entire Jacobian functionality.
static bool testPoseFisheyeCameraJacobian2x18(const double testDuration)
Tests the Jacobian for the extrinsic, intrinsic and radial camera parameters and distortion parameter...
static bool testPinholeCameraDistortionJacobian2x4(const double testDuration)
Tests the Jacobian for the radial and tangential distortion camera parameters.
static bool testFisheyeCameraJacobian2x12(const double testDuration)
Tests the Jacobian for the intrinsic, radial and tangential distortion of fisheye camera parameters.
static bool checkScalarDerivative(const T analyticalDerivative, const T approximatedDerivative)
Checks if an analytical derivative matches an approximated derivative within tolerance.
Definition TestJacobian.h:606
static bool testPinholeCameraJacobian2x7(const double testDuration)
Tests the Jacobian for the intrinsic and radial and tangential distortion of pinhole camera parameter...
static bool testPosePinholeCameraJacobian2x12(const double testDuration)
Tests the Jacobian for the extrinsic, intrinsic and radial camera parameters for a pinhole camera.
static bool testFisheyeCameraObjectTransformation2nx6(const double testDuration)
Tests the 2x6 Jacobian for a 6-DOF transformation with fixed camera pose.
static bool testOrientationJacobian2nx3(const double testDuration)
Tests the Jacobian for the orientation of a camera.
static bool testPinholeCameraJacobian2x6(const double testDuration)
Tests the Jacobian for the intrinsic and radial distortion of pinhole camera parameters.
static bool testPinholeCameraJacobian2x8(const double testDuration)
Tests the Jacobian for the intrinsic, radial and tangential distortion of pinhole camera parameters.
static bool testPinholeCameraPointJacobian2nx3(const double testDuration)
Tests the Jacobian for an 2D image point projection in relation to an object point using a pinhole ca...
static bool testIdentityHomography2x9(const double testDuration)
Tests the 2x9 Jacobian for the identity homography.
static bool testFisheyeCameraPoseJacobian2x6(const double testDuration)
Deprecated.
static bool testOrientationalJacobian2x3(const double testDuration)
Tests the Jacobian for the rotational part of extrinsic camera parameters.
static bool testPinholeCameraPoseJacobian2nx6(const double testDuration)
Deprecated.
static constexpr double successThreshold()
Returns the minimal threshold necessary to succeed a verification.
Definition TestJacobian.h:660
static bool testPoseJacobianDampedDistortion2nx6(const double testDuration)
Tests the Jacobian for the extrinsic camera parameters using a damped distortion.
This class implements a vector with two elements.
Definition Vector2.h:96
const T & x() const noexcept
Returns the x value.
Definition Vector2.h:710
const T & y() const noexcept
Returns the y value.
Definition Vector2.h:722
const T & y() const noexcept
Returns the y value.
Definition Vector3.h:824
const T & x() const noexcept
Returns the x value.
Definition Vector3.h:812
const T & z() const noexcept
Returns the z value.
Definition Vector3.h:836
float Scalar
Definition of a scalar type.
Definition Math.h:129
The namespace covering the entire Ocean framework.
Definition Accessor.h:15