Ocean
MapMerging.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_MAPBUILDING_MAP_MERGING_H
9 #define META_OCEAN_TRACKING_MAPBUILDING_MAP_MERGING_H
10 
14 
16 #include "ocean/base/Worker.h"
17 
19 
21 
22 namespace Ocean
23 {
24 
25 namespace Tracking
26 {
27 
28 namespace MapBuilding
29 {
30 
31 /**
32  * This class implements merging algorithms and functionalities for maps.
33  * @ingroup trackingmapbuilding
34  */
35 class OCEAN_TRACKING_MAPBUILDING_EXPORT MapMerging : public DescriptorHandling
36 {
37  public:
38 
39  /**
40  * Executes bundle adjustment in a given database.
41  * @param database The database in which the bundle adjustment will be executed
42  * @param pinholeCamera The pinhole camera profile to be used, must be valid
43  * @param randomGenerator The random generator object to be used
44  * @param iterations The number of optimization iterations, with range [1, infinity)
45  * @return True, if succeeded
46  */
47  static bool bundleAdjustment(Database& database, const PinholeCamera& pinholeCamera, RandomGenerator& randomGenerator, const unsigned int iterations);
48 
49  /**
50  * Closes the loop(s) in a database and merges all corresponding 3D object points.
51  * @param database The database in which the loops will be closed
52  * @param freakMap The map mapping object points to descriptors
53  * @param pinholeCamera The pinhole camera profile to be used, must be valid
54  * @param randomGenerator The random generator to be used
55  * @param minimalNumberValidCorrespondences The minimal number of valid correspondences between 3D object points and (not associated) 2D image points so that the correspondences are considered to be valid and thus a closed loop, with range [3, infinity)
56  * @param maximalNumberOverlappingObjectPointInPosePair The maximal number of 3D object points which can be visible in both frames so that both frames are still considered for loop closing, with range [0, infinity)
57  * @param maximalDescriptorDistance The maximal descriptor distance so that two descriptors are still considered to match, with range [0, infinity)
58  * @param iterationsWithoutImprovements The number of loop searching iterations without any further loop improvement until the search for further loops stops, with range [1, infinity)
59  * @return The number of merged object points
60  */
61  static size_t closeLoops(Database& database, FreakMultiDescriptorMap256& freakMap, const PinholeCamera& pinholeCamera, RandomGenerator& randomGenerator, const unsigned int minimalNumberValidCorrespondences, const unsigned int maximalNumberOverlappingObjectPointInPosePair = 50u, const unsigned int maximalDescriptorDistance = 64u, const unsigned int iterationsWithoutImprovements = 100u);
62 
63  /**
64  * Merges individual 3D object points in a database.
65  * Object points with are not visible in the same frame (not known to be visible) will be merged if the projection error of both object points are below a threshold.
66  * @param database The database in which the 3D object points will be merged
67  * @param freakMap The map mapping object points to descriptors
68  * @param pinholeCamera The pinhole camera profile to be used, must be valid
69  * @param randomGenerator The random generator to be used
70  * @param maximalProjectionError The maximal projection error between a projected 3D object point and a 2D image point to count as corresponding, in pixel, with range [0, infinity)
71  * @param maximalDescriptorDistance The maximal descriptor distance so that two descriptors are still considered to match, with range [0, infinity)
72  * @param iterationsWithoutImprovements The number of searching iterations without any further improvement until the search for further loops stops, with range [1, infinity)
73  * @return The number of merged object points
74  */
75  static size_t mergeObjectPoints(Database& database, FreakMultiDescriptorMap256& freakMap, const PinholeCamera& pinholeCamera, RandomGenerator& randomGenerator, const Scalar maximalProjectionError, const unsigned int maximalDescriptorDistance = 64u, const unsigned int iterationsWithoutImprovements = 100u);
76 
77  /**
78  * Merges two maps together.
79  * @param sourceCamera The camera profile used for the source database
80  * @param sourceDatabase The source database which will be merged into the target database
81  * @param sourceDescriptorMap The descriptor map for the source database
82  * @param targetCamera The camera profile used for the target database
83  * @param targetDatabase The target database in which the source database will be merged
84  * @param targetDescriptorMap the descriptor map for the target database
85  * @param randomGenerator The random generator to be used
86  * @param minimalNumberCorrespondingFeaturesPerPose The minimal number of feature correspondences between the source and target database in one frame so that both frames (and their feature points) count as corresponding and will be merged, with range [3, infinity)
87  * @param minimalNumberCorrespondingPoses The minimal number of corresponding poses between source and target database so that a set of candidate correspondences count as valid, with range [1, infinity)
88  * @param iterationsWithoutImprovements The number of searching iterations without any further improvement until the search for further improvements stops, with range [1, infinity)
89  * @param maximalNumberImprovements The maximal number of merging improvements, with range [1, infinity)
90  * @return True, if succeeded
91  */
92  static bool mergeMaps(const PinholeCamera& sourceCamera, const Database& sourceDatabase, const UnifiedDescriptorMap& sourceDescriptorMap, const PinholeCamera& targetCamera, Database& targetDatabase, UnifiedDescriptorMap& targetDescriptorMap, RandomGenerator& randomGenerator, const unsigned int minimalNumberCorrespondingFeaturesPerPose = 50u, const unsigned int minimalNumberCorrespondingPoses = 20u, const unsigned int iterationsWithoutImprovements = 100u, const unsigned int maximalNumberImprovements = (unsigned int)(-1));
93 };
94 
95 }
96 
97 }
98 
99 }
100 
101 #endif // META_OCEAN_TRACKING_MAPBUILDING_MAP_MERGING_H
This class implements a generator for random numbers.
Definition: RandomGenerator.h:42
This class implements a database for 3D object points, 2D image points and 6DOF camera poses.
Definition: Database.h:67
This class implements functions necessary when handling descriptors.
Definition: DescriptorHandling.h:32
std::unordered_map< Index32, FreakMultiDescriptors256 > FreakMultiDescriptorMap256
Definition of an unordered map mapping FREAK Multi descriptors.
Definition: DescriptorHandling.h:48
This class implements merging algorithms and functionalities for maps.
Definition: MapMerging.h:36
static size_t mergeObjectPoints(Database &database, FreakMultiDescriptorMap256 &freakMap, const PinholeCamera &pinholeCamera, RandomGenerator &randomGenerator, const Scalar maximalProjectionError, const unsigned int maximalDescriptorDistance=64u, const unsigned int iterationsWithoutImprovements=100u)
Merges individual 3D object points in a database.
static bool mergeMaps(const PinholeCamera &sourceCamera, const Database &sourceDatabase, const UnifiedDescriptorMap &sourceDescriptorMap, const PinholeCamera &targetCamera, Database &targetDatabase, UnifiedDescriptorMap &targetDescriptorMap, RandomGenerator &randomGenerator, const unsigned int minimalNumberCorrespondingFeaturesPerPose=50u, const unsigned int minimalNumberCorrespondingPoses=20u, const unsigned int iterationsWithoutImprovements=100u, const unsigned int maximalNumberImprovements=(unsigned int)(-1))
Merges two maps together.
static bool bundleAdjustment(Database &database, const PinholeCamera &pinholeCamera, RandomGenerator &randomGenerator, const unsigned int iterations)
Executes bundle adjustment in a given database.
static size_t closeLoops(Database &database, FreakMultiDescriptorMap256 &freakMap, const PinholeCamera &pinholeCamera, RandomGenerator &randomGenerator, const unsigned int minimalNumberValidCorrespondences, const unsigned int maximalNumberOverlappingObjectPointInPosePair=50u, const unsigned int maximalDescriptorDistance=64u, const unsigned int iterationsWithoutImprovements=100u)
Closes the loop(s) in a database and merges all corresponding 3D object points.
This class implements the base class for all unified descriptor maps in which ids are mapped to descr...
Definition: UnifiedDescriptorMap.h:38
float Scalar
Definition of a scalar type.
Definition: Math.h:128
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15