8#ifndef META_OCEAN_MATH_PINHOLE_CAMERA_H
9#define META_OCEAN_MATH_PINHOLE_CAMERA_H
296 PinholeCameraT(
const unsigned int width,
const unsigned int height,
const T focalX,
const T focalY,
const T principalX,
const T principalY);
372 template <
typename U>
383 template <
typename TParameter>
521 template <
typename TParameter>
540 void copyElements(T* arrayValues,
const bool copyRadialDistortion =
true,
const bool copyTangentialDistortion =
true)
const;
577 bool isDistortionPlausible(
const T symmetricFocalLengthRatio = T(1.05),
const T modelAccuracy = T(0.001),
const T symmetricDistortionRatio = T(1.08))
const;
589 template <
bool tUseBorderDistortionIfOuts
ide>
619 template <
bool tUseBorderDistortionIfOuts
ide>
676 template <
bool tUseBorderDistortionIfOuts
ide>
695 template <
bool tUseBorderDistortionIfOuts
ide>
706 template <
bool tUseBorderDistortionIfOuts
ide>
724 template <
bool tUseBorderDistortionIfOuts
ide>
741 template <
bool tUseBorderDistortionIfOuts
ide>
758 template <
bool tUseBorderDistortionIfOuts
ide>
776 template <
bool tUseBorderDistortionIfOuts
ide>
792 template <
bool tUseBorderDistortionIfOuts
ide>
810 template <
bool tUseBorderDistortionIfOuts
ide>
827 template <
bool tDistortImagePo
int,
bool tUseBorderDistortionIfOuts
ide>
844 template <
bool tUseBorderDistortionIfOuts
ide>
861 template <
bool tUseBorderDistortionIfOuts
ide>
874 template <
bool tUseBorderDistortionIfOuts
ide>
892 template <
bool tUseBorderDistortionIfOuts
ide>
908 template <
bool tUseBorderDistortionIfOuts
ide>
1175 template <
typename U,
bool tUseDistortionParameters>
1202 explicit inline operator bool()
const;
1225 template <
bool tUseBorderDistortionIfOuts
ide>
1269 VectorT2<T> dampedNormalized(
const VectorT2<T>& normalized,
const T dampingFactor,
const T leftNormalizedBorder,
const T rightNormalizedBorder,
const T topNormalizedBorder,
const T bottomNormalizedBorder)
const;
1292template <
typename T>
1298template <
typename T>
1302 return distortionLookupTable.bilinearValue(distortedImagePoint.
x(), distortedImagePoint.
y()) + distortedImagePoint;
1305template <
typename T>
1312template <
typename T>
1316 return distortionLookupTable.bicubicValue(distortedImagePoint.
x(), distortedImagePoint.
y()) + distortedImagePoint;
1319template <
typename T>
1326template <
typename T>
1332template <
typename T>
1338template <
typename T>
1344template <
typename T>
1350template <
typename T>
1351template <
typename U>
1355 if (copyDistortionParameters)
1362template <
typename T>
1363template <
typename TParameter>
1366 static_assert((std::is_same<TParameter, float>::value) || (std::is_same<TParameter, double>::value),
"Invalid TParameter, must be 'float' or 'double'!");
1369 ocean_assert(parameters !=
nullptr);
1371 switch (parameterConfiguration)
1375 const T focalLength = T(parameters[0]);
1404 const T focalLength = T(parameters[0]);
1409 const T radialDistortion0 = T(parameters[3]);
1410 const T radialDistortion1 = T(parameters[4]);
1412 const T tangentialDistortion0 = T(parameters[5]);
1413 const T tangentialDistortion1 = T(parameters[6]);
1427 const T radialDistortion0 = T(parameters[4]);
1428 const T radialDistortion1 = T(parameters[5]);
1430 const T tangentialDistortion0 = T(parameters[6]);
1431 const T tangentialDistortion1 = T(parameters[7]);
1441 ocean_assert(
false &&
"Invalid parameter configuration!");
1444template <
typename T>
1451template <
typename T>
1457template <
typename T>
1463template <
typename T>
1469template <
typename T>
1475template <
typename T>
1481template <
typename T>
1487template <
typename T>
1493template <
typename T>
1502template <
typename T>
1511template <
typename T>
1517template <
typename T>
1523template <
typename T>
1524template <
bool tUseBorderDistortionIfOuts
ide>
1527 ocean_assert(iterations >= 1u && iterations <= 1000u && zoom >
NumericT<T>::eps());
1535 const T invZoom = T(1) / zoom;
1540 VectorT2<T> nIntermediateUndistorted(nDistorted - nMainOffset);
1542 unsigned int i = 0u;
1544 while (i++ < iterations)
1547 const VectorT2<T> nIntermediateOffset(nDistorted - nIntermediateDistorted);
1549 nIntermediateUndistorted = nIntermediateUndistorted + nIntermediateOffset * T(0.75);
1554 if (offsetPixelX < 0.05 && offsetPixelY < 0.05)
1559 if (offsetPixelX > T(
width_ * 10u) || offsetPixelY > T(
height_ * 10u))
1568template <
typename T>
1569template <
bool tUseBorderDistortionIfOuts
ide>
1574 if constexpr (tUseBorderDistortionIfOutside)
1582 const T
sqr = clampedNormalizedImagePoint.
sqr();
1586 const T tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * clampedNormalizedImagePoint.
x() * clampedNormalizedImagePoint.
y()
1600 const T
sqr = nUndistorted.
sqr();
1604 const T tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * nUndistorted.
x() * nUndistorted.
y()
1620template <
typename T>
1621template <
typename TParameter>
1643 ocean_assert(parameters.size() == 8);
1658template <
typename T>
1662 ocean_assert(signedBorder < T(std::min(
width_ / 2u,
height_ / 2u)));
1664 return imagePoint.
x() >= signedBorder && imagePoint.
y() >= signedBorder
1665 && imagePoint.
x() < T(
width_) - signedBorder && imagePoint.
y() < T(
height_) - signedBorder;
1668template <
typename T>
1675 debugCameraMatrix(0, 0) *= zoom;
1676 debugCameraMatrix(1, 1) *= zoom;
1677 debugCameraMatrix[15] = 1;
1683 ocean_assert(transformationMatrix.
isValid());
1685 ocean_assert(transformationMatrix == debugTransformationMatrix);
1691template <
typename T>
1692template <
typename U,
bool tUseDistortionParameters>
1696 ocean_assert(jx !=
nullptr && jy !=
nullptr);
1700 const U x = U(flippedCameraObjectPoint.
x());
1701 const U y = U(flippedCameraObjectPoint.
y());
1702 const U z = U(flippedCameraObjectPoint.
z());
1714 const U invZ = U(1) / z;
1716 const U u = x * invZ;
1717 const U v = y * invZ;
1719 const U dist1_u = U(1) + U(6) * p2 * u + U(2) * p1 * v + k1 * (U(3) * u * u + v * v) + k2 * (u * u + v * v) * (U(5) * u * u + v * v);
1720 const U dist2_u_1_v = U(2) * (p1 * u + v * (p2 + u * (k1 + U(2) * k2 * (u * u + v * v))));
1721 const U dist2_v = U(1) + U(2) * p2 * u + U(6) * p1 * v + k1 * (u * u + U(3) * v * v) + k2 * (u * u + v * v) * (u * u + U(5) * v * v);
1723 const U Fx_w_dist1_u = fx * invZ * dist1_u;
1724 const U Fy_w_dist2_u = fy * invZ * dist2_u_1_v;
1726 const U Fx_w_dist1_v = fx * invZ * dist2_u_1_v;
1727 const U Fy_w_dist2_v = fy * invZ * dist2_v;
1729 const U Fx_w2__ = -fx * invZ * invZ * (x * dist1_u + y * dist2_u_1_v);
1730 const U Fy_w2__ = -fy * invZ * invZ * (x * dist2_u_1_v + y * dist2_v);
1732 jx[0] = Fx_w_dist1_u;
1733 jx[1] = Fx_w_dist1_v;
1736 jy[0] = Fy_w_dist2_u;
1737 jy[1] = Fy_w_dist2_v;
1743 const U invZ = U(1) / U(flippedCameraObjectPoint.
z());
1748 const U fx_x_z2 = -fx_z * U(flippedCameraObjectPoint.
x()) * invZ;
1749 const U fy_y_z2 = -fy_z * U(flippedCameraObjectPoint.
y()) * invZ;
1761template <
typename T>
1767template <
typename T>
1768template <
bool tUseBorderDistortionIfOuts
ide>
1771 if (undistortImagePoint)
1779template <
typename T>
1782 if (undistortImagePoint)
1790template <
typename T>
1791template <
bool tUseBorderDistortionIfOuts
ide>
1796 if (distortImagePoints)
1798 if constexpr (tUseBorderDistortionIfOutside)
1806 const T
sqr = clampedNormalizedImagePoint.
sqr();
1816 const T
sqr = clampedNormalizedImagePoint.
sqr();
1819 const T tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * clampedNormalizedImagePoint.
x() * clampedNormalizedImagePoint.
y()
1834 const T
sqr = normalizedImagePoint.
sqr();
1844 const T
sqr = normalizedImagePoint.
sqr();
1847 const T tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * normalizedImagePoint.
x() * normalizedImagePoint.
y()
1864template <
typename T>
1865template <
bool tUseBorderDistortionIfOuts
ide>
1868 ocean_assert(numberNormalizedImagePoints == 0u || (normalizedImagePoints && imagePoints));
1880 T
sqr, radialDistortionFactor;
1882 for (
unsigned int n = 0u; n < numberNormalizedImagePoints; ++n)
1884 const VectorT2<T>& normalizedImagePoint(normalizedImagePoints[n]);
1886 if constexpr (tUseBorderDistortionIfOutside)
1888 const VectorT2<T> clampedNormalizedImagePoint(
minmax(leftClamping, normalizedImagePoint.
x(), rightClamping),
minmax(topClamping, normalizedImagePoint.
y(), bottomClamping));
1890 sqr = clampedNormalizedImagePoint.
sqr();
1898 sqr = normalizedImagePoint.
sqr();
1909 T
sqr, radialDistortionFactor, tangentialDistortionCorrectionX, tangentialDistortionCorrectionY;
1911 for (
unsigned int n = 0u; n < numberNormalizedImagePoints; ++n)
1913 const VectorT2<T>& normalizedImagePoint(normalizedImagePoints[n]);
1915 if constexpr (tUseBorderDistortionIfOutside)
1917 const VectorT2<T> clampedNormalizedImagePoint(
minmax(leftClamping, normalizedImagePoint.
x(), rightClamping),
minmax(topClamping, normalizedImagePoint.
y(), bottomClamping));
1919 sqr = clampedNormalizedImagePoint.
sqr();
1922 tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * clampedNormalizedImagePoint.
x() * clampedNormalizedImagePoint.
y()
1928 imagePoints[n].
x() = (normalizedImagePoint.
x() * radialDistortionFactor + tangentialDistortionCorrectionX) *
focalLengthX() +
principalPointX();
1929 imagePoints[n].
y() = (normalizedImagePoint.
y() * radialDistortionFactor + tangentialDistortionCorrectionY) *
focalLengthY() +
principalPointY();
1933 sqr = normalizedImagePoint.
sqr();
1936 tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * normalizedImagePoint.
x() * normalizedImagePoint.
y()
1942 imagePoints[n].
x() = (normalizedImagePoint.
x() * radialDistortionFactor + tangentialDistortionCorrectionX) *
focalLengthX() +
principalPointX();
1943 imagePoints[n].
y() = (normalizedImagePoint.
y() * radialDistortionFactor + tangentialDistortionCorrectionY) *
focalLengthY() +
principalPointY();
1950 for (
unsigned int n = 0u; n < numberNormalizedImagePoints; ++n)
1952 const VectorT2<T>& normalizedImagePoint(normalizedImagePoints[n]);
1960template <
typename T>
1961template <
bool tUseBorderDistortionIfOuts
ide>
1968template <
typename T>
1969template <
bool tUseBorderDistortionIfOuts
ide>
1976template <
typename T>
1977template <
bool tUseBorderDistortionIfOuts
ide>
1984template <
typename T>
1985template <
bool tUseBorderDistortionIfOuts
ide>
1989 ocean_assert(numberObjectPoints == 0u || (worldObjectPoints !=
nullptr && imagePoints !=
nullptr));
1994template <
typename T>
1995template <
bool tUseBorderDistortionIfOuts
ide>
1999 ocean_assert(worldLine.
isValid());
2004template <
typename T>
2005template <
bool tUseBorderDistortionIfOuts
ide>
2010 const VectorT3<T> transformedObjectPoint(flippedCamera_T_world * worldObjectPoint);
2013 const T factor = T(1) / transformedObjectPoint.
z();
2015 const VectorT2<T> normalizedImagePoint(transformedObjectPoint.
x() * factor, transformedObjectPoint.
y() * factor);
2017 if (!distortImagePoint)
2022 if constexpr (tUseBorderDistortionIfOutside)
2024 const T invZoom = T(1) / zoom;
2029 const T
sqr = clampedNormalizedImagePoint.
sqr();
2033 const T tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * clampedNormalizedImagePoint.
x() * clampedNormalizedImagePoint.
y()
2044 const T
sqr = normalizedImagePoint.
sqr();
2048 const T tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * normalizedImagePoint.
x() * normalizedImagePoint.
y()
2059template <
typename T>
2060template <
bool tUseBorderDistortionIfOuts
ide>
2064 ocean_assert(worldObjectBox.
isValid());
2067 const unsigned int numberBoxImagePoints = worldObjectBox.
corners(boxObjectCorners);
2070 for (
unsigned int n = 0; n < numberBoxImagePoints; ++n)
2078template <
typename T>
2079template <
bool tUseBorderDistortionIfOuts
ide>
2083 ocean_assert(worldObjectTriangle.
isValid());
2090template <
typename T>
2091template <
bool tUseBorderDistortionIfOuts
ide>
2096 if (distortImagePoint)
2098 if constexpr (tUseBorderDistortionIfOutside)
2100 const T invZoom = T(1) / zoom;
2105 const T
sqr = clampedNormalizedImagePoint.
sqr();
2109 const T tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * clampedNormalizedImagePoint.
x() * clampedNormalizedImagePoint.
y()
2120 const T
sqr = normalizedObjectPoint.
sqr();
2124 const T tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * normalizedObjectPoint.
x() * normalizedObjectPoint.
y()
2140template <
typename T>
2141template <
bool tUseBorderDistortionIfOuts
ide>
2145 ocean_assert((worldObjectPoints !=
nullptr && imagePoints !=
nullptr) || numberObjectPoints == 0u);
2149 const T invZoom = T(1) / zoom;
2159 for (
size_t n = 0; n < numberObjectPoints; ++n)
2161 const VectorT3<T> objectPoint(flippedCamera_T_world * worldObjectPoints[n]);
2164 const T factor = 1 / objectPoint.
z();
2166 const VectorT2<T> normalizedImagePoint(objectPoint.
x() * factor, objectPoint.
y() * factor);
2168 if constexpr (tUseBorderDistortionIfOutside)
2170 const VectorT2<T> clampedNormalizedImagePoint(
minmax(leftClamping, normalizedImagePoint.
x(), rightClamping),
minmax(topClamping, normalizedImagePoint.
y(), bottomClamping));
2172 const T
sqr = clampedNormalizedImagePoint.
sqr();
2180 const T
sqr = normalizedImagePoint.
sqr();
2194 for (
size_t n = 0; n < numberObjectPoints; ++n)
2196 const VectorT3<T> objectPoint(flippedCamera_T_world * worldObjectPoints[n]);
2199 const T factor = 1 / objectPoint.
z();
2201 const VectorT2<T> normalizedImagePoint(objectPoint.
x() * factor, objectPoint.
y() * factor);
2203 if constexpr (tUseBorderDistortionIfOutside)
2205 const VectorT2<T> clampedNormalizedImagePoint(
minmax(leftClamping, normalizedImagePoint.
x(), rightClamping),
minmax(topClamping, normalizedImagePoint.
y(), bottomClamping));
2207 const T
sqr = clampedNormalizedImagePoint.
sqr();
2210 const T tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * clampedNormalizedImagePoint.
x() * clampedNormalizedImagePoint.
y()
2221 const T
sqr = normalizedImagePoint.
sqr();
2224 const T tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * normalizedImagePoint.
x() * normalizedImagePoint.
y()
2242 ocean_assert(transformationIF.
isValid());
2244 for (
size_t n = 0; n < numberObjectPoints; ++n)
2246 const VectorT3<T> transformedObjectPoint(transformationIF * worldObjectPoints[n]);
2249 const T factor = 1 / transformedObjectPoint.
z();
2251 *imagePoints++ =
VectorT2<T>(transformedObjectPoint.
x() * factor, transformedObjectPoint.
y() * factor);
2256template <
typename T>
2257template <
bool tUseBorderDistortionIfOuts
ide>
2261 ocean_assert(worldLine.
isValid());
2266 if (firstImagePoint == secondImagePoint)
2271 return LineT2<T>(firstImagePoint, (secondImagePoint - firstImagePoint).normalized());
2274template <
typename T>
2281template <
typename T>
2288template <
typename T>
2295template <
typename T>
2299 ocean_assert(numberObjectPoints == 0u || (objectPoints && imagePoints));
2304template <
typename T>
2305template <
bool tDistortImagePo
int,
bool tUseBorderDistortionIfOuts
ide>
2310 const VectorT3<T> transformedObjectPoint(flippedCamera_T_world * objectPoint);
2313 const T factor = T(1) / transformedObjectPoint.
z();
2316 const VectorT2<T> normalizedImagePoint(transformedObjectPoint.
x() * factor, transformedObjectPoint.
y() * factor);
2318 if (!tDistortImagePoint)
2323 if constexpr (tUseBorderDistortionIfOutside)
2325 const T invZoom = T(1) / zoom;
2330 const T
sqr = clampedNormalizedImagePoint.
sqr();
2334 const T tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * clampedNormalizedImagePoint.
x() * clampedNormalizedImagePoint.
y()
2345 const T
sqr = normalizedImagePoint.
sqr();
2349 const T tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * normalizedImagePoint.
x() * normalizedImagePoint.
y()
2360template <
typename T>
2409template <
typename T>
2442 const T invZoom = T(1) / zoom;
2462template <
typename T>
2491template <
typename T>
2511 const T invZoom = T(1) / zoom;
2524template <
typename T>
2543template <
typename T>
2548 const T invZoom = T(1) / zoom;
2567template <
typename T>
2577template <
typename T>
2582 return LineT3<T>(world_t_camera, world_Q_camera *
vector(position, zoom));
2585template <
typename T>
2615template <
typename T>
2618 return !(*
this == camera);
2621template <
typename T>
2627template <
typename T>
2628template <
bool tUseBorderDistortionIfOuts
ide>
2635 if constexpr (tUseBorderDistortionIfOutside)
2640 const T
sqr = clampedNormalizedImagePoint.
sqr();
2644 const T tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * clampedNormalizedImagePoint.
x() * clampedNormalizedImagePoint.
y()
2650 return VectorT2<T>(undistortedNormalized.
x() * radialDistortionFactor + tangentialDistortionCorrectionX,
2651 undistortedNormalized.
y() * radialDistortionFactor + tangentialDistortionCorrectionY);
2655 const T
sqr = undistortedNormalized.
sqr();
2659 const T tangentialDistortionCorrectionX =
tangentialDistortion_.first * 2 * undistortedNormalized.
x() * undistortedNormalized.
y()
2665 return VectorT2<T>(undistortedNormalized.
x() * radialDistortionFactor + tangentialDistortionCorrectionX,
2666 undistortedNormalized.
y() * radialDistortionFactor + tangentialDistortionCorrectionY);
2671 return undistortedNormalized;
This class implements an axis aligned 2D box object.
Definition Box2.h:68
This class implements an axis aligned 3D bounding box.
Definition Box3.h:67
bool isValid() const
Returns whether the bounding box is valid.
unsigned int corners(VectorT3< T > *corners) const
Returns the corner positions of this box.
This class implements the base class for all cameras.
Definition Camera.h:99
static HomogenousMatrixT4< U > standard2InvertedFlipped(const HomogenousMatrixT4< U > &world_T_camera)
Transforms a standard homogenous 4x4 viewing (extrinsic camera) matrix into an inverted and flipped c...
Definition Camera.h:779
This class implements a 4x4 homogeneous transformation matrix using floating point values with the pr...
Definition HomogenousMatrix4.h:110
SquareMatrixT3< T > rotationMatrix() const
Returns the rotation matrix of the transformation.
Definition HomogenousMatrix4.h:1487
VectorT3< T > translation() const
Returns the translation of the transformation.
Definition HomogenousMatrix4.h:1375
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1800
QuaternionT< T > rotation() const
Returns the rotation of the transformation as quaternion.
Definition HomogenousMatrix4.h:1382
This class implements an infinite line in 2D space.
Definition Line2.h:83
This class implements an infinite line in 3D space.
Definition Line3.h:69
bool isValid() const
Returns whether this line has valid parameters.
Definition Line3.h:312
const VectorT3< T > & point() const
Returns a point on the line.
Definition Line3.h:280
This class implements a 2D lookup object with values at the bins' center positions defining the indiv...
Definition Lookup2.h:198
static T abs(const T value)
Returns the absolute value of a given value.
Definition Numeric.h:1220
static bool isWeakEqual(const T first, const T second)
Returns whether two values a equal up to a weak epsilon.
Definition Numeric.h:2581
static constexpr T eps()
Returns a small epsilon.
static bool isEqual(const T first, const T second)
Returns whether two values are equal up to a small epsilon.
Definition Numeric.h:2395
static constexpr T sqr(const T value)
Returns the square of a given value.
Definition Numeric.h:1499
static constexpr T rad2deg(const T rad)
Converts rad to deg.
Definition Numeric.h:3247
static constexpr bool isNotEqualEps(const T value)
Returns whether a value is not smaller than or equal to a small epsilon.
Definition Numeric.h:2246
DistortionLookup(const PinholeCameraT< T > &camera, const unsigned int binSize)
Creates an lookup object for a given camera.
VectorT2< Scalar > undistortionOffset(const VectorT2< Scalar > &distortedImagePoint) const
Definition PinholeCamera.h:1306
VectorT2< Scalar > undistortedImagePointBicubic(const VectorT2< Scalar > &distortedImagePoint) const
Definition PinholeCamera.h:1313
VectorT2< Scalar > undistortionOffsetBicubic(const VectorT2< Scalar > &distortedImagePoint) const
Definition PinholeCamera.h:1320
VectorT2< Scalar > undistortedImagePoint(const VectorT2< Scalar > &distortedImagePoint) const
Definition PinholeCamera.h:1299
LookupCenter2< VectorT2< T >, T > LookupTable
Definition of a lookup table for 2D vectors.
Definition PinholeCamera.h:209
DistortionLookup()
Creates an invalid lookup object.
Definition PinholeCamera.h:1293
LookupTable distortionLookupTable
The distortion lookup table.
Definition PinholeCamera.h:256
Definition of a pinhole camera model.
Definition PinholeCamera.h:114
std::pair< Scalar, Scalar > DistortionPair
Definition PinholeCamera.h:123
VectorT2< T > projectToImageIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const VectorT3< T > &worldObjectPoint, 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:2306
void setTangentialDistortion(const DistortionPair &tangential)
Sets the tangential distortion parameters.
Definition PinholeCamera.h:1518
VectorT2< T > imagePoint2normalizedImagePoint(const VectorT2< T > &imagePoint, const bool undistortImagePoint) const
Calculates the normalized image point corresponding to a given (distorted) image point.
Definition PinholeCamera.h:1769
unsigned int width() const
VectorT2< T > projectToImageDampedIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const VectorT3< T > &objectPoint, const bool distortImagePoint, const T dampingFactor=T(1), const T zoom=T(1)) const
Projects a 3D object point to the 2D image plane of the camera by a given inverse extrinsic camera ma...
PinholeCameraT(const unsigned int width, const unsigned int height, const T focalX, const T focalY, const T principalX, const T principalY, const DistortionPair &radial, const DistortionPair &tangential)
Creates a new PinholeCameraT<T> object by it's given intrinsic parameters.
T fovYBottom() const
Returns the bottom field of view in y direction.
bool isEqual(const PinholeCameraT< T > &camera, const T eps=NumericT< T >::eps()) const
Returns whether two camera profiles are identical up to a given epsilon.
bool isInside(const VectorT2< T > &imagePoint, const T signedBorder=T(0)) const
Returns whether a given 2D image point lies inside the camera frame.
Definition PinholeCamera.h:1659
T fovYTop() const
Returns the top field of view in y direction.
VectorT2< T > dampedNormalized(const VectorT2< T > &normalized, const T dampingFactor, const T invZoom) const
Determines the damped normalized coordinate for a given normalized coordinate.
PinholeCameraT(const unsigned int width, const unsigned int height, const T *parameters, const bool radialDistortion=true, const bool tangentialDistortion=true)
Creates a new PinholeCameraT<T> object by it's given intrinsic parameters.
T principalPointX() const
Returns the x-value of the principal point of the camera image in the pixel domain.
Definition PinholeCamera.h:1470
DistortionPair tangentialDistortion_
Definition PinholeCamera.h:1289
TriangleT2< T > projectToImageDampedIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const TriangleT3< T > &objectTriangle, const bool distortImagePoint, const T dampingFactor=T(1), const T zoom=T(1)) const
Projects a 3D triangle to the 2D image plane of the camera by a given inverse extrinsic camera matrix...
BoxT2< T > projectToImageDampedIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const BoxT3< T > &objectBox, const bool distortImagePoint, const T dampingFactor=T(1), const T zoom=T(1)) const
Projects a 3D box to the 2D image plane of the camera by a given inverse extrinsic camera matrix.
PinholeCameraT()=default
Standard constructor.
const SquareMatrixT3< T > & invertedIntrinsic() const
Returns the inverted intrinsic camera matrix.
Definition PinholeCamera.h:1333
bool operator==(const PinholeCameraT< T > &camera) const
Returns whether two camera objects are identical up to a small epsilon.
VectorT2< T > principalPoint() const
Returns the coordinate of the principal point of the camera image in the pixel domain.
Definition PinholeCamera.h:1464
void copyParameters(unsigned int &width, unsigned int &height, std::vector< TParameter > ¶meters, ParameterConfiguration ¶meterConfiguration) const
Copies the parameters of this camera.
Definition PinholeCamera.h:1622
BoxT2< T > projectToImage(const HomogenousMatrixT4< T > &world_T_camera, const BoxT3< T > &worldObjectBox, const bool distortImagePoint, const T zoom=T(1)) const
Projects a 3D box to the 2D image plane of the camera by a given camera pose.
Definition PinholeCamera.h:1970
HomogenousMatrixT4< T > transformationMatrixIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const T zoom=T(1)) const
Returns a 4x4 homogeneous transformation matrix (corresponding to a 3x4 matrix) that covers an extrin...
Definition PinholeCamera.h:1669
PinholeCameraT(const unsigned int width, const unsigned int height, const ParameterConfiguration parameterConfiguration, const TParameter *parameters)
Creates a new camera object with parameters with specific configuration.
Definition PinholeCamera.h:1364
TriangleT2< T > projectToImageIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const TriangleT3< T > &worldObjectTriangle, const bool distortImagePoint, const T zoom=T(1)) const
Projects a 3D triangle to the 2D image plane of the camera by a given extrinsic camera pose.
Definition PinholeCamera.h:2080
TriangleT2< T > projectToImageDamped(const HomogenousMatrixT4< T > &world_T_camera, const TriangleT3< T > &objectTriangle, const bool distortImagePoint, const T dampingFactor=T(1), const T zoom=T(1)) const
Projects a 3D triangle to the 2D image plane of the camera by a given extrinsic camera matrix.
Definition PinholeCamera.h:2289
VectorT2< T > projectToImageIF(const VectorT2< T > &normalizedObjectPoint, const bool distortImagePoint, const T zoom=T(1)) const
Transforms a normalized object point (a 3D object point transformed by the inverted and flipped extri...
Definition PinholeCamera.h:2092
bool isDistortionPlausible(const T symmetricFocalLengthRatio=T(1.05), const T modelAccuracy=T(0.001), const T symmetricDistortionRatio=T(1.08)) const
Checks whether the distortion of this camera is plausible.
VectorT2< T > dampedNormalized(const VectorT2< T > &normalized, const T dampingFactor, const T leftNormalizedBorder, const T rightNormalizedBorder, const T topNormalizedBorder, const T bottomNormalizedBorder) const
Determines the damped normalized coordinate for a given normalized coordinate.
LineT3< T > ray(const VectorT2< T > &position, const HomogenousMatrixT4< T > &world_T_camera, const T zoom=T(1)) const
Returns a ray starting at the camera's center and intersection a given 2D point on the image plane.
Definition PinholeCamera.h:2568
T fovXRight() const
Returns the right field of view in x direction.
VectorT2< T > distortDamped(const VectorT2< T > &undistorted, const T dampingFactor=T(1), const T zoom=T(1)) const
Returns the distorted position of a given undistorted position defined in pixel coordinates.
VectorT2< T > distort(const VectorT2< T > &undistorted) const
Returns the distorted position of a given undistorted position defined in pixel coordinates.
Definition PinholeCamera.h:1570
LineT3< T > ray(const VectorT2< T > &position, const VectorT3< T > &world_t_camera, const QuaternionT< T > &world_Q_camera, const T zoom=T(1)) const
Returns a ray starting at the camera's center and intersection a given 2D point on the image plane.
Definition PinholeCamera.h:2578
PinholeCameraT(const unsigned int width, const unsigned int height, const T fovX, const T principalX, const T principalY)
Creates a new PinholeCameraT<T> object by the given frame dimensions, the ideal field of view,...
PinholeCameraT(const SquareMatrixT3< T > &intrinsic)
Creates a new PinholeCameraT<T> object by a given projection matrix with the intrinsic camera paramet...
VectorT2< T > distortNormalized(const VectorT2< T > &undistortedNormalized, const T invZoom) const
Returns the distorted position of a given undistorted normalized position.
Definition PinholeCamera.h:2629
VectorT2< T > undistort(const VectorT2< T > &distorted, const unsigned int iterations=10u, const T zoom=T(1)) const
Returns the undistorted position of a given distorted position defined in pixel coordinates.
Definition PinholeCamera.h:1525
bool isValid() const
Returns whether this camera is valid.
Definition PinholeCamera.h:1762
VectorT3< T > vectorToPlane(const VectorT2< T > &position, const T distance, const T zoom) const
Returns a vector starting at the camera's center and intersecting a given 2D point on the image plane...
Definition PinholeCamera.h:2492
void setRadialDistortion(const DistortionPair &radial)
Sets the radial distortion parameters.
Definition PinholeCamera.h:1512
BoxT2< T > projectToImageIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const BoxT3< T > &worldObjectBox, const bool distortImagePoint, const T zoom=T(1)) const
Projects a 3D box to the 2D image plane of the camera by a given inverse camera pose.
Definition PinholeCamera.h:2061
unsigned int height_
Definition PinholeCamera.h:1277
T focalLengthY() const
Returns the vertical focal length parameter.
Definition PinholeCamera.h:1488
SquareMatrixT3< Scalar > invertedIntrinsics_
Definition PinholeCamera.h:1283
PinholeCameraT(const PinholeCameraT< U > &pinholeCamera, const bool copyDistortionParameters=true)
Copy constructor for a pinhole camera with difference element data type than T.
Definition PinholeCamera.h:1352
bool hasDistortionParameters() const
Returns whether this camera object has specified distortion parameters.
Definition PinholeCamera.h:1445
const SquareMatrixT3< Scalar > & intrinsic() const
T calculateCosBetween(const VectorT2< T > &first, const VectorT2< T > &second) const
Returns the cosine of the viewing angle between two undistorted points on the camera's image plane.
PinholeCameraT(const unsigned int width, const unsigned int height, const T focalX, const T focalY, const T principalX, const T principalY)
Creates a new PinholeCameraT<T> object by it's given intrinsic parameters.
void calculateInverseIntrinsic()
Determines the inverse of the intrinsic camera matrix.
Definition PinholeCamera.h:2586
VectorT3< T > vectorToPlane(const VectorT2< T > &position, const T distance) const
Returns a vector starting at the camera's center and intersecting a given 2D point on the image plane...
Definition PinholeCamera.h:2463
VectorT2< T > projectToImageDamped(const HomogenousMatrixT4< T > &world_T_camera, const VectorT3< T > &objectPoint, const bool distortImagePoint, const T dampingFactor=T(1), const T zoom=T(1)) const
Projects a 3D object point to the 2D image plane of the camera by a given extrinsic camera matrix.
Definition PinholeCamera.h:2275
bool rotation(const VectorT2< T > &undistortedPosition, T &angleX, T &angleY) const
Gets two rotation parameters of the viewing ray for a given undistorted 2D position in the camera ima...
T fovY() const
Returns the field of view in x direction of the camera.
SquareMatrixT3< Scalar > intrinsics_
Definition PinholeCamera.h:1280
T fovDiagonal() const
Returns the diagonal field of view of the camera.
SquareMatrixT4< T > frustumMatrix(const T nearDistance, const T farDistance) const
Returns the 4x4 frustum projection matrix corresponding to this camera.
void projectToImageDamped(const HomogenousMatrixT4< T > &world_T_camera, const VectorT3< T > *objectPoints, const size_t numberObjectPoints, const bool distortImagePoints, VectorT2< T > *imagePoints, const T dampingFactor=T(1), const T zoom=T(1)) const
Projects a set of 3D object points onto an image plane of the camera by a given extrinsic camera matr...
Definition PinholeCamera.h:2296
void normalizedImagePoints2imagePoints(const VectorT2< T > *normalizedImagePoints, const size_t numberNormalizedImagePoints, const bool distortImagePoints, VectorT2< T > *imagePoints) const
Calculates the image points corresponding to a set of given normalized image points.
Definition PinholeCamera.h:1866
Scalar TScalar
Definition PinholeCamera.h:120
VectorT3< T > vectorIF(const VectorT2< T > &position, const bool makeUnitVector=true) const
Returns a vector starting at the camera's center and intersecting a given 2D point on the image plane...
Definition PinholeCamera.h:2525
OptimizationStrategy
Definition of individual optimization strategies for camera parameters.
Definition PinholeCamera.h:178
@ OS_FOCAL_LENGTHS
Definition PinholeCamera.h:184
@ OS_NONE
Definition PinholeCamera.h:180
@ OS_SYMMETRIC_INTRINSIC_PARAMETERS_DISTORTIONS
Definition PinholeCamera.h:190
@ OS_FOCAL_LENGTH
Definition PinholeCamera.h:182
@ OS_INTRINSIC_PARAMETERS
Definition PinholeCamera.h:186
@ OS_INTRINSIC_PARAMETERS_RADIAL_DISTORTION
Definition PinholeCamera.h:196
@ OS_FOCAL_LENGTHS_DISTORTION
Definition PinholeCamera.h:188
@ OS_INTRINSIC_PARAMETERS_DISTORTIONS
Definition PinholeCamera.h:192
@ OS_DISTORTION
Definition PinholeCamera.h:194
unsigned int height() const
const DistortionPair & radialDistortion() const
DistortionPair radialDistortion_
Definition PinholeCamera.h:1286
TriangleT2< T > projectToImage(const HomogenousMatrixT4< T > &world_T_camera, const TriangleT3< T > &worldObjectTriangle, const bool distortImagePoint, const T zoom=T(1)) const
Projects a 3D triangle to the 2D image plane of the camera by a given camera pose.
Definition PinholeCamera.h:1978
VectorT3< T > vectorIF(const VectorT2< T > &position, const T zoom, const bool makeUnitVector) const
Returns a vector starting at the camera's center and intersecting a given 2D point on the image plane...
Definition PinholeCamera.h:2544
void applyZoomFactor(const T relativeZoom)
Applies a given (relative) zoom factor which mainly multiplies the focal length parameters by the giv...
T inverseFocalLengthX() const
Returns the inverse horizontal focal length parameter.
Definition PinholeCamera.h:1494
PinholeCameraT(const SquareMatrixT3< T > &intrinsic, const unsigned int width, const unsigned int height)
Creates a new PinholeCameraT<T> object by the given intrinsic camera matrix and width and height of t...
PinholeCameraT(const unsigned int width, const unsigned int height, const T fovX)
Creates a new PinholeCameraT<T> object by the given width, height and field of view of a camera.
const DistortionPair & tangentialDistortion() const
VectorT2< T > normalizedImagePoint2imagePoint(const VectorT2< T > &normalizedImagePoint, const bool distortImagePoint) const
Calculates the image point corresponding to a given normalized image point.
Definition PinholeCamera.h:1792
VectorT2< T > distortNormalizedDamped(const VectorT2< T > &undistortedNormalized, const T dampingFactor, const T invZoom) const
Returns the distorted position of a given undistorted normalized position.
void copyElements(T *arrayValues, const bool copyRadialDistortion=true, const bool copyTangentialDistortion=true) const
Copies the elements of this camera to an array with 4 to 8 floating point values.
void projectToImageDampedIF(const HomogenousMatrixT4< T > &invertedFlippedExtrinsic, const VectorT3< T > *objectPoints, const size_t numberObjectPoints, const bool distortImagePoints, VectorT2< T > *imagePoints, const T dampingFactor=T(1), const T zoom=T(1)) const
Projects a set of 3D object points onto an image plane of the camera by a given inverse extrinsic cam...
ParameterConfiguration
Definition of individual parameter configurations.
Definition PinholeCamera.h:129
@ PC_8_PARAMETERS
Definition PinholeCamera.h:171
@ PC_UNKNOWN
Definition PinholeCamera.h:133
@ PC_7_PARAMETERS_ONE_FOCAL_LENGTH
Definition PinholeCamera.h:160
@ PC_3_PARAMETERS_ONE_FOCAL_LENGTH
Definition PinholeCamera.h:141
@ PC_4_PARAMETERS
Definition PinholeCamera.h:150
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
T principalPointY() const
Returns the y-value of the principal point of the camera image in the pixel domain.
Definition PinholeCamera.h:1476
LineT2< T > projectToImage(const HomogenousMatrixT4< T > &world_T_camera, const LineT3< T > &worldLine, const bool distortProjectedLine, const T zoom=T(1)) const
Projects a 3D line onto an image plane of the camera by a given camera pose.
Definition PinholeCamera.h:1996
T calculateAngleBetween(const VectorT2< T > &first, const VectorT2< T > &second) const
Returns the viewing angle between two undistorted points on the camera's image plane.
VectorT2< T > undistortDamped(const VectorT2< T > &distorted, const T dampingFactor=T(1), const unsigned int iterations=10u, const T zoom=T(1)) const
Returns the undistorted position of a given distorted position defined in pixel coordinates.
PinholeCameraT(const unsigned int width, const unsigned int height, const PinholeCameraT< T > &camera)
Creates a new camera object with specified frame dimension and intrinsic camera parameters best match...
bool operator!=(const PinholeCameraT< T > &camera) const
Returns whether two camera objects are not identical up to a small epsilon.
Definition PinholeCamera.h:2616
PinholeCameraT(const SquareMatrixT3< T > &intrinsic, const unsigned int width, const unsigned int height, const DistortionPair &radial, const DistortionPair &tangential)
Creates a new PinholeCameraT<T> object by the given intrinsic camera matrix, the width and height and...
T fovXLeft() const
Returns the left field of view in x direction.
T inverseFocalLengthY() const
Returns the inverse vertical focal length parameter.
Definition PinholeCamera.h:1503
VectorT3< T > vector(const VectorT2< T > &position, const T zoom, const bool makeUnitVector=true) const
Returns a vector starting at the camera's center and intersecting a given 2D point on the image plane...
Definition PinholeCamera.h:2410
bool setIntrinsic(const SquareMatrixT3< T > &intrinsic)
Sets the intrinsic camera matrix.
BoxT2< T > projectToImageDamped(const HomogenousMatrixT4< T > &world_T_camera, const BoxT3< T > &objectBox, const bool distortImagePoint, const T dampingFactor=T(1), const T zoom=T(1)) const
Projects a 3D box to the 2D image plane of the camera by a given inverse extrinsic camera matrix.
Definition PinholeCamera.h:2282
VectorT2< T > imagePoint2normalizedImagePointDamped(const VectorT2< T > &imagePoint, const bool undistortImagePoint) const
Calculates the normalized image point corresponding to a given (distorted) image point.
Definition PinholeCamera.h:1780
PinholeCameraT(const T subFrameLeft, const T subFrameTop, const unsigned int subFrameWidth, const unsigned int subFrameHeight, const PinholeCameraT< T > &camera)
Creates a new sub-frame camera profile based on a camera profile of the entire camera frame.
LineT2< T > projectToImageIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const LineT3< T > &worldLine, const bool distortProjectedLine, const T zoom=T(1)) const
Projects a 3D line onto an image plane of the camera by a given inverse camera pose.
Definition PinholeCamera.h:2258
void pointJacobian2x3IF(const VectorT3< U > &flippedCameraObjectPoint, U *jx, U *jy) const
Calculates the 2x3 jacobian matrix for the 3D object point projection into the camera frame.
Definition PinholeCamera.h:1693
void projectToImageIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const VectorT3< T > *worldObjectPoints, const size_t numberObjectPoints, const bool distortImagePoints, VectorT2< T > *imagePoints, const T zoom=T(1)) const
Projects a set of 3D object points onto an image plane of the camera by a given inverse camera pose.
Definition PinholeCamera.h:2142
friend class PinholeCameraT
Definition PinholeCamera.h:115
unsigned int width_
Definition PinholeCamera.h:1274
void projectToImage(const HomogenousMatrixT4< T > &world_T_camera, const VectorT3< T > *worldObjectPoints, const size_t numberObjectPoints, const bool distortImagePoints, VectorT2< T > *imagePoints, const T zoom=T(1)) const
Projects a set of 3D object points onto an image plane of the camera by a given camera pose.
Definition PinholeCamera.h:1986
VectorT2< T > projectToImage(const HomogenousMatrixT4< T > &world_T_camera, const VectorT3< T > &worldObjectPoint, 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 camera pose.
Definition PinholeCamera.h:1962
T focalLengthX() const
Returns the horizontal focal length parameter.
Definition PinholeCamera.h:1482
VectorT3< T > vector(const VectorT2< T > &position, const bool makeUnitVector=true) const
Returns a vector starting at the camera's center and intersecting a given 2D point on the image plane...
Definition PinholeCamera.h:2361
This class implements a unit quaternion rotation.
Definition Quaternion.h:100
bool isValid() const
Returns whether this quaternion is a valid unit quaternion.
Definition Quaternion.h:882
This class implements a 3x3 square matrix.
Definition SquareMatrix3.h:89
This class implements a 4x4 square matrix.
Definition SquareMatrix4.h:85
This class implements a 2D triangle with Cartesian coordinates.
Definition Triangle2.h:81
This class implements a 3D triangle.
Definition Triangle3.h:80
const VectorT3< T > & point0() const
Returns the first point of this triangle.
Definition Triangle3.h:278
bool isValid() const
Returns whether this triangle is valid.
Definition Triangle3.h:579
const VectorT3< T > & point2() const
Returns the third point of this triangle.
Definition Triangle3.h:290
const VectorT3< T > & point1() const
Returns the second point of this triangle.
Definition Triangle3.h:284
This class implements a vector with two elements.
Definition Vector2.h:96
const T & x() const noexcept
Returns the x value.
Definition Vector2.h:703
const T & y() const noexcept
Returns the y value.
Definition Vector2.h:715
bool isEqual(const VectorT2< T > &vector, const T eps) const
Returns whether two vectors are equal up to a specified epsilon.
Definition Vector2.h:751
T sqr() const
Returns the square of the vector length.
Definition Vector2.h:626
This class implements a vector with three elements.
Definition Vector3.h:97
const T & y() const noexcept
Returns the y value.
Definition Vector3.h:816
const T & x() const noexcept
Returns the x value.
Definition Vector3.h:804
VectorT3< T > normalized() const
Returns the normalized vector.
Definition Vector3.h:609
const T & z() const noexcept
Returns the z value.
Definition Vector3.h:828
T length() const
Returns the length of the vector.
Definition Vector3.h:668
T minmax(const T &lowerBoundary, const T &value, const T &upperBoundary)
This function fits a given parameter into a specified value range.
Definition base/Utilities.h:973
unsigned int sqr(const char value)
Returns the square value of a given value.
Definition base/Utilities.h:1099
PinholeCamerasT< Scalar > PinholeCameras
Definition of a vector holding pinhole camera objects.
Definition PinholeCamera.h:68
PinholeCameraT< Scalar > PinholeCamera
Definition of an pinhole camera object with Scalar precision.
Definition PinholeCamera.h:39
PinholeCamerasT< double > PinholeCamerasD
Definition of a vector holding PinholeCameraD objects.
Definition PinholeCamera.h:75
PinholeCameraT< double > PinholeCameraD
Definition of an pinhole camera object with double precision.
Definition PinholeCamera.h:46
PinholeCamerasT< float > PinholeCamerasF
Definition of a vector holding PinholeCameraF objects.
Definition PinholeCamera.h:82
std::vector< PinholeCameraT< T > > PinholeCamerasT
Definition of a typename alias for vectors with PinholeCameraT objects.
Definition PinholeCamera.h:61
PinholeCameraT< float > PinholeCameraF
Definition of an pinhole camera object with float precision.
Definition PinholeCamera.h:53
The namespace covering the entire Ocean framework.
Definition Accessor.h:15