]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/commitdiff
Added comments to variables in ThreadCtx + renamed p_scale_vars in kcf
authorShanigen <vkaraf@gmail.com>
Sun, 9 Sep 2018 04:33:44 +0000 (06:33 +0200)
committerShanigen <vkaraf@gmail.com>
Sun, 9 Sep 2018 04:33:44 +0000 (06:33 +0200)
This commit adresses issue #11.

src/kcf.cpp
src/kcf.h
src/threadctx.hpp

index 52f97d40b61e3354ebb2b1f6d4b1caeeb8d24354..20e3db15a8515c7d4f59273114cbafc1f56b0978 100644 (file)
@@ -180,10 +180,10 @@ void KCF_Tracker::init(cv::Mat &img, const cv::Rect &bbox, int fit_size_x, int f
     int max = m_use_big_batch ? 2 : p_num_scales;
     for (int i = 0; i < max; ++i) {
         if (m_use_big_batch && i == 1) {
-            p_scale_vars.emplace_back(
+            p_threadctxs.emplace_back(
                 new ThreadCtx(p_windows_size, p_cell_size, p_num_of_feats * p_num_scales, p_num_scales));
         } else {
-            p_scale_vars.emplace_back(new ThreadCtx(p_windows_size, p_cell_size, p_num_of_feats, 1));
+            p_threadctxs.emplace_back(new ThreadCtx(p_windows_size, p_cell_size, p_num_of_feats, 1));
         }
     }
 
@@ -209,15 +209,15 @@ void KCF_Tracker::init(cv::Mat &img, const cv::Rect &bbox, int fit_size_x, int f
     // window weights, i.e. labels
     fft.forward(
         gaussian_shaped_labels(p_output_sigma, p_windows_size.width / p_cell_size, p_windows_size.height / p_cell_size), p_yf,
-        m_use_cuda ? p_rot_labels_data.deviceMem() : nullptr, p_scale_vars.front()->stream);
+        m_use_cuda ? p_rot_labels_data.deviceMem() : nullptr, p_threadctxs.front()->stream);
     DEBUG_PRINTM(p_yf);
 
     // obtain a sub-window for training initial model
-    p_scale_vars.front()->patch_feats.clear();
+    p_threadctxs.front()->patch_feats.clear();
     get_features(input_rgb, input_gray, int(p_pose.cx), int(p_pose.cy), p_windows_size.width, p_windows_size.height,
-                 *p_scale_vars.front());
-    fft.forward_window(p_scale_vars.front()->patch_feats, p_model_xf, p_scale_vars.front()->fw_all,
-                       m_use_cuda ? p_scale_vars.front()->data_features.deviceMem() : nullptr, p_scale_vars.front()->stream);
+                 *p_threadctxs.front());
+    fft.forward_window(p_threadctxs.front()->patch_feats, p_model_xf, p_threadctxs.front()->fw_all,
+                       m_use_cuda ? p_threadctxs.front()->data_features.deviceMem() : nullptr, p_threadctxs.front()->stream);
     DEBUG_PRINTM(p_model_xf);
 #if !defined(BIG_BATCH) && defined(CUFFT) && (defined(ASYNC) || defined(OPENMP))
     p_scale_vars.front()->model_xf = p_model_xf;
@@ -237,12 +237,12 @@ void KCF_Tracker::init(cv::Mat &img, const cv::Rect &bbox, int fit_size_x, int f
         gaussian_correlation(*p_scale_vars.front(), p_scale_vars.front()->model_xf, p_scale_vars.front()->model_xf,
                              p_kernel_sigma, true);
 #else
-        gaussian_correlation(*p_scale_vars.front(), p_model_xf, p_model_xf, p_kernel_sigma, true);
+        gaussian_correlation(*p_threadctxs.front(), p_model_xf, p_model_xf, p_kernel_sigma, true);
 #endif
-        DEBUG_PRINTM(p_scale_vars.front()->kf);
-        p_model_alphaf_num = p_yf * p_scale_vars.front()->kf;
+        DEBUG_PRINTM(p_threadctxs.front()->kf);
+        p_model_alphaf_num = p_yf * p_threadctxs.front()->kf;
         DEBUG_PRINTM(p_model_alphaf_num);
-        p_model_alphaf_den = p_scale_vars.front()->kf * (p_scale_vars.front()->kf + float(p_lambda));
+        p_model_alphaf_den = p_threadctxs.front()->kf * (p_threadctxs.front()->kf + float(p_lambda));
         DEBUG_PRINTM(p_model_alphaf_den);
     }
     p_model_alphaf = p_model_alphaf_num / p_model_alphaf_den;
@@ -330,14 +330,14 @@ void KCF_Tracker::track(cv::Mat &img)
 
     if (m_use_multithreading) {
         std::vector<std::future<void>> async_res(p_scales.size());
-        for (auto it = p_scale_vars.begin(); it != p_scale_vars.end(); ++it) {
-            uint index = uint(std::distance(p_scale_vars.begin(), it));
+        for (auto it = p_threadctxs.begin(); it != p_threadctxs.end(); ++it) {
+            uint index = uint(std::distance(p_threadctxs.begin(), it));
             async_res[index] = std::async(std::launch::async, [this, &input_gray, &input_rgb, index, it]() -> void {
                 return scale_track(*(*it), input_rgb, input_gray, this->p_scales[index]);
             });
         }
-        for (auto it = p_scale_vars.begin(); it != p_scale_vars.end(); ++it) {
-            uint index = uint(std::distance(p_scale_vars.begin(), it));
+        for (auto it = p_threadctxs.begin(); it != p_threadctxs.end(); ++it) {
+            uint index = uint(std::distance(p_threadctxs.begin(), it));
             async_res[index].wait();
             if ((*it)->max_response > max_response) {
                 max_response = (*it)->max_response;
@@ -351,7 +351,7 @@ void KCF_Tracker::track(cv::Mat &img)
         uint end = m_use_big_batch ? 2 : uint(p_num_scales);
         NORMAL_OMP_PARALLEL_FOR
         for (uint i = start; i < end; ++i) {
-            auto it = p_scale_vars.begin();
+            auto it = p_threadctxs.begin();
             std::advance(it, i);
             scale_track(*(*it), input_rgb, input_gray, this->p_scales[i]);
 
@@ -417,11 +417,11 @@ void KCF_Tracker::track(cv::Mat &img)
     if (p_current_scale > p_min_max_scale[1]) p_current_scale = p_min_max_scale[1];
 
     // obtain a subwindow for training at newly estimated target position
-    p_scale_vars.front()->patch_feats.clear();
+    p_threadctxs.front()->patch_feats.clear();
     get_features(input_rgb, input_gray, int(p_pose.cx), int(p_pose.cy), p_windows_size.width, p_windows_size.height,
-                 *p_scale_vars.front(), p_current_scale);
-    fft.forward_window(p_scale_vars.front()->patch_feats, p_xf, p_scale_vars.front()->fw_all,
-                       m_use_cuda ? p_scale_vars.front()->data_features.deviceMem() : nullptr, p_scale_vars.front()->stream);
+                 *p_threadctxs.front(), p_current_scale);
+    fft.forward_window(p_threadctxs.front()->patch_feats, p_xf, p_threadctxs.front()->fw_all,
+                       m_use_cuda ? p_threadctxs.front()->data_features.deviceMem() : nullptr, p_threadctxs.front()->stream);
 
     // subsequent frames, interpolate model
     p_model_xf = p_model_xf * float((1. - p_interp_factor)) + p_xf * float(p_interp_factor);
@@ -434,12 +434,12 @@ void KCF_Tracker::track(cv::Mat &img)
         alphaf_den = (p_xf * xfconj);
     } else {
         // Kernel Ridge Regression, calculate alphas (in Fourier domain)
-        gaussian_correlation(*p_scale_vars.front(), p_xf, p_xf, p_kernel_sigma,
+        gaussian_correlation(*p_threadctxs.front(), p_xf, p_xf, p_kernel_sigma,
                              true);
         //        ComplexMat alphaf = p_yf / (kf + p_lambda); //equation for fast training
         //        p_model_alphaf = p_model_alphaf * (1. - p_interp_factor) + alphaf * p_interp_factor;
-        alphaf_num = p_yf * p_scale_vars.front()->kf;
-        alphaf_den = p_scale_vars.front()->kf * (p_scale_vars.front()->kf + float(p_lambda));
+        alphaf_num = p_yf * p_threadctxs.front()->kf;
+        alphaf_den = p_threadctxs.front()->kf * (p_threadctxs.front()->kf + float(p_lambda));
     }
 
     p_model_alphaf_num = p_model_alphaf_num * float((1. - p_interp_factor)) + alphaf_num * float(p_interp_factor);
@@ -881,14 +881,14 @@ double KCF_Tracker::sub_grid_scale(int index)
         // fit 1d quadratic function f(x) = a*x^2 + b*x + c
         A.create(int(p_scales.size()), 3, CV_32FC1);
         fval.create(int(p_scales.size()), 1, CV_32FC1);
-        for (auto it = p_scale_vars.begin(); it != p_scale_vars.end(); ++it) {
-            uint i = uint(std::distance(p_scale_vars.begin(), it));
+        for (auto it = p_threadctxs.begin(); it != p_threadctxs.end(); ++it) {
+            uint i = uint(std::distance(p_threadctxs.begin(), it));
             int j = int(i);
             A.at<float>(j, 0) = float(p_scales[i] * p_scales[i]);
             A.at<float>(j, 1) = float(p_scales[i]);
             A.at<float>(j, 2) = 1;
             fval.at<float>(j) =
-                m_use_big_batch ? float(p_scale_vars.back()->max_responses[i]) : float((*it)->max_response);
+                m_use_big_batch ? float(p_threadctxs.back()->max_responses[i]) : float((*it)->max_response);
         }
     } else {
         // only from neighbours
@@ -897,16 +897,16 @@ double KCF_Tracker::sub_grid_scale(int index)
         A = (cv::Mat_<float>(3, 3) << p_scales[uint(index) - 1] * p_scales[uint(index) - 1], p_scales[uint(index) - 1],
              1, p_scales[uint(index)] * p_scales[uint(index)], p_scales[uint(index)], 1,
              p_scales[uint(index) + 1] * p_scales[uint(index) + 1], p_scales[uint(index) + 1], 1);
-        auto it1 = p_scale_vars.begin();
+        auto it1 = p_threadctxs.begin();
         std::advance(it1, index - 1);
-        auto it2 = p_scale_vars.begin();
+        auto it2 = p_threadctxs.begin();
         std::advance(it2, index);
-        auto it3 = p_scale_vars.begin();
+        auto it3 = p_threadctxs.begin();
         std::advance(it3, index + 1);
-        fval = (cv::Mat_<float>(3, 1) << (m_use_big_batch ? p_scale_vars.back()->max_responses[uint(index) - 1]
+        fval = (cv::Mat_<float>(3, 1) << (m_use_big_batch ? p_threadctxs.back()->max_responses[uint(index) - 1]
                                                           : (*it1)->max_response),
-                (m_use_big_batch ? p_scale_vars.back()->max_responses[uint(index)] : (*it2)->max_response),
-                (m_use_big_batch ? p_scale_vars.back()->max_responses[uint(index) + 1] : (*it3)->max_response));
+                (m_use_big_batch ? p_threadctxs.back()->max_responses[uint(index)] : (*it2)->max_response),
+                (m_use_big_batch ? p_threadctxs.back()->max_responses[uint(index) + 1] : (*it3)->max_response));
     }
 
     cv::Mat x;
index 9bbd94af370009995299de85c72465267aad1e11..a6bb78e0462195bfbd925a4f6ed1c2bf7224a2fa 100644 (file)
--- a/src/kcf.h
+++ b/src/kcf.h
@@ -130,7 +130,7 @@ private:
     int p_num_of_feats;
     int p_roi_height, p_roi_width;
 
-    std::list<std::unique_ptr<ThreadCtx>> p_scale_vars;
+    std::list<std::unique_ptr<ThreadCtx>> p_threadctxs;
 
     //CUDA compability
     cv::Mat p_rot_labels;
index bf9963459e288f7651c2122782fc4d3bd6613b5a..0e172c91460e376681c0007eedde5fd9cfa6717a 100644 (file)
@@ -94,10 +94,12 @@ struct ThreadCtx {
     cudaStream_t stream = nullptr;
     ComplexMat model_alphaf, model_xf;
 
-    // Big batch variables
+    // Variables used during non big batch mode and in big batch mode with ThreadCtx in p_threadctxs in kcf  on zero index.
     cv::Point2i max_loc;
     double max_val, max_response;
 
+    // Big batch variables
+    // Stores value of responses, location of maximal response and response maps for each scale
     std::vector<double> max_responses;
     std::vector<cv::Point2i> max_locs;
     std::vector<cv::Mat> response_maps;