Ocean
Rectifier.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_CV_DEPTH_RECTIFIER_H
9 #define META_OCEAN_CV_DEPTH_RECTIFIER_H
10 
11 #include "ocean/cv/depth/Depth.h"
12 
13 #include "ocean/base/Frame.h"
14 #include "ocean/base/Worker.h"
15 
16 #include "ocean/math/AnyCamera.h"
18 #include "ocean/math/Quaternion.h"
19 
20 namespace Ocean
21 {
22 
23 namespace CV
24 {
25 
26 namespace Depth
27 {
28 
29 /**
30  * This class implements frame rectification functions.
31  * @ingroup cvdepth
32  */
33 class OCEAN_CV_DEPTH_EXPORT Rectifier
34 {
35  public:
36 
37  /**
38  * Rectifies two images with given camera profile and camera pose.
39  * @param cameraA The camera profile of the first camera, must be valid
40  * @param cameraB The camera profile of the second camera, must be valid
41  * @param world_T_cameraA The transformation between the first camera and world, with default camera pointing towards the negative z-space with y-axis up
42  * @param world_T_cameraB The transformation between the first camera and world, with default camera pointing towards the negative z-space with y-axis up
43  * @param frameA The first camera image, must be valid
44  * @param frameB The second camera image, must be valid
45  * @param pinholeCamera The camera profile of the pinhole camera to be used when rectifying the images, must be valid
46  * @param rectifiedFrameA The resulting rectified image of the first camera, must be valid
47  * @param rectifiedFrameB The resulting rectified image of the second camera, must be valid
48  * @param world_T_rectifiedA The resulting transformation between the first rectified camera and world, with default camera pointing towards the negative z-space with y-axis up
49  * @param world_T_rectifiedB The resulting transformation between the second rectified camera and world, with default camera pointing towards the negative z-space with y-axis up
50  * @param useTangentMapping Whether to use tangent mapping to better preserve the original resolution
51  * @param worker Optional worker object to distribute the computation, nullptr to execute the code on one core only
52  * @return True, if succeeded
53  */
54  static bool rectify(const AnyCamera& cameraA, const AnyCamera& cameraB, const HomogenousMatrix4& world_T_cameraA, const HomogenousMatrix4& world_T_cameraB, const Frame& frameA, const Frame& frameB, const PinholeCamera& pinholeCamera, Frame& rectifiedFrameA, Frame& rectifiedFrameB, HomogenousMatrix4& world_T_rectifiedA, HomogenousMatrix4& world_T_rectifiedB, const bool useTangentMapping, Worker* worker = nullptr);
55 
56  /**
57  * Returns the rotation between the rectified pinhole camera(s) and world for two camera poses.
58  * @param world_T_cameraA The transformation between the first camera and world, with default camera pointing towards the negative z-space with y-axis up
59  * @param world_T_cameraB The transformation between the second camera and world, with default camera pointing towards the negative z-space with y-axis up
60  * @param world_R_rectified The resulting transformation between rectified pinhole camera(s) and world, with default camera pointing towards the negative z-space with y-axis up
61  * @return True, if succeeded
62  */
63  static bool detemineRectificationRotation(const HomogenousMatrix4& world_T_cameraA, const HomogenousMatrix4& world_T_cameraB, Quaternion& world_R_rectified);
64 
65  /**
66  * Re-samples a camera image which has been captured with a camera profile as if the image would have been captured with a second camera profile.
67  * Optionally applies tangent mapping to the target image to better preserve the original resolution.
68  * The function can be used e.g., to rectify a fisheye camera image into a pinhole camera image.
69  * @param sourceFrame The source image captured with the source camera profile, must be valid
70  * @param sourceCamera The source camera profile which has been used to capture the source image, with resolution sourceFrame.width() x sourceFrame.height(), must be valid
71  * @param source_R_target The rotation transforming 3D points defined in the coordinate system of the target camera image to 3D points defined in the coordinate system of the source camera image, must be valid
72  * @param targetCamera The camera profile of the target frame, must be valid
73  * @param targetFrame The resulting target image, with resolution targetCamera.width() x targetCamera.height(), must be valid
74  * @param source_OLT_target Optional resulting offset lookup table between target image points and source image points
75  * @param worker Optional worker object to distribute the computational load
76  * @param binSizeInPixel The size in pixel of the interpolation bins used for building the lookup table, with range [1, infinity)
77  * @param borderColor The color of border pixels for which now visual content exists, provide one value for each channel, nullptr to use ElementType(0) for each channel
78  * @return True, if succeeded
79  * @see FrameInterpolatorBilinear::Comfort::resampleCameraImage().
80  */
81  static bool resampleCameraImageWithOptionalTangentMapping(const Frame& sourceFrame, const AnyCamera& sourceCamera, const SquareMatrix3& source_R_target, const AnyCamera& targetCamera, Frame& targetFrame, LookupCorner2<Vector2>* source_OLT_target = nullptr, Worker* worker = nullptr, const unsigned int binSizeInPixel = 8u, const void* borderColor = nullptr, const bool useTangentMapping = false);
82 
83 };
84 
85 }
86 
87 }
88 
89 }
90 
91 #endif // META_OCEAN_CV_DEPTH_RECTIFIER_H
This class implements the abstract base class for all AnyCamera objects.
Definition: AnyCamera.h:130
This class implements frame rectification functions.
Definition: Rectifier.h:34
static bool rectify(const AnyCamera &cameraA, const AnyCamera &cameraB, const HomogenousMatrix4 &world_T_cameraA, const HomogenousMatrix4 &world_T_cameraB, const Frame &frameA, const Frame &frameB, const PinholeCamera &pinholeCamera, Frame &rectifiedFrameA, Frame &rectifiedFrameB, HomogenousMatrix4 &world_T_rectifiedA, HomogenousMatrix4 &world_T_rectifiedB, const bool useTangentMapping, Worker *worker=nullptr)
Rectifies two images with given camera profile and camera pose.
static bool resampleCameraImageWithOptionalTangentMapping(const Frame &sourceFrame, const AnyCamera &sourceCamera, const SquareMatrix3 &source_R_target, const AnyCamera &targetCamera, Frame &targetFrame, LookupCorner2< Vector2 > *source_OLT_target=nullptr, Worker *worker=nullptr, const unsigned int binSizeInPixel=8u, const void *borderColor=nullptr, const bool useTangentMapping=false)
Re-samples a camera image which has been captured with a camera profile as if the image would have be...
static bool detemineRectificationRotation(const HomogenousMatrix4 &world_T_cameraA, const HomogenousMatrix4 &world_T_cameraB, Quaternion &world_R_rectified)
Returns the rotation between the rectified pinhole camera(s) and world for two camera poses.
This class implements Ocean's image class.
Definition: Frame.h:1760
This class implements a 2D lookup object with values at the bins' corners defining the individual loo...
Definition: Lookup2.h:636
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15