]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blobdiff - src/kcf.h
Extend to support not only multiple scales but also multiple angles
[hercules2020/kcf.git] / src / kcf.h
index 10b189a678c27a9b87d5950b59a0a1a7602ef704..76abc5ea4ea48989f9dcfe7693268b857bc43d7b 100644 (file)
--- a/src/kcf.h
+++ b/src/kcf.h
@@ -6,13 +6,10 @@
 #include <memory>
 #include "fhog.hpp"
 
+#include "complexmat.hpp"
 #ifdef CUFFT
-#include "complexmat.cuh"
-#include "cuda_functions.cuh"
 #include "cuda_error_check.hpp"
 #include <cuda_runtime.h>
-#else
-#include "complexmat.hpp"
 #endif
 
 #include "cnfeat.hpp"
@@ -24,7 +21,7 @@ struct ThreadCtx;
 
 struct BBox_c
 {
-    double cx, cy, w, h;
+    double cx, cy, w, h, a;
 
     inline cv::Point2d center() const { return cv::Point2d(cx, cy); }
 
@@ -46,6 +43,7 @@ struct BBox_c
 class KCF_Tracker
 {
     friend ThreadCtx;
+    friend Kcf_Tracker_Private;
 public:
     bool m_debug {false};
     bool m_visual_debug {false};
@@ -89,6 +87,7 @@ private:
     // Information to calculate current pose of the tracked object
     cv::Point2d p_current_center;
     double p_current_scale = 1.;
+    double p_current_angle = 0.;
 
     double max_response = -1.;
 
@@ -113,14 +112,15 @@ private:
 
     const uint p_num_angles = 1;
     const int p_angle_step = 10;
-    std::vector<double> p_angles = {0};
+    std::vector<double> p_angles;
 
     const int p_num_of_feats = 31 + (m_use_color ? 3 : 0) + (m_use_cnfeat ? 10 : 0);
     cv::Size feature_size;
 
-    Kcf_Tracker_Private &d;
+    std::unique_ptr<Kcf_Tracker_Private> d;
 
     class Model {
+        cv::Size feature_size;
         uint height, width, n_feats;
     public:
         ComplexMat yf {height, width, 1};
@@ -130,7 +130,17 @@ private:
         ComplexMat model_xf {height, width, n_feats};
         ComplexMat xf {height, width, n_feats};
 
-        Model(cv::Size freq_size, uint _n_feats) : height(freq_size.height), width(freq_size.width), n_feats(_n_feats) {}
+        // Temporary variables for trainig
+        MatScaleFeats patch_feats{1, n_feats, feature_size};
+        MatScaleFeats temp{1, n_feats, feature_size};
+
+
+
+        Model(cv::Size feature_size, uint _n_feats)
+            : feature_size(feature_size)
+            , height(Fft::freq_size(feature_size).height)
+            , width(Fft::freq_size(feature_size).width)
+            , n_feats(_n_feats) {}
     };
 
     std::unique_ptr<Model> model;
@@ -153,15 +163,14 @@ private:
         MatScales k;
     };
 
-
     //helping functions
     void scale_track(ThreadCtx &vars, cv::Mat &input_rgb, cv::Mat &input_gray);
-    cv::Mat get_subwindow(const cv::Mat &input, int cx, int cy, int size_x, int size_y) const;
+    cv::Mat get_subwindow(const cv::Mat &input, int cx, int cy, int size_x, int size_y, double angle) const;
     cv::Mat gaussian_shaped_labels(double sigma, int dim1, int dim2);
     std::unique_ptr<GaussianCorrelation> gaussian_correlation;
     cv::Mat circshift(const cv::Mat &patch, int x_rot, int y_rot) const;
     cv::Mat cosine_window_function(int dim1, int dim2);
-    cv::Mat get_features(cv::Mat &input_rgb, cv::Mat &input_gray, int cx, int cy, int size_x, int size_y, double scale) const;
+    cv::Mat get_features(cv::Mat &input_rgb, cv::Mat &input_gray, cv::Mat *dbg_patch, int cx, int cy, int size_x, int size_y, double scale, double angle) const;
     cv::Point2f sub_pixel_peak(cv::Point &max_loc, cv::Mat &response) const;
     double sub_grid_scale(uint index);
     void resizeImgs(cv::Mat &input_rgb, cv::Mat &input_gray);