Ocean
PnP.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_PNP_H
9 #define META_OCEAN_GEOMETRY_PNP_H
10 
13 
14 #include "ocean/math/AnyCamera.h"
15 
16 namespace Ocean
17 {
18 
19 namespace Geometry
20 {
21 
22 /**
23  * This class provides functions determining the camera's pose based on at least five 3D object and corresponding 2D image points.
24  * @ingroup geometry
25  */
26 class OCEAN_GEOMETRY_EXPORT PnP : public PerspectivePose
27 {
28  public:
29 
30  /**
31  * Calculates the pose of a camera by a set of at least five image and object points.
32  * @param camera The camera profile defining the projection, must be valid
33  * @param objectPoints The 3D object points for which the camera pose will be determined, defined in world, must be valid
34  * @param imagePoints The 2D image points located in the camera image, one for each 3D object point, must be valid
35  * @param correspondences Number of point correspondences, with range [5, infinity)
36  * @param world_T_camera Resulting camera pose, with default camera pointing towards the negative z-space, with y-axis upwards
37  * @return True, if succeeded
38  */
39  static bool pose(const AnyCamera& camera, const Vector3* objectPoints, const Vector2* imagePoints, const size_t correspondences, HomogenousMatrix4& world_T_camera);
40 
41  protected:
42 
43  /**
44  * Calculates distances between camera center and at least five 3D object points.
45  * @param objectPoints The object points for which the distances will be determined, must be valid
46  * @param imageRays Three 3D rays with unit length, defined in the coordinate system of the camera, starting at the camera's center of projection (equal to the origin), hitting the image plane at image points corresponding to the 3D object points and pointing towards the object points, each ray corresponds to one 3D object point, must be valid
47  * @param correspondences Number of point correspondences, with range [5, infinity)
48  * @param distances Resulting distances between camera center and each of the object points
49  * @return True, if succeeded
50  */
51  static bool calculatePointDistances(const Vector3* objectPoints, const Vector3* imageRays, const size_t correspondences, Scalars &distances);
52 
53  /**
54  * Calculates the eighth degree polynomial resulting from three law of cosine polynomials.
55  * It uses the method of Sylvester resultants.<br>
56  * <pre>
57  * g(x) = a4 x^8 + a3 x^6 + a2 x^4 + a1 x1^2 + a0 = 0
58  * </pre>
59  * @param cos12 Cosine value of angle between first and second leg
60  * @param cos13 Cosine value of angle between first and third leg
61  * @param cos23 Cosine value of angle between second and third leg
62  * @param d12_2 Square of distance between first and second object point
63  * @param d13_2 Square of distance between first and third object point
64  * @param d23_2 Square of distance between second and third object point
65  * @param a0 Resulting parameter for x1^0
66  * @param a1 Resulting parameter for x1^2
67  * @param a2 Resulting parameter for x1^4
68  * @param a3 Resulting parameter for x1^6
69  * @param a4 Resulting parameter for x1^8
70  * @return True, if succeeded
71  */
72  static bool calculateResultant(const Scalar cos12, const Scalar cos13, const Scalar cos23, const Scalar d12_2, const Scalar d13_2, const Scalar d23_2, Scalar& a0, Scalar& a1, Scalar& a2, Scalar& a3, Scalar& a4);
73 
74  /**
75  * Calculates the eighth degree polynomial resulting from three law of cosine polynomials.
76  * It uses the method of Sylvester resultants.<br>
77  * It's optimized to performance.
78  * <pre>
79  * g(x) = a4 x^8 + a3 x^6 + a2 x^4 + a1 x1^2 + a0 = 0
80  * </pre>
81  * @param cos12 Cosine value of angle between first and second leg
82  * @param cos13 Cosine value of angle between first and third leg
83  * @param cos23 Cosine value of angle between second and third leg
84  * @param d12_2 Square of distance between first and second object point
85  * @param d13_2 Square of distance between first and third object point
86  * @param d23_2 Square of distance between second and third object point
87  * @param a0 Resulting parameter for x1^0
88  * @param a1 Resulting parameter for x1^2
89  * @param a2 Resulting parameter for x1^4
90  * @param a3 Resulting parameter for x1^6
91  * @param a4 Resulting parameter for x1^8
92  * @return True, if succeeded
93  */
94  static bool calculateResultantOptimized(const Scalar cos12, const Scalar cos13, const Scalar cos23, const Scalar d12_2, const Scalar d13_2, const Scalar d23_2, Scalar& a0, Scalar& a1, Scalar& a2, Scalar& a3, Scalar& a4);
95 };
96 
97 }
98 
99 }
100 
101 #endif // META_OCEAN_GEOMETRY_PNP_H
This class implements the abstract base class for all AnyCamera objects.
Definition: AnyCamera.h:130
This class is the base class for all perspective pose classes.
Definition: PerspectivePose.h:27
This class provides functions determining the camera's pose based on at least five 3D object and corr...
Definition: PnP.h:27
static bool calculateResultant(const Scalar cos12, const Scalar cos13, const Scalar cos23, const Scalar d12_2, const Scalar d13_2, const Scalar d23_2, Scalar &a0, Scalar &a1, Scalar &a2, Scalar &a3, Scalar &a4)
Calculates the eighth degree polynomial resulting from three law of cosine polynomials.
static bool calculatePointDistances(const Vector3 *objectPoints, const Vector3 *imageRays, const size_t correspondences, Scalars &distances)
Calculates distances between camera center and at least five 3D object points.
static bool calculateResultantOptimized(const Scalar cos12, const Scalar cos13, const Scalar cos23, const Scalar d12_2, const Scalar d13_2, const Scalar d23_2, Scalar &a0, Scalar &a1, Scalar &a2, Scalar &a3, Scalar &a4)
Calculates the eighth degree polynomial resulting from three law of cosine polynomials.
static bool pose(const AnyCamera &camera, const Vector3 *objectPoints, const Vector2 *imagePoints, const size_t correspondences, HomogenousMatrix4 &world_T_camera)
Calculates the pose of a camera by a set of at least five image and object points.
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< Scalar > Scalars
Definition of a vector holding Scalar objects.
Definition: Math.h:144
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15