Ocean
orb/UnidirectionalCorrespondences.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_UNIDIRECTIONAL_CORRESPONDENCES_H
9 #define META_OCEAN_TRACKING_ORB_UNIDIRECTIONAL_CORRESPONDENCES_H
10 
11 #include "ocean/tracking/orb/ORB.h"
13 
14 #include "ocean/base/Lock.h"
15 #include "ocean/base/Worker.h"
16 
18 
20 
21 #include <vector>
22 
23 namespace Ocean
24 {
25 
26 namespace Tracking
27 {
28 
29 namespace ORB
30 {
31 
32 /**
33  * This class provides unidirectional feature correspondences.
34  * @ingroup trackingorb
35  */
36 class OCEAN_TRACKING_ORB_EXPORT UnidirectionalCorrespondences : public Correspondences
37 {
38  public:
39 
40  /**
41  * Definition of a vector counting correspondences.
42  */
43  typedef std::vector<unsigned int> CorrespondenceCounters;
44 
45  public:
46 
47  /**
48  * Creates a new unidirecitonal correspondences object.
49  * @param numberForward Number of forward features
50  * @param numberBackward Number of backward features
51  */
52  UnidirectionalCorrespondences(const unsigned int numberForward, const unsigned int numberBackward);
53 
54  /**
55  * Adds a new feature correspondence candidate.
56  * The given indices must be below the number of specified features.<br>
57  * Beware: This function is not threadsafe!
58  * @param forwardIndex Index of the forward feature
59  * @param backwardIndex Index of the best matching backward feature
60  */
61  void addCandidate(const unsigned int forwardIndex, const unsigned int backwardIndex);
62 
63  /**
64  * Adds a new feature correspondence candidate.
65  * The given indices must be below the number of specified features.<br>
66  * This function is threadsafe.
67  * @param forwardIndex Index of the forward feature
68  * @param backwardIndex Index of the best matching backward feature
69  */
70  void lockedAddCandidate(const unsigned int forwardIndex, const unsigned int backwardIndex);
71 
72  /**
73  * Returns all uni-directional feature correspondences.
74  * Beware: This function is not threadsafe!
75  * @return Unique feature correspondences
76  */
78 
79  /**
80  * Determines unidirectional features correspondences between two sets of features without any previous knowledge.
81  * @param forwardFeatures The forward features for which corresponding backward features will be determined, at least one
82  * @param backwardFeatures The backward features to be used
83  * @param threshold The percentage (in relation to the number of descriptor bits) of the maximal hamming distance so that two descriptors count as similar, with range [0, 1]
84  * @param worker Optional worker object to distribute the computation to several CPU cores
85  * @return The determined resulting correspondences
86  */
87  static CorrespondencePairs determineBijectiveCorrespondences(const CV::Detector::ORBFeatures& forwardFeatures, const CV::Detector::ORBFeatures& backwardFeatures, const float threshold = 0.15f, Worker* worker = nullptr);
88 
89  /**
90  * Determines unidirectional features correspondences of two sets of features with previous knowledge.
91  * Based on a given camera profile and a rough camera pose, feature candidates are rejected if the projected (backward) feature points is not close enough to the corresponding (forward) feature point.
92  * @param forwardFeatures The forward features for which corresponding backward features will be determined, at least one
93  * @param backwardFeatures The backward features to be used
94  * @param pinholeCamera The pinhole camera profile defining the projection, must be valid
95  * @param pose The rough camera pose, e.g., a pose from the previous frame, must be valid
96  * @param threshold The percentage (in relation to the number of descriptor bits) of the maximal hamming distance so that two descriptors count as similar, with range [0, 1]
97  * @return correspondencePairs Resulting correspondences
98  */
99  static CorrespondencePairs determineBijectiveCorrespondencesWithPose(const CV::Detector::ORBFeatures& forwardFeatures, const CV::Detector::ORBFeatures& backwardFeatures, const PinholeCamera& pinholeCamera, const HomogenousMatrix4& pose, const float threshold = 0.15f);
100 
101  private:
102 
103  /// Correspondence counter for forward features.
105 
106  /// Correspondence counter for backward features.
108 
109  /// Correspondence candidates.
111 
112  /// Lock object.
114 };
115 
116 }
117 
118 }
119 
120 }
121 
122 #endif // META_OCEAN_TRACKING_ORB_UNIDIRECTIONAL_CORRESPONDENCES_H
This class implements a recursive lock object.
Definition: Lock.h:31
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
This class provides unidirectional feature correspondences.
Definition: orb/UnidirectionalCorrespondences.h:37
void addCandidate(const unsigned int forwardIndex, const unsigned int backwardIndex)
Adds a new feature correspondence candidate.
Lock correspondenceLock
Lock object.
Definition: orb/UnidirectionalCorrespondences.h:113
static CorrespondencePairs determineBijectiveCorrespondencesWithPose(const CV::Detector::ORBFeatures &forwardFeatures, const CV::Detector::ORBFeatures &backwardFeatures, const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const float threshold=0.15f)
Determines unidirectional features correspondences of two sets of features with previous knowledge.
std::vector< unsigned int > CorrespondenceCounters
Definition of a vector counting correspondences.
Definition: orb/UnidirectionalCorrespondences.h:43
static CorrespondencePairs determineBijectiveCorrespondences(const CV::Detector::ORBFeatures &forwardFeatures, const CV::Detector::ORBFeatures &backwardFeatures, const float threshold=0.15f, Worker *worker=nullptr)
Determines unidirectional features correspondences between two sets of features without any previous ...
CorrespondenceCounters correspondenceForwardCounters
Correspondence counter for forward features.
Definition: orb/UnidirectionalCorrespondences.h:104
CorrespondencePairs correspondences() const
Returns all uni-directional feature correspondences.
void lockedAddCandidate(const unsigned int forwardIndex, const unsigned int backwardIndex)
Adds a new feature correspondence candidate.
UnidirectionalCorrespondences(const unsigned int numberForward, const unsigned int numberBackward)
Creates a new unidirecitonal correspondences object.
CorrespondenceCounters correspondenceBackwardCounters
Correspondence counter for backward features.
Definition: orb/UnidirectionalCorrespondences.h:107
CorrespondencePairs correspondenceCandidates
Correspondence candidates.
Definition: orb/UnidirectionalCorrespondences.h:110
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
std::vector< ORBFeature > ORBFeatures
Definition of a vector holding ORB features.
Definition: ORBFeature.h:26
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15