forked from AaltoML/SLAM-module
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrelocation.cpp
More file actions
63 lines (54 loc) · 1.73 KB
/
relocation.cpp
File metadata and controls
63 lines (54 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "relocation.hpp"
#include "../util/logging.hpp"
#include "keyframe_matcher.hpp"
#include "loop_ransac.hpp"
namespace slam {
void tryRelocation(
KfId currentKfId,
MapKf candidate,
MapDB ¤tMapDB,
const Atlas &atlas,
const odometry::ParametersSlam ¶meters,
const StaticSettings &settings
) {
const MapDB &candidateMapDB = atlas[candidate.mapId.v];
const Keyframe ¤tKf = *currentMapDB.keyframes.at(currentKfId);
const Keyframe &candidateKf = *candidateMapDB.keyframes.at(candidate.kfId);
std::vector<int> matchedFeatureIds;
matchForLoopClosures(
currentKf,
candidateKf,
currentMapDB,
candidateMapDB,
matchedFeatureIds,
parameters);
std::vector<std::pair<MpId, MpId>> matches;
for (unsigned i = 0; i < matchedFeatureIds.size(); ++i) {
const int kfIdx2 = matchedFeatureIds.at(i);
if (kfIdx2 >= 0) {
const MpId mpId1 = currentKf.mapPoints.at(i);
const MpId mpId2 = candidateKf.mapPoints.at(kfIdx2);
if (mpId1.v != -1 && mpId2.v != -1) {
matches.emplace_back(mpId1, mpId2);
}
}
}
if (matches.size() < parameters.minLoopClosureFeatureMatches) {
return;
}
currentMapDB.loopStages[candidate] = LoopStage::RELOCATION_MAP_POINT_MATCHES;
LoopRansac loopRansac(
currentKf,
candidateKf,
matches,
currentMapDB,
candidateMapDB,
settings
);
loopRansac.ransacSolve(parameters.loopClosureRansacIterations, LoopRansac::DoF::SIM3);
if (!loopRansac.solutionOk) {
return;
}
currentMapDB.loopStages[candidate] = LoopStage::RELOCATION_MAP_POINT_RANSAC;
}
} // namespace slam