From ca0285cc18e55bdafeaeaaf592a39e45c5756280 Mon Sep 17 00:00:00 2001 From: Matej Petrlik Date: Tue, 2 Apr 2024 17:41:17 +0200 Subject: [PATCH] added getter for the number of tracked features --- ov_core/src/track/TrackBase.cpp | 21 ++++++++++++++++++++- ov_core/src/track/TrackBase.h | 2 ++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ov_core/src/track/TrackBase.cpp b/ov_core/src/track/TrackBase.cpp index e214c233f..f2fd427ce 100644 --- a/ov_core/src/track/TrackBase.cpp +++ b/ov_core/src/track/TrackBase.cpp @@ -116,6 +116,25 @@ void TrackBase::display_active(cv::Mat &img_out, int r1, int g1, int b1, int r2, } } +size_t TrackBase::get_num_tracks() { + + std::map img_last_cache; + std::unordered_map> ids_last_cache; + { + std::lock_guard lckv(mtx_last_vars); + img_last_cache = img_last; + ids_last_cache = ids_last; + } + + size_t num_tracks = 0; + + for (auto const &pair : img_last_cache) { + num_tracks += ids_last_cache[pair.first].size(); + } + + return num_tracks; +} + void TrackBase::display_history(cv::Mat &img_out, int r1, int g1, int b1, int r2, int g2, int b2, std::vector highlighted, std::string overlay) { @@ -245,4 +264,4 @@ void TrackBase::change_feat_id(size_t id_old, size_t id_new) { } } } -} \ No newline at end of file +} diff --git a/ov_core/src/track/TrackBase.h b/ov_core/src/track/TrackBase.h index e0afee1d9..53aea3900 100644 --- a/ov_core/src/track/TrackBase.h +++ b/ov_core/src/track/TrackBase.h @@ -105,6 +105,8 @@ class TrackBase { */ virtual void display_active(cv::Mat &img_out, int r1, int g1, int b1, int r2, int g2, int b2, std::string overlay = ""); + + size_t get_num_tracks(); /** * @brief Shows a "trail" for each feature (i.e. its history) * @param img_out image to which we will overlayed features on