]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blobdiff - src/kcf.h
Integration of the visual debug, with zero changes to the tracker's API.
[hercules2020/kcf.git] / src / kcf.h
index 2e02be6f3044d55a7c5f3cb0991a28e5054a2d64..4ca1066e033efeb732bb65b0de476f2df43d6338 100644 (file)
--- a/src/kcf.h
+++ b/src/kcf.h
@@ -9,7 +9,7 @@
 #ifdef CUFFT
 #include "complexmat.cuh"
 #include "cuda_functions.cuh"
-#include "cuda/cuda_error_check.cuh"
+#include "cuda_error_check.hpp"
 #include <cuda_runtime.h>
 #else
 #include "complexmat.hpp"
@@ -26,6 +26,8 @@ struct BBox_c
 {
     double cx, cy, w, h;
 
+    inline cv::Point2d center() const { return cv::Point2d(cx, cy); }
+
     inline void scale(double factor)
     {
         cx *= factor;
@@ -57,13 +59,15 @@ class KCF_Tracker
 {
     friend ThreadCtx;
 public:
-    bool m_debug     {false};
-    bool m_use_scale {true};
-    bool m_use_color {true};
-    bool m_use_subpixel_localization {true};
-    bool m_use_subgrid_scale {true};
-    bool m_use_cnfeat {true};
-    bool m_use_linearkernel {false};
+    bool m_debug {false};
+    bool m_visual_debug {false};
+    const bool m_use_scale {true};
+    const bool m_use_color {true};
+    const bool m_use_subpixel_localization {true};
+    const bool m_use_subgrid_scale {true};
+    const bool m_use_cnfeat {true};
+    const bool m_use_linearkernel {false};
+    const int p_cell_size = 4;            //4 for hog (= bin_size)
 
     /*
     padding             ... extra area surrounding the target           (1.5)
@@ -78,8 +82,8 @@ public:
     ~KCF_Tracker();
 
     // Init/re-init methods
-    void init(cv::Mat & img, const cv::Rect & bbox, int fit_size_x, int fit_size_y);
-    void setTrackerPose(BBox_c & bbox, cv::Mat & img, int fit_size_x, int fit_size_y);
+    void init(cv::Mat & img, const cv::Rect & bbox, int fit_size_x = -1, int fit_size_y = -1);
+    void setTrackerPose(BBox_c & bbox, cv::Mat & img, int fit_size_x = -1, int fit_size_y = -1);
     void updateTrackerPosition(BBox_c & bbox);
 
     // frame-to-frame object tracking
@@ -90,33 +94,43 @@ public:
 private:
     Fft &fft;
 
-    BBox_c p_pose;
+    // Initial pose of tracked object in internal image coordinates
+    // (scaled by p_downscale_factor if p_resize_image)
+    BBox_c p_init_pose;
+
+    // Information to calculate current pose of the tracked object
+    cv::Point2d p_current_center;
+    double p_current_scale = 1.;
+
     double max_response = -1.;
 
     bool p_resize_image = false;
     bool p_fit_to_pw2 = false;
 
     const double p_downscale_factor = 0.5;
-    double p_scale_factor_x = 1;
-    double p_scale_factor_y = 1;
+    double p_fit_factor_x = 1;
+    double p_fit_factor_y = 1;
     const double p_floating_error = 0.0001;
 
-    double p_padding = 1.5;
-    double p_output_sigma_factor = 0.1;
+    const double p_padding = 1.5;
+    const double p_output_sigma_factor = 0.1;
     double p_output_sigma;
-    double p_kernel_sigma = 0.5;    //def = 0.5
-    double p_lambda = 1e-4;         //regularization in learning step
-    double p_interp_factor = 0.02;  //def = 0.02, linear interpolation factor for adaptation
-    int p_cell_size = 4;            //4 for hog (= bin_size)
+    const double p_kernel_sigma = 0.5;    //def = 0.5
+    const double p_lambda = 1e-4;         //regularization in learning step
+    const double p_interp_factor = 0.02;  //def = 0.02, linear interpolation factor for adaptation
     cv::Size p_windows_size;
-    uint p_num_scales {7};
-    double p_scale_step = 1.02;
-    double p_current_scale = 1.;
+
+    const uint p_num_scales = m_use_scale ? 7 : 1;
+    const double p_scale_step = 1.02;
     double p_min_max_scale[2];
     std::vector<double> p_scales;
 
+    const uint p_num_angles = 1;
+    const int p_angle_step = 10;
+    std::vector<double> p_angles = {0};
+
     const int p_num_of_feats = 31 + (m_use_color ? 3 : 0) + (m_use_cnfeat ? 10 : 0);
-    cv::Size p_roi;
+    cv::Size feature_size;
 
     Kcf_Tracker_Private &d;
 
@@ -132,11 +146,11 @@ private:
       public:
         GaussianCorrelation(uint num_scales, cv::Size size)
             : xf_sqr_norm(num_scales)
-            , xyf(Fft::freq_size(size), num_scales)
+            , xyf(Fft::freq_size(size), 1, num_scales)
             , ifft_res(num_scales, size)
             , k(num_scales, size)
         {}
-        void operator()(const KCF_Tracker &kcf, ComplexMat &result, const ComplexMat &xf, const ComplexMat &yf, double sigma, bool auto_correlation = false);
+        void operator()(ComplexMat &result, const ComplexMat &xf, const ComplexMat &yf, double sigma, bool auto_correlation, const KCF_Tracker &kcf);
 
       private:
         DynMem xf_sqr_norm;
@@ -157,8 +171,8 @@ private:
     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);
-    void train(cv::Mat input_gray, cv::Mat input_rgb, double interp_factor);
-    void findMaxReponse(uint &max_idx, cv::Point2f &new_location) const;
+    void train(cv::Mat input_rgb, cv::Mat input_gray, double interp_factor);
+    double findMaxReponse(uint &max_idx, cv::Point2d &new_location) const;
 };
 
 #endif //KCF_HEADER_6565467831231