Ocean
Loading...
Searching...
No Matches
FisheyeEpipolarGeometry.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_GEOMETRY_FISHEYEEPIPOLARGEOMETRY_H
9#define META_OCEAN_GEOMETRY_FISHEYEEPIPOLARGEOMETRY_H
10
12
15#include "ocean/math/Line2.h"
17
18namespace Ocean
19{
20
21namespace Geometry
22{
23
24/**
25 * This class implements fisheye epipolar geometry functionality.
26 * @ingroup geometry
27 */
28class OCEAN_GEOMETRY_EXPORT FisheyeEpipolarGeometry
29{
30 public:
31
32 /**
33 * Definition of camera identifiers.
34 */
35 enum CameraIdentifier : unsigned int
36 {
37 /// Camera 0
38 CI_CAMERA0 = 0u,
39 /// Camera 1
40 CI_CAMERA1
41 };
42
43 /**
44 * Definition of an epipolar line as a vector of 2D points.
45 */
46 using EpipolarLine = std::vector<Vector2>;
47
48 /**
49 * Definition of a vector holding epipolar lines.
50 */
51 using EpipolarLines = std::vector<EpipolarLine>;
52
53 public:
54
55 /**
56 * Default constructor creating an invalid epipolar geometry object.
57 */
59
60 /**
61 * Creates a new fisheye epipolar geometry object.
62 * @param camera0 The first camera, must be valid
63 * @param camera1 The second camera, must be valid
64 * @param camera0_T_camera1 The transformation from camera 1 to camera 0, must be valid
65 */
66 FisheyeEpipolarGeometry(const SharedAnyCamera& camera0, const SharedAnyCamera& camera1, const HomogenousMatrix4& camera0_T_camera1);
67
68 /**
69 * Returns whether this epipolar geometry object is valid.
70 * @return True, if so
71 */
72 bool isValid() const;
73
74 /**
75 * Updates the cameras and transformation of this epipolar geometry object.
76 * @param camera0 The first camera, must be valid
77 * @param camera1 The second camera, must be valid
78 * @param camera0_T_camera1 The transformation from camera 1 to camera 0, must be valid
79 * @return True, if succeeded
80 */
81 bool updateCameras(const SharedAnyCamera& camera0, const SharedAnyCamera& camera1, const HomogenousMatrix4& camera0_T_camera1);
82
83 /**
84 * Computes the epipolar line in the target camera corresponding to a point in the source camera.
85 * @param sourcePointFisheye The point in the source camera, with range [0, sourceCamera.width())x[0, sourceCamera.height())
86 * @param fisheyeEpipolarLineSegments The resulting epipolar line in the target camera as a sequence of connected points
87 * @param sourceCameraIdentifier The identifier of the source camera, either CI_CAMERA0 or CI_CAMERA1
88 * @param lineStep The step size along the epipolar line, in pixels, with range (0, infinity)
89 * @param maxNumberLineSegments The maximum number of line segments to compute, with range [1, infinity)
90 * @return True, if succeeded
91 */
92 bool epipolarLine(const Vector2& sourcePointFisheye, Vectors2& fisheyeEpipolarLineSegments, const CameraIdentifier sourceCameraIdentifier = CI_CAMERA0, const Scalar lineStep = Scalar(70), const size_t maxNumberLineSegments = 100u) const;
93
94 /**
95 * Determines whether a target point lies on the epipolar line corresponding to a source point.
96 * @param sourceCameraIdentifier The identifier of the source camera, either CI_CAMERA0 or CI_CAMERA1
97 * @param sourcePointFisheye The point in the source camera, with range [0, sourceCamera.width())x[0, sourceCamera.height())
98 * @param targetPointFisheye The point in the target camera to check, with range [0, targetCamera.width())x[0, targetCamera.height())
99 * @param maxDistance The maximum allowed distance from the epipolar line, in pixels, with range [0, infinity)
100 * @return True, if the target point lies on the epipolar line
101 */
102 bool isOnEpipolarLine(const CameraIdentifier sourceCameraIdentifier, const Vector2& sourcePointFisheye, const Vector2& targetPointFisheye, const Scalar maxDistance = Scalar(2)) const;
103
104 /**
105 * Computes the squared distance from a target point to the epipolar line corresponding to a source point.
106 * @param sourceCameraIdentifier The identifier of the source camera, either CI_CAMERA0 or CI_CAMERA1
107 * @param sourcePointFisheye The point in the source camera, with range [0, sourceCamera.width())x[0, sourceCamera.height())
108 * @param targetPointFisheye The point in the target camera, with range [0, targetCamera.width())x[0, targetCamera.height())
109 * @return The squared distance from the target point to the epipolar line, in pixels^2, with range [0, infinity), or -1 if the computation fails
110 */
111 Scalar squareDistanceToEpipolarLine(const CameraIdentifier sourceCameraIdentifier, const Vector2& sourcePointFisheye, const Vector2& targetPointFisheye) const;
112
113 protected:
114
115 /**
116 * Reprojects a point from one camera to another.
117 * @param sourceCamera The source camera, must be valid
118 * @param targetCamera The target camera, must be valid
119 * @param sourcePoint The point in the source camera
120 * @return The reprojected point in the target camera
121 */
122 Vector2 reprojectPoint(const AnyCamera& sourceCamera, const AnyCamera& targetCamera, const Vector2& sourcePoint) const;
123
124 /**
125 * Computes the epipolar line in the target camera corresponding to a point in the source camera (in pinhole space).
126 * @param sourceCameraIdentifier The identifier of the source camera, either CI_CAMERA0 or CI_CAMERA1
127 * @param sourcePointFisheye The point in the source camera (fisheye space), with range [0, sourceCamera.width())x[0, sourceCamera.height())
128 * @param epipolarLinePinhole The resulting epipolar line in the target camera (pinhole space)
129 * @return True, if succeeded
130 */
131 bool epipolarLine(const CameraIdentifier sourceCameraIdentifier, const Vector2& sourcePointFisheye, Line2& epipolarLinePinhole) const;
132
133 protected:
134
135 /// The first fisheye camera
137
138 /// The second fisheye camera
140
141 /// The first pinhole camera
143
144 /// The second pinhole camera
146
147 /// The transformation from camera 1 to camera 0
149
150 /// The essential matrix from camera 0 to camera 1
152
153 /// The fundamental matrix from camera 0 to camera 1
155};
156
157} // namespace Geometry
158
159} // namespace Ocean
160
161#endif // META_OCEAN_GEOMETRY_FISHEYEEPIPOLARGEOMETRY_H
This class implements the abstract base class for all AnyCamera objects.
Definition AnyCamera.h:130
This class implements fisheye epipolar geometry functionality.
Definition FisheyeEpipolarGeometry.h:29
HomogenousMatrix4 camera0_T_camera1_
The transformation from camera 1 to camera 0.
Definition FisheyeEpipolarGeometry.h:148
SharedAnyCamera pinholeCamera0_
The first pinhole camera.
Definition FisheyeEpipolarGeometry.h:142
SquareMatrix3 camera1_E_camera0_
The essential matrix from camera 0 to camera 1.
Definition FisheyeEpipolarGeometry.h:151
bool isOnEpipolarLine(const CameraIdentifier sourceCameraIdentifier, const Vector2 &sourcePointFisheye, const Vector2 &targetPointFisheye, const Scalar maxDistance=Scalar(2)) const
Determines whether a target point lies on the epipolar line corresponding to a source point.
SquareMatrix3 camera1_F_camera0_
The fundamental matrix from camera 0 to camera 1.
Definition FisheyeEpipolarGeometry.h:154
bool epipolarLine(const CameraIdentifier sourceCameraIdentifier, const Vector2 &sourcePointFisheye, Line2 &epipolarLinePinhole) const
Computes the epipolar line in the target camera corresponding to a point in the source camera (in pin...
bool isValid() const
Returns whether this epipolar geometry object is valid.
CameraIdentifier
Definition of camera identifiers.
Definition FisheyeEpipolarGeometry.h:36
SharedAnyCamera fisheyeCamera0_
The first fisheye camera.
Definition FisheyeEpipolarGeometry.h:136
bool updateCameras(const SharedAnyCamera &camera0, const SharedAnyCamera &camera1, const HomogenousMatrix4 &camera0_T_camera1)
Updates the cameras and transformation of this epipolar geometry object.
Vector2 reprojectPoint(const AnyCamera &sourceCamera, const AnyCamera &targetCamera, const Vector2 &sourcePoint) const
Reprojects a point from one camera to another.
Scalar squareDistanceToEpipolarLine(const CameraIdentifier sourceCameraIdentifier, const Vector2 &sourcePointFisheye, const Vector2 &targetPointFisheye) const
Computes the squared distance from a target point to the epipolar line corresponding to a source poin...
SharedAnyCamera fisheyeCamera1_
The second fisheye camera.
Definition FisheyeEpipolarGeometry.h:139
FisheyeEpipolarGeometry()=default
Default constructor creating an invalid epipolar geometry object.
FisheyeEpipolarGeometry(const SharedAnyCamera &camera0, const SharedAnyCamera &camera1, const HomogenousMatrix4 &camera0_T_camera1)
Creates a new fisheye epipolar geometry object.
std::vector< Vector2 > EpipolarLine
Definition of an epipolar line as a vector of 2D points.
Definition FisheyeEpipolarGeometry.h:46
bool epipolarLine(const Vector2 &sourcePointFisheye, Vectors2 &fisheyeEpipolarLineSegments, const CameraIdentifier sourceCameraIdentifier=CI_CAMERA0, const Scalar lineStep=Scalar(70), const size_t maxNumberLineSegments=100u) const
Computes the epipolar line in the target camera corresponding to a point in the source camera.
SharedAnyCamera pinholeCamera1_
The second pinhole camera.
Definition FisheyeEpipolarGeometry.h:145
std::vector< EpipolarLine > EpipolarLines
Definition of a vector holding epipolar lines.
Definition FisheyeEpipolarGeometry.h:51
This class implements an infinite line in 2D space.
Definition Line2.h:83
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition AnyCamera.h:60
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition Vector2.h:64
The namespace covering the entire Ocean framework.
Definition Accessor.h:15