Ocean
HomographyPlaneFinder.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_TRACKING_HOMOGRAPHY_PLANE_FINDER_H
9 #define META_OCEAN_TRACKING_HOMOGRAPHY_PLANE_FINDER_H
10 
13 
15 
16 namespace Ocean
17 {
18 
19 namespace Tracking
20 {
21 
22 /**
23  * This class implements a 3D plane finder that determines the plane by calculation of a homography between two frames taken from two individual camera positions.
24  * The resulting plane quality can be improved by using more than two frames.<br>
25  * Two possible plane solutions will be provided.<br>
26  * **NOTE** This class is almost obsolete we keep it for demonstration purpose only.
27  * @ingroup tracking
28  */
29 class OCEAN_TRACKING_EXPORT HomographyPlaneFinder : public PlaneFinder
30 {
31  public:
32 
33  /**
34  * Definition of a pair storing two corresponding normals.
35  */
36  typedef std::pair<Vector3, Vector3> NormalPair;
37 
38  protected:
39 
40  /**
41  * Definition of a vector holding pairs of normals.
42  */
43  typedef std::vector<NormalPair> NormalPairs;
44 
45  public:
46 
47  /**
48  * Creates a new plane finder object.
49  */
50  inline HomographyPlaneFinder();
51 
52  /**
53  * Returns the first point set that is stored.
54  * @return First set of points
55  */
56  inline const Vectors2& initialImagePoints() const;
57 
58  /**
59  * Returns the current point set that is stored.
60  * @return current set of points
61  */
62  inline const Vectors2& currentImagePoints() const;
63 
64  /**
65  * Adds new image points as new set of correspondences.
66  * After new points have added the homography determination needs to be invoked.<br>
67  * @see PlaneFinder::addImagePoint(), applyHomographyDetermination().
68  */
69  virtual bool addImagePoint(const Vectors2& imagePoints);
70 
71  /**
72  * Adds new image points as new set of correspondences.
73  * After new points have added the homography determination needs to be invoked.<br>
74  * @see PlaneFinder::addImagePoint(), applyHomographyDetermination().
75  */
76  virtual bool addImagePoint(Vectors2&& imagePoints);
77 
78  /**
79  * Adds a new subset of image points that corresponds to a subset of the stored sets of image points.
80  * After new points have added the homography determination needs to be invoked.<br>
81  * @see PlaneFinder::addImagePoint(), applyHomographyDetermination().
82  */
83  virtual bool addImagePoint(const Vectors2& imagePoints, const Indices32& validIndices);
84 
85  /**
86  * Determines a new set of plane candidates matching with the currently stored image point correspondences.
87  * The new candidates will be added to the large set of possible plane candidates finally allowing to determine the most reliable/accurate plane(s).
88  * @param pinhole The pinhole camera profile defining the projection, must be valid
89  * @return True, if succeeded
90  * @see determineMostAccuratePlanes().
91  */
92  bool addPlaneCandidates(const PinholeCamera& pinhole);
93 
94  /**
95  * Checks whether one of the last three successive frames provided almost identical plane normals.
96  * @param maxAngle The maximal angle between two plane normals, in radian, with range [0, PI/2)
97  */
98  bool hasAccuratePlane(const Scalar maxAngle);
99 
100  /**
101  * Determines the pair of planes which have been determined in the previous calls of addPlaneCandidates().
102  * @param planes The two resulting planes
103  * @return True, if succeeded
104  */
106 
107  protected:
108 
109  /**
110  * Determines the maximal cosine value between three pairs of plane normals.
111  * @param minus The previous pairs of plane normals
112  * @param center The current pairs of plane normals
113  * @param plus The next pairs of plane normals
114  * @return The maximal cosine value, with range [-1, 1]
115  */
116  static Scalar maximalCosBetweenNormalPairs(const NormalPair& minus, const NormalPair& center, const NormalPair& plus);
117 
118  /**
119  * Determines the pair of normals with smallest angle.
120  * @param normalPairs The pairs of normals, at least 3
121  * @param index The resulting index of the best pairs, with range [0, normalPairs.size())
122  * @param angle The resulting angle between the best pairs of normals
123  * @return True, if succeeded
124  */
125  static bool determineBestNormalPair(const NormalPairs& normalPairs, size_t& index, Scalar& angle);
126 
127  protected:
128 
129  /// Successive plane normal sets.
131 
132  /// Random number generator.
134 
135  /// Number of image points sets that have been added.
137 };
138 
140  planeImagePointsSets(0)
141 {
142  // nothing to do here
143 }
144 
146 {
147  ocean_assert(!imagePointCorrespondences.isEmpty());
149 }
150 
152 {
153  ocean_assert(!imagePointCorrespondences.isEmpty());
155 }
156 
157 }
158 
159 }
160 
161 #endif // META_OCEAN_TRACKING_HOMOGRAPHY_PLANE_FINDER_H
This class implements a generator for random numbers.
Definition: RandomGenerator.h:42
bool isEmpty() const
Returns whether this object does not hold any set of elements.
Definition: CorrespondenceSet.h:536
const ElementsVector & correspondences() const
Returns the set of stored correspondences.
Definition: CorrespondenceSet.h:258
This class implements a 3D plane finder that determines the plane by calculation of a homography betw...
Definition: HomographyPlaneFinder.h:30
static bool determineBestNormalPair(const NormalPairs &normalPairs, size_t &index, Scalar &angle)
Determines the pair of normals with smallest angle.
std::pair< Vector3, Vector3 > NormalPair
Definition of a pair storing two corresponding normals.
Definition: HomographyPlaneFinder.h:36
HomographyPlaneFinder()
Creates a new plane finder object.
Definition: HomographyPlaneFinder.h:139
bool addPlaneCandidates(const PinholeCamera &pinhole)
Determines a new set of plane candidates matching with the currently stored image point correspondenc...
NormalPairs planeFinderNormalPairs
Successive plane normal sets.
Definition: HomographyPlaneFinder.h:130
const Vectors2 & initialImagePoints() const
Returns the first point set that is stored.
Definition: HomographyPlaneFinder.h:145
const Vectors2 & currentImagePoints() const
Returns the current point set that is stored.
Definition: HomographyPlaneFinder.h:151
bool determineMostAccuratePlanes(Plane3 planes[2])
Determines the pair of planes which have been determined in the previous calls of addPlaneCandidates(...
static Scalar maximalCosBetweenNormalPairs(const NormalPair &minus, const NormalPair &center, const NormalPair &plus)
Determines the maximal cosine value between three pairs of plane normals.
bool hasAccuratePlane(const Scalar maxAngle)
Checks whether one of the last three successive frames provided almost identical plane normals.
RandomGenerator randomGenerator
Random number generator.
Definition: HomographyPlaneFinder.h:133
std::vector< NormalPair > NormalPairs
Definition of a vector holding pairs of normals.
Definition: HomographyPlaneFinder.h:43
size_t planeImagePointsSets
Number of image points sets that have been added.
Definition: HomographyPlaneFinder.h:136
virtual bool addImagePoint(const Vectors2 &imagePoints, const Indices32 &validIndices)
Adds a new subset of image points that corresponds to a subset of the stored sets of image points.
virtual bool addImagePoint(Vectors2 &&imagePoints)
Adds new image points as new set of correspondences.
virtual bool addImagePoint(const Vectors2 &imagePoints)
Adds new image points as new set of correspondences.
This class implements a 3D plane finder without any previous knowledge about the plane or the camera ...
Definition: PlaneFinder.h:32
ImagePointCorrespondenceSet imagePointCorrespondences
The set of image point correspondences.
Definition: PlaneFinder.h:123
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
float Scalar
Definition of a scalar type.
Definition: Math.h:128
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