]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/commitdiff
Remove patch_feats from ThreadCtx
authorMichal Sojka <michal.sojka@cvut.cz>
Thu, 13 Sep 2018 22:56:40 +0000 (00:56 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Fri, 14 Sep 2018 07:14:00 +0000 (09:14 +0200)
It does not belong there. Also revert get_features to the original
implementation.

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

index 49348d2d0b6eff1f8ab8a878a53f490e8cece1f5..2eeb40155837ff1d9ab242047d5ce9baa5964f8b 100644 (file)
@@ -209,10 +209,9 @@ void KCF_Tracker::init(cv::Mat &img, const cv::Rect &bbox, int fit_size_x, int f
     DEBUG_PRINTM(p_yf);
 
     // obtain a sub-window for training initial model
-    p_threadctxs.front().patch_feats.clear();
-    get_features(input_rgb, input_gray, p_pose.cx, p_pose.cy, p_windows_size.width, p_windows_size.height,
-                 p_threadctxs.front());
-    fft.forward_window(p_threadctxs.front().patch_feats, p_model_xf, p_threadctxs.front().fw_all,
+    std::vector<cv::Mat> patch_feats = get_features(input_rgb, input_gray, p_pose.cx, p_pose.cy,
+                                                    p_windows_size.width, p_windows_size.height);
+    fft.forward_window(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);
@@ -404,10 +403,10 @@ void KCF_Tracker::track(cv::Mat &img)
 
     ThreadCtx &ctx = p_threadctxs.front();
     // obtain a subwindow for training at newly estimated target position
-    ctx.patch_feats.clear();
-    get_features(input_rgb, input_gray, p_pose.cx, p_pose.cy, p_windows_size.width, p_windows_size.height,
-                 ctx, p_current_scale);
-    fft.forward_window(ctx.patch_feats, p_xf, ctx.fw_all,
+    std::vector<cv::Mat> patch_feats = get_features(input_rgb, input_gray, p_pose.cx, p_pose.cy,
+                                                    p_windows_size.width, p_windows_size.height,
+                                                    p_current_scale);
+    fft.forward_window(patch_feats, p_xf, ctx.fw_all,
                        m_use_cuda ? ctx.data_features.deviceMem() : nullptr, ctx.stream);
 
     // subsequent frames, interpolate model
@@ -445,19 +444,21 @@ void KCF_Tracker::track(cv::Mat &img)
 
 void KCF_Tracker::scale_track(ThreadCtx &vars, cv::Mat &input_rgb, cv::Mat &input_gray)
 {
+    std::vector<cv::Mat> patch_feats;
     if (m_use_big_batch) {
-        vars.patch_feats.clear();
         BIG_BATCH_OMP_PARALLEL_FOR
         for (uint i = 0; i < p_num_scales; ++i) {
-            get_features(input_rgb, input_gray, this->p_pose.cx, this->p_pose.cy, this->p_windows_size.width,
-                         this->p_windows_size.height, vars, this->p_current_scale * this->p_scales[i]);
+            patch_feats = get_features(input_rgb, input_gray, this->p_pose.cx, this->p_pose.cy,
+                                       this->p_windows_size.width, this->p_windows_size.height,
+                                       this->p_current_scale * this->p_scales[i]);
         }
     } else {
-        get_features(input_rgb, input_gray, this->p_pose.cx, this->p_pose.cy, this->p_windows_size.width,
-                     this->p_windows_size.height, vars, this->p_current_scale * vars.scale);
+        patch_feats = get_features(input_rgb, input_gray, this->p_pose.cx, this->p_pose.cy,
+                                   this->p_windows_size.width, this->p_windows_size.height,
+                                   this->p_current_scale * vars.scale);
     }
 
-    fft.forward_window(vars.patch_feats, vars.zf, vars.fw_all, m_use_cuda ? vars.data_features.deviceMem() : nullptr,
+    fft.forward_window(patch_feats, vars.zf, vars.fw_all, m_use_cuda ? vars.data_features.deviceMem() : nullptr,
                        vars.stream);
     DEBUG_PRINTM(vars.zf);
 
@@ -511,8 +512,7 @@ void KCF_Tracker::scale_track(ThreadCtx &vars, cv::Mat &input_rgb, cv::Mat &inpu
 
 // ****************************************************************************
 
-void KCF_Tracker::get_features(cv::Mat &input_rgb, cv::Mat &input_gray, int cx, int cy, int size_x, int size_y,
-                               ThreadCtx &vars, double scale)
+std::vector<cv::Mat> KCF_Tracker::get_features(cv::Mat & input_rgb, cv::Mat & input_gray, int cx, int cy, int size_x, int size_y, double scale)
 {
     int size_x_scaled = floor(size_x * scale);
     int size_y_scaled = floor(size_y * scale);
@@ -529,7 +529,7 @@ void KCF_Tracker::get_features(cv::Mat &input_rgb, cv::Mat &input_gray, int cx,
     }
 
     // get hog(Histogram of Oriented Gradients) features
-    vars.patch_feats = FHoG::extract(patch_gray, 2, p_cell_size, 9);
+    std::vector<cv::Mat> hog_feat = FHoG::extract(patch_gray, 2, p_cell_size, 9);
 
     // get color rgb features (simple r,g,b channels)
     std::vector<cv::Mat> color_feat;
@@ -537,11 +537,9 @@ void KCF_Tracker::get_features(cv::Mat &input_rgb, cv::Mat &input_gray, int cx,
         // resize to default size
         if (scale > 1.) {
             // if we downsample use  INTER_AREA interpolation
-            cv::resize(patch_rgb, patch_rgb, cv::Size(size_x / p_cell_size, size_y / p_cell_size), 0., 0.,
-                       cv::INTER_AREA);
+            cv::resize(patch_rgb, patch_rgb, cv::Size(size_x / p_cell_size, size_y / p_cell_size), 0., 0., cv::INTER_AREA);
         } else {
-            cv::resize(patch_rgb, patch_rgb, cv::Size(size_x / p_cell_size, size_y / p_cell_size), 0., 0.,
-                       cv::INTER_LINEAR);
+            cv::resize(patch_rgb, patch_rgb, cv::Size(size_x / p_cell_size, size_y / p_cell_size), 0., 0., cv::INTER_LINEAR);
         }
     }
 
@@ -561,9 +559,9 @@ void KCF_Tracker::get_features(cv::Mat &input_rgb, cv::Mat &input_gray, int cx,
         std::vector<cv::Mat> cn_feat = CNFeat::extract(patch_rgb);
         color_feat.insert(color_feat.end(), cn_feat.begin(), cn_feat.end());
     }
-    BIG_BATCH_OMP_ORDERED
-    vars.patch_feats.insert(vars.patch_feats.end(), color_feat.begin(), color_feat.end());
-    return;
+
+    hog_feat.insert(hog_feat.end(), color_feat.begin(), color_feat.end());
+    return hog_feat;
 }
 
 cv::Mat KCF_Tracker::gaussian_shaped_labels(double sigma, int dim1, int dim2)
index ec0ab45ff57e2b37f60f2e092e032e8fee3f2d9c..de5e73f91648a6efea269f8ecd373c1940bcb780 100644 (file)
--- a/src/kcf.h
+++ b/src/kcf.h
@@ -151,7 +151,7 @@ private:
     void gaussian_correlation(struct ThreadCtx &vars, const ComplexMat & xf, const ComplexMat & yf, double sigma, bool auto_correlation = false);
     cv::Mat circshift(const cv::Mat & patch, int x_rot, int y_rot);
     cv::Mat cosine_window_function(int dim1, int dim2);
-    void get_features(cv::Mat & input_rgb, cv::Mat & input_gray, int cx, int cy, int size_x, int size_y, ThreadCtx & vars, double scale = 1.);
+    std::vector<cv::Mat> get_features(cv::Mat & input_rgb, cv::Mat & input_gray, int cx, int cy, int size_x, int size_y, double scale = 1.);
     cv::Point2f sub_pixel_peak(cv::Point & max_loc, cv::Mat & response);
     double sub_grid_scale(uint index);
 
index 62aebec1b459775aaa8d87c6e0d6d0f4fd4f7afb..5395ae7b7c7933078e91b61796cf1ab3c270555a 100644 (file)
@@ -21,7 +21,6 @@ struct ThreadCtx {
     {
         this->xf_sqr_norm = DynMem(num_of_scales * sizeof(float));
         this->yf_sqr_norm = DynMem(sizeof(float));
-        this->patch_feats.reserve(uint(num_of_feats));
 
         uint cells_size = roi.width * roi.height * sizeof(float);
 
@@ -49,8 +48,6 @@ struct ThreadCtx {
         this->ifft2_res = cv::Mat(roi, CV_32FC(num_of_feats), this->data_i_features.hostMem());
         this->response = cv::Mat(roi, CV_32FC(num_of_scales), this->data_i_1ch.hostMem());
 
-        this->patch_feats.reserve(num_of_feats);
-
 #ifdef CUFFT
         this->zf.create(roi.height, width_freq, num_of_feats, num_of_scales, this->stream);
         this->kzf.create(roi.height, width_freq, num_of_scales, this->stream);
@@ -81,7 +78,6 @@ struct ThreadCtx {
 #endif
 
     DynMem xf_sqr_norm, yf_sqr_norm;
-    std::vector<cv::Mat> patch_feats;
 
     cv::Mat in_all, fw_all, ifft2_res, response;
     ComplexMat zf, kzf, kf, xyf;