]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blob - src/kcf.h
Work I have done so far
[hercules2020/kcf.git] / src / kcf.h
1 #ifndef KCF_HEADER_6565467831231
2 #define KCF_HEADER_6565467831231
3
4 //TODO workout the includes
5 #include <opencv2/opencv.hpp>
6 #include <vector>
7 #include </usr/local/cuda-8.0/targets/aarch64-linux/include/cuda.h>
8 #include </usr/local/cuda-8.0/targets/aarch64-linux/include/cuda_runtime.h>
9 #include "fhog.hpp"
10 #include "complexmat.hpp"
11 #include "cnfeat.hpp"
12
13 struct BBox_c
14 {
15     double cx, cy, w, h;
16
17     inline void scale(double factor)
18     {
19         cx *= factor;
20         cy *= factor;
21         w  *= factor;
22         h  *= factor;
23     }
24
25     inline cv::Rect get_rect()
26     {
27         return cv::Rect(cx-w/2., cy-h/2., w, h);
28     }
29
30 };
31
32 class KCF_Tracker
33 {
34 public:
35     bool m_use_scale {false};//true
36     bool m_use_color {false};//true
37     bool m_use_subpixel_localization {true};
38     bool m_use_subgrid_scale {true};
39     bool m_use_multithreading {true};
40     bool m_use_cnfeat {true};
41     bool m_use_linearkernel {false};
42
43     /*
44     padding             ... extra area surrounding the target           (1.5)
45     kernel_sigma        ... gaussian kernel bandwidth                   (0.5)
46     lambda              ... regularization                              (1e-4)
47     interp_factor       ... linear interpolation factor for adaptation  (0.02)
48     output_sigma_factor ... spatial bandwidth (proportional to target)  (0.1)
49     cell_size           ... hog cell size                               (4)
50     */
51     KCF_Tracker(double padding, double kernel_sigma, double lambda, double interp_factor, double output_sigma_factor, int cell_size) :
52         p_padding(padding), p_output_sigma_factor(output_sigma_factor), p_kernel_sigma(kernel_sigma),
53         p_lambda(lambda), p_interp_factor(interp_factor), p_cell_size(cell_size) {}
54     KCF_Tracker() {}
55
56     // Init/re-init methods
57     void init(cv::Mat & img, const cv::Rect & bbox);
58     void setTrackerPose(BBox_c & bbox, cv::Mat & img);
59     void updateTrackerPosition(BBox_c & bbox);
60
61     // frame-to-frame object tracking
62     void track(cv::Mat & img);
63     BBox_c getBBox();
64
65 private:
66     BBox_c p_pose;
67     bool p_resize_image = false;
68     
69     bool first = true;
70     cv::cuda::Stream stream;
71
72     double p_padding = 1.5;
73     double p_output_sigma_factor = 0.1;
74     double p_output_sigma;
75     double p_kernel_sigma = 0.5;    //def = 0.5
76     double p_lambda = 1e-4;         //regularization in learning step
77     double p_interp_factor = 0.02;  //def = 0.02, linear interpolation factor for adaptation
78     int p_cell_size = 4;            //4 for hog (= bin_size)
79     int p_windows_size[2];
80     cv::Mat p_cos_window;
81     int p_num_scales {7};
82     double p_scale_step = 1.02;
83     double p_current_scale = 1.;
84     double p_min_max_scale[2];
85     std::vector<double> p_scales;
86      cv::cuda::GpuMat src_gpu,dst_gpu,p_cos_window_gpu;
87
88     //model
89     ComplexMat p_yf;
90     ComplexMat p_model_alphaf;
91     ComplexMat p_model_alphaf_num;
92     ComplexMat p_model_alphaf_den;
93     ComplexMat p_model_xf;
94
95     //helping functions
96     cv::Mat get_subwindow(const cv::Mat & input, int cx, int cy, int size_x, int size_y);
97     cv::Mat gaussian_shaped_labels(double sigma, int dim1, int dim2);
98     ComplexMat gaussian_correlation(const ComplexMat & xf, const ComplexMat & yf, double sigma, bool auto_correlation = false);
99     cv::Mat circshift(const cv::Mat & patch, int x_rot, int y_rot);
100     cv::Mat cosine_window_function(int dim1, int dim2);
101     ComplexMat fft2(const cv::Mat & input);
102     ComplexMat fft2(const std::vector<cv::Mat> & input, const cv::Mat & cos_window);
103     cv::Mat ifft2(const ComplexMat & inputf);
104     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.);
105     cv::Point2f sub_pixel_peak(cv::Point & max_loc, cv::Mat & response);
106     double sub_grid_scale(std::vector<double> & responses, int index = -1);
107
108 };
109
110 #endif //KCF_HEADER_6565467831231