35 for (
const auto& kv : matches) {
36 const auto pair_indices = kv.first;
37 const auto corr_indices = kv.second;
40 size_t i1 = pair_indices.first;
41 size_t i2 = pair_indices.second;
42 size_t m =
static_cast<size_t>(corr_indices.rows());
43 for (
size_t k = 0; k <
m; k++) {
45 size_t k1 = corr_indices(k, 0), k2 = corr_indices(k, 1);
47 dsf.
merge({i1, k1}, {i2, k2});
60 for (
const auto& index_pair : index_pair_set) {
63 size_t i = index_pair.i();
64 size_t k = index_pair.j();
73 static std::vector<SfmTrack2d>
tracksFromDSF(
const DSFMapIndexPair& dsf,
75 const std::map<IndexPair, std::set<IndexPair> > key_sets = dsf.
sets();
78 if (key_sets.empty())
return {};
82 std::vector<SfmTrack2d> tracks2d;
83 for (
const auto& kv : key_sets) {
86 tracks2d.emplace_back(track2d);
107 if (verbose) std::cout <<
"[SfmTrack2d] Starting Union-Find..." << std::endl;
109 if (verbose) std::cout <<
"[SfmTrack2d] Union-Find Complete" << std::endl;
111 std::vector<SfmTrack2d> tracks2d =
tracksFromDSF(dsf, keypoints);
116 std::vector<SfmTrack2d> validTracks;
118 tracks2d.begin(), tracks2d.end(), std::back_inserter(validTracks),
119 [](
const SfmTrack2d& track2d) {
return track2d.hasUniqueCameras(); });
122 size_t erroneous_track_count = tracks2d.size() - validTracks.size();
123 double erroneous_percentage =
static_cast<float>(erroneous_track_count) /
124 static_cast<float>(tracks2d.size()) * 100;
126 std::cout << std::fixed << std::setprecision(2);
127 std::cout <<
"DSF Union-Find: " << erroneous_percentage;
128 std::cout <<
"% of tracks discarded from multiple obs. in a single image."
void merge(const KEY &x, const KEY &y)
Merge two sets.
DSFMap< IndexPair > DSFMapIndexPair
std::map< IndexPair, CorrespondenceIndices > MatchIndicesMap
static DSFMapIndexPair generateDSF(const MatchIndicesMap &matches)
Generate the DSF to form tracks.
static SfmTrack2d trackFromIndexPairs(const std::set< IndexPair > &index_pair_set, const KeypointsVector &keypoints)
Generate a single track from a set of index pairs.
Identifies connected components in the keypoint matches graph.
static std::vector< SfmTrack2d > tracksFromDSF(const DSFMapIndexPair &dsf, const KeypointsVector &keypoints)
Generate tracks from the DSF.
std::vector< SfmTrack2d > tracksFromPairwiseMatches(const MatchIndicesMap &matches, const KeypointsVector &keypoints, bool verbose)
Creates a list of tracks from 2d point correspondences.
void addMeasurement(size_t idx, const gtsam::Point2 &m)
Add measurement (camera_idx, Point2) to track.
Track containing 2D measurements associated with a single 3D point. Note: Equivalent to gtsam...
std::vector< Keypoints > KeypointsVector
std::map< KEY, Set > sets() const
return all sets, i.e. a partition of all elements