Ocean
Correspondences.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_ORB_CORRESPONDENCES_H
9 #define META_OCEAN_TRACKING_ORB_CORRESPONDENCES_H
10 
11 #include "ocean/tracking/orb/ORB.h"
13 
15 
17 
19 #include "ocean/math/Quaternion.h"
20 
21 #include <set>
22 #include <vector>
23 
24 namespace Ocean
25 {
26 
27 namespace Tracking
28 {
29 
30 namespace ORB
31 {
32 
33 /**
34  * This class implements simple helper functions for feature correspondences.
35  * @ingroup trackingorb
36  */
37 class OCEAN_TRACKING_ORB_EXPORT Correspondences
38 {
39  public:
40 
41  /**
42  * Definition of a pair holding the indices of two corresponding features.
43  */
44  typedef std::pair<unsigned int, unsigned int> CorrespondencePair;
45 
46  /**
47  * Definition of a vector holding correspondence pairs.
48  */
49  typedef std::vector<CorrespondencePair> CorrespondencePairs;
50 
51  /**
52  * Definition of a vector holding different feature indices.
53  */
54  typedef std::vector<CV::Detector::FeatureIndices> MultiCandidates;
55 
56  private:
57 
58  /**
59  * Definition of a set holding feature indices.
60  */
61  typedef std::set<unsigned int> CandidateSet;
62 
63  public:
64 
65  /**
66  * Extracts object and image positions of ORB features by pairs of feature correspondences.
67  * Beware: The indices of the feature correspondences must not exceed the number of forward or backward features respectively!
68  * @param forwardFeatures Forward or image features
69  * @param backwardFeatures Backward or object features
70  * @param correspondences Pairs of feature correspondences
71  * @param imagePoints Resultling image points taken form the forward features
72  * @param objectPoints Resulting object points taken from the backward features
73  */
74  static void extractCorrespondingPoints(const CV::Detector::ORBFeatures& forwardFeatures, const CV::Detector::ORBFeatures& backwardFeatures, const CorrespondencePairs& correspondences, Geometry::ImagePoints& imagePoints, Geometry::ObjectPoints& objectPoints);
75 
76  /**
77  * Extracts object and image features by pairs of feature correspondences all correspondences are expected to be valid.
78  * @param forwardFeatures Forward or image features building the correspondences
79  * @param backwardFeatures Backward or object features building the correspondences
80  * @param correspondencePairs Pairs of correspondence candidates defining a correspondence between forward and backward features
81  * @param forwardCorrespondences Resulting features from the forward correspondences
82  * @param backwardCorrespondences Resulting feature from the backward correspondences
83  */
84  static void extractCorrespondingFeatures(const CV::Detector::ORBFeatures& forwardFeatures, const CV::Detector::ORBFeatures& backwardFeatures, const CorrespondencePairs& correspondencePairs, CV::Detector::ORBFeatures& forwardCorrespondences, CV::Detector::ORBFeatures& backwardCorrespondences);
85 
86  /**
87  * Extracts object and image features by pairs of feature correspondences all correspondences are expected to be candidates.
88  * However, feature correspondences are extracted only if their projection error is below a given threshold.
89  * @param forwardFeatures Forward or image features building the correspondences
90  * @param backwardFeatures Backward or object features building the correspondences
91  * @param correspondencePairs Pairs of correspondence candidates defining a correspondence between forward and backward features
92  * @param pose Pose corresponding to the determined corresponding pairs
93  * @param pinholeCamera The pinhole camera used for tracking
94  * @param sqrDistance Maximal square distance of the projected object feature and the image feature
95  * @param forwardCorrespondences Resulting features from the forward correspondences
96  * @param backwardCorrespondences Resulting feature from the backward correspondences
97  */
98  static void extractCorrespondingFeatures(const CV::Detector::ORBFeatures& forwardFeatures, const CV::Detector::ORBFeatures& backwardFeatures, const CorrespondencePairs& correspondencePairs, const HomogenousMatrix4& pose, const PinholeCamera& pinholeCamera, const Scalar sqrDistance, CV::Detector::ORBFeatures& forwardCorrespondences, CV::Detector::ORBFeatures& backwardCorrespondences);
99 
100  /**
101  * Extracts object and image features by pairs of feature correspondence candidates.
102  * Some candidates are expected to be invalid, thus additional indices specify the valid candidates.
103  * @param forwardFeatures Forward or image features building the correspondences
104  * @param backwardFeatures Backward or object features building the correspondences
105  * @param candidatePairs Pairs of correspondence candidates defining a correspondence between forward and backward features
106  * @param correspondenceIndices Indices specifying the valid pairs of corresponding candidates
107  * @param forwardCorrespondences Resulting features from the forward correspondences
108  * @param backwardCorrespondences Resulting feature from the backward correspondences
109  */
110  static void extractCorrespondingFeatures(const CV::Detector::ORBFeatures& forwardFeatures, const CV::Detector::ORBFeatures& backwardFeatures, const CorrespondencePairs& candidatePairs, const CV::Detector::FeatureIndices& correspondenceIndices, CV::Detector::ORBFeatures& forwardCorrespondences, CV::Detector::ORBFeatures& backwardCorrespondences);
111 
112  /**
113  * Determines candidates for feature correspondences upon their spatial position in the frame.
114  * @param interestFeatures ORB features of interest to find candidates for
115  * @param candidatePool A pool of ORB features holding all possible candidates
116  * @param window Size of the search window for possible candidates
117  * @param multiCandidates Lists of feature candidates for each feature of interest
118  * @param candidates List of all feature candidates
119  */
120  static void determineCandidates(const CV::Detector::ORBFeatures& interestFeatures, const CV::Detector::ORBFeatures& candidatePool, const Scalar window, MultiCandidates& multiCandidates, CV::Detector::FeatureIndices& candidates);
121 };
122 
123 }
124 
125 }
126 
127 }
128 
129 #endif // META_OCEAN_TRACKING_ORB_CORRESPONDENCES_H
This class implements simple helper functions for feature correspondences.
Definition: Correspondences.h:38
std::vector< CorrespondencePair > CorrespondencePairs
Definition of a vector holding correspondence pairs.
Definition: Correspondences.h:49
static void extractCorrespondingFeatures(const CV::Detector::ORBFeatures &forwardFeatures, const CV::Detector::ORBFeatures &backwardFeatures, const CorrespondencePairs &correspondencePairs, CV::Detector::ORBFeatures &forwardCorrespondences, CV::Detector::ORBFeatures &backwardCorrespondences)
Extracts object and image features by pairs of feature correspondences all correspondences are expect...
static void extractCorrespondingFeatures(const CV::Detector::ORBFeatures &forwardFeatures, const CV::Detector::ORBFeatures &backwardFeatures, const CorrespondencePairs &candidatePairs, const CV::Detector::FeatureIndices &correspondenceIndices, CV::Detector::ORBFeatures &forwardCorrespondences, CV::Detector::ORBFeatures &backwardCorrespondences)
Extracts object and image features by pairs of feature correspondence candidates.
static void extractCorrespondingFeatures(const CV::Detector::ORBFeatures &forwardFeatures, const CV::Detector::ORBFeatures &backwardFeatures, const CorrespondencePairs &correspondencePairs, const HomogenousMatrix4 &pose, const PinholeCamera &pinholeCamera, const Scalar sqrDistance, CV::Detector::ORBFeatures &forwardCorrespondences, CV::Detector::ORBFeatures &backwardCorrespondences)
Extracts object and image features by pairs of feature correspondences all correspondences are expect...
std::set< unsigned int > CandidateSet
Definition of a set holding feature indices.
Definition: Correspondences.h:61
std::vector< CV::Detector::FeatureIndices > MultiCandidates
Definition of a vector holding different feature indices.
Definition: Correspondences.h:54
static void extractCorrespondingPoints(const CV::Detector::ORBFeatures &forwardFeatures, const CV::Detector::ORBFeatures &backwardFeatures, const CorrespondencePairs &correspondences, Geometry::ImagePoints &imagePoints, Geometry::ObjectPoints &objectPoints)
Extracts object and image positions of ORB features by pairs of feature correspondences.
std::pair< unsigned int, unsigned int > CorrespondencePair
Definition of a pair holding the indices of two corresponding features.
Definition: Correspondences.h:44
static void determineCandidates(const CV::Detector::ORBFeatures &interestFeatures, const CV::Detector::ORBFeatures &candidatePool, const Scalar window, MultiCandidates &multiCandidates, CV::Detector::FeatureIndices &candidates)
Determines candidates for feature correspondences upon their spatial position in the frame.
unsigned int sqrDistance(const char first, const char second)
Returns the square distance between two values.
Definition: base/Utilities.h:1089
std::vector< unsigned int > FeatureIndices
Definition of a vector holding feature indices.
Definition: Feature.h:28
std::vector< ORBFeature > ORBFeatures
Definition of a vector holding ORB features.
Definition: ORBFeature.h:26
std::vector< ObjectPoint > ObjectPoints
Definition of a vector holding 3D object points.
Definition: geometry/Geometry.h:129
std::vector< ImagePoint > ImagePoints
Definition of a vector holding 2D image points.
Definition: geometry/Geometry.h:123
float Scalar
Definition of a scalar type.
Definition: Math.h:128
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15