]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blob - src/kcf.h
Removed obsolete variable
[hercules2020/kcf.git] / src / kcf.h
1 #ifndef KCF_HEADER_6565467831231
2 #define KCF_HEADER_6565467831231
3
4 #include <opencv2/opencv.hpp>
5 #include <vector>
6 #include "fhog.hpp"
7
8 #ifdef CUFFT
9   #include "complexmat.cuh"
10   #include "cuda_functions.cuh"
11   #include "cuda/cuda_error_check.cuh"
12   #include <cuda_runtime.h>
13 #else
14   #include "complexmat.hpp"
15 #endif
16
17 #include "cnfeat.hpp"
18 #include "fft.h"
19 #include "scale_vars.hpp"
20
21 struct BBox_c
22 {
23     double cx, cy, w, h;
24
25     inline void scale(double factor)
26     {
27         cx *= factor;
28         cy *= factor;
29         w  *= factor;
30         h  *= factor;
31     }
32
33     inline void scale_x(double factor)
34     {
35         cx *= factor;
36         w  *= factor;
37     }
38
39     inline void scale_y(double factor)
40     {
41         cy *= factor;
42         h  *= factor;
43     }
44
45     inline cv::Rect get_rect()
46     {
47         return cv::Rect(cx-w/2., cy-h/2., w, h);
48     }
49
50 };
51
52 class KCF_Tracker
53 {
54 public:
55     bool m_debug     {false};
56     bool m_use_scale {true};
57     bool m_use_color {true};
58 #ifdef ASYNC
59     bool m_use_multithreading {true};
60 #else
61     bool m_use_multithreading {false};
62 #endif //ASYNC
63     bool m_use_subpixel_localization {true};
64     bool m_use_subgrid_scale {true};
65     bool m_use_cnfeat {true};
66     bool m_use_linearkernel {false};
67 #ifdef BIG_BATCH
68     bool m_use_big_batch {true};
69 #else
70     bool m_use_big_batch {false};
71 #endif
72
73     /*
74     padding             ... extra area surrounding the target           (1.5)
75     kernel_sigma        ... gaussian kernel bandwidth                   (0.5)
76     lambda              ... regularization                              (1e-4)
77     interp_factor       ... linear interpolation factor for adaptation  (0.02)
78     output_sigma_factor ... spatial bandwidth (proportional to target)  (0.1)
79     cell_size           ... hog cell size                               (4)
80     */
81     KCF_Tracker(double padding, double kernel_sigma, double lambda, double interp_factor, double output_sigma_factor, int cell_size);
82     KCF_Tracker();
83     ~KCF_Tracker();
84
85     // Init/re-init methods
86     void init(cv::Mat & img, const cv::Rect & bbox, int fit_size_x, int fit_size_y);
87     void init_scale_vars();
88     void setTrackerPose(BBox_c & bbox, cv::Mat & img, int fit_size_x, int fit_size_y);
89     void updateTrackerPosition(BBox_c & bbox);
90
91     // frame-to-frame object tracking
92     void track(cv::Mat & img);
93     BBox_c getBBox();
94
95 private:
96     Fft &fft;
97
98     BBox_c p_pose;
99     bool p_resize_image = false;
100     bool p_fit_to_pw2 = false;
101
102     bool first = true;
103
104     const double p_downscale_factor = 0.5;
105     double p_scale_factor_x = 1;
106     double p_scale_factor_y = 1;
107
108     double p_padding = 1.5;
109     double p_output_sigma_factor = 0.1;
110     double p_output_sigma;
111     double p_kernel_sigma = 0.5;    //def = 0.5
112     double p_lambda = 1e-4;         //regularization in learning step
113     double p_interp_factor = 0.02;  //def = 0.02, linear interpolation factor for adaptation
114     int p_cell_size = 4;            //4 for hog (= bin_size)
115     int p_windows_size[2];
116     int p_num_scales {7};
117     double p_scale_step = 1.02;
118     double p_current_scale = 1.;
119     double p_min_max_scale[2];
120     std::vector<double> p_scales;
121
122     //for big batch
123     int p_num_of_feats;
124     int p_roi_height, p_roi_width;
125
126     std::vector<Scale_vars> scale_vars;
127
128     //model
129     ComplexMat p_yf;
130     ComplexMat p_model_alphaf;
131     ComplexMat p_model_alphaf_num;
132     ComplexMat p_model_alphaf_den;
133     ComplexMat p_model_xf;
134     //helping functions
135     void scale_track(Scale_vars & vars, cv::Mat & input_rgb, cv::Mat & input_gray, double scale);
136     cv::Mat get_subwindow(const cv::Mat & input, int cx, int cy, int size_x, int size_y);
137     void gaussian_shaped_labels(Scale_vars & vars, double sigma, int dim1, int dim2);
138     void gaussian_correlation(struct Scale_vars &vars, const ComplexMat & xf, const ComplexMat & yf, double sigma, bool auto_correlation = false);
139     cv::Mat circshift(const cv::Mat & patch, int x_rot, int y_rot);
140     cv::Mat cosine_window_function(int dim1, int dim2);
141     void get_features(cv::Mat & input_rgb, cv::Mat & input_gray, int cx, int cy, int size_x, int size_y, Scale_vars & vars, double scale = 1.);
142     cv::Point2f sub_pixel_peak(cv::Point & max_loc, cv::Mat & response);
143     double sub_grid_scale(int index = -1);
144
145 };
146
147 #endif //KCF_HEADER_6565467831231