1 #ifndef KCF_HEADER_6565467831231
2 #define KCF_HEADER_6565467831231
4 #include <opencv2/opencv.hpp>
10 #include "complexmat.cuh"
11 #include "cuda_functions.cuh"
12 #include "cuda_error_check.hpp"
13 #include <cuda_runtime.h>
15 #include "complexmat.hpp"
22 class Kcf_Tracker_Private;
29 inline cv::Point2d center() const { return cv::Point2d(cx, cy); }
31 inline void scale(double factor)
39 inline cv::Rect get_rect()
41 return cv::Rect(int(cx-w/2.), int(cy-h/2.), int(w), int(h));
51 const bool m_use_scale {true};
52 const bool m_use_color {true};
53 const bool m_use_subpixel_localization {true};
54 const bool m_use_subgrid_scale {true};
55 const bool m_use_cnfeat {true};
56 const bool m_use_linearkernel {false};
57 const int p_cell_size = 4; //4 for hog (= bin_size)
60 padding ... extra area surrounding the target (1.5)
61 kernel_sigma ... gaussian kernel bandwidth (0.5)
62 lambda ... regularization (1e-4)
63 interp_factor ... linear interpolation factor for adaptation (0.02)
64 output_sigma_factor ... spatial bandwidth (proportional to target) (0.1)
65 cell_size ... hog cell size (4)
67 KCF_Tracker(double padding, double kernel_sigma, double lambda, double interp_factor, double output_sigma_factor, int cell_size);
71 // Init/re-init methods
72 void init(cv::Mat & img, const cv::Rect & bbox, int fit_size_x = -1, int fit_size_y = -1);
73 void setTrackerPose(BBox_c & bbox, cv::Mat & img, int fit_size_x = -1, int fit_size_y = -1);
74 void updateTrackerPosition(BBox_c & bbox);
76 // frame-to-frame object tracking
77 void track(cv::Mat & img);
79 double getFilterResponse() const; // Measure of tracking accuracy
84 // Initial pose of tracked object in internal image coordinates
85 // (scaled by p_downscale_factor if p_resize_image)
88 // Information to calculate current pose of the tracked object
89 cv::Point2d p_current_center;
90 double p_current_scale = 1.;
92 double max_response = -1.;
94 bool p_resize_image = false;
96 const double p_downscale_factor = 0.5;
97 const double p_floating_error = 0.0001;
99 const double p_padding = 1.5;
100 const double p_output_sigma_factor = 0.1;
101 double p_output_sigma;
102 const double p_kernel_sigma = 0.5; //def = 0.5
103 const double p_lambda = 1e-4; //regularization in learning step
104 const double p_interp_factor = 0.02; //def = 0.02, linear interpolation factor for adaptation
105 cv::Size p_windows_size; // size of the patch to find the tracked object in
106 cv::Size fit_size; // size to which rescale the patch for better FFT performance
108 const uint p_num_scales = m_use_scale ? 7 : 1;
109 const double p_scale_step = 1.02;
110 double p_min_max_scale[2];
111 std::vector<double> p_scales;
113 const uint p_num_angles = 1;
114 const int p_angle_step = 10;
115 std::vector<double> p_angles = {0};
117 const int p_num_of_feats = 31 + (m_use_color ? 3 : 0) + (m_use_cnfeat ? 10 : 0);
118 cv::Size feature_size;
120 Kcf_Tracker_Private &d;
124 ComplexMat p_model_alphaf;
125 ComplexMat p_model_alphaf_num;
126 ComplexMat p_model_alphaf_den;
127 ComplexMat p_model_xf;
130 class GaussianCorrelation {
132 GaussianCorrelation(uint num_scales, cv::Size size)
133 : xf_sqr_norm(num_scales)
134 , xyf(Fft::freq_size(size), 1, num_scales)
135 , ifft_res(num_scales, size)
136 , k(num_scales, size)
138 void operator()(ComplexMat &result, const ComplexMat &xf, const ComplexMat &yf, double sigma, bool auto_correlation, const KCF_Tracker &kcf);
142 DynMem yf_sqr_norm{1};
149 void scale_track(ThreadCtx &vars, cv::Mat &input_rgb, cv::Mat &input_gray);
150 cv::Mat get_subwindow(const cv::Mat &input, int cx, int cy, int size_x, int size_y) const;
151 cv::Mat gaussian_shaped_labels(double sigma, int dim1, int dim2);
152 std::unique_ptr<GaussianCorrelation> gaussian_correlation;
153 cv::Mat circshift(const cv::Mat &patch, int x_rot, int y_rot);
154 cv::Mat cosine_window_function(int dim1, int dim2);
155 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;
156 cv::Point2f sub_pixel_peak(cv::Point &max_loc, cv::Mat &response) const;
157 double sub_grid_scale(uint index);
158 void resizeImgs(cv::Mat &input_rgb, cv::Mat &input_gray);
159 void train(cv::Mat input_rgb, cv::Mat input_gray, double interp_factor);
160 double findMaxReponse(uint &max_idx, cv::Point2d &new_location) const;
163 #endif //KCF_HEADER_6565467831231