X-Git-Url: http://rtime.felk.cvut.cz/gitweb/hercules2020/kcf.git/blobdiff_plain/3748e7e9a8a41c4ba9ce4ef2c225b49f7e3feadc..2c6dc73e108709604927a59ec0168f0187e0270c:/src/kcf.h diff --git a/src/kcf.h b/src/kcf.h index 48eb18d..02fe814 100644 --- a/src/kcf.h +++ b/src/kcf.h @@ -6,13 +6,10 @@ #include #include "fhog.hpp" +#include "complexmat.hpp" #ifdef CUFFT -#include "complexmat.cuh" -#include "cuda_functions.cuh" #include "cuda_error_check.hpp" #include -#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,15 +43,17 @@ struct BBox_c class KCF_Tracker { friend ThreadCtx; + friend Kcf_Tracker_Private; public: 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}; + enum class vd {NONE, PATCH, RESPONSE} m_visual_debug {vd::NONE}; + constexpr static bool m_use_scale {true}; + constexpr static bool m_use_color {true}; + constexpr static bool m_use_subpixel_localization {true}; + constexpr static bool m_use_subgrid_scale {true}; + constexpr static bool m_use_subgrid_angle {true}; + constexpr static bool m_use_cnfeat {true}; + constexpr static bool m_use_linearkernel {false}; const int p_cell_size = 4; //4 for hog (= bin_size) /* @@ -89,13 +88,14 @@ 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.; bool p_resize_image = false; - const double p_downscale_factor = 0.5; - const double p_floating_error = 0.0001; + constexpr static double p_downscale_factor = 0.5; + constexpr static double p_floating_error = 0.0001; const double p_padding = 1.5; const double p_output_sigma_factor = 0.1; @@ -106,40 +106,51 @@ private: cv::Size p_windows_size; // size of the patch to find the tracked object in cv::Size fit_size; // size to which rescale the patch for better FFT performance - const uint p_num_scales = m_use_scale ? 7 : 1; - const double p_scale_step = 1.02; + constexpr static uint p_num_scales = m_use_scale ? 5 : 1; + constexpr static double p_scale_step = 1.03; double p_min_max_scale[2]; std::vector p_scales; - const uint p_num_angles = 1; - const int p_angle_step = 10; - std::vector p_angles = {0}; + constexpr static uint p_num_angles = 3; + constexpr static int p_angle_step = 10; + std::vector p_angles; - const int p_num_of_feats = 31 + (m_use_color ? 3 : 0) + (m_use_cnfeat ? 10 : 0); + constexpr static 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 d; class Model { + cv::Size feature_size; uint height, width, n_feats; public: ComplexMat yf {height, width, 1}; - ComplexMat model_alphaf {height, width, n_feats}; - ComplexMat model_alphaf_num {height, width, n_feats}; - ComplexMat model_alphaf_den {height, width, n_feats}; + ComplexMat model_alphaf {height, width, 1}; + ComplexMat model_alphaf_num {height, width, 1}; + ComplexMat model_alphaf_den {height, width, 1}; 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; class GaussianCorrelation { public: - GaussianCorrelation(uint num_scales, cv::Size size) + GaussianCorrelation(uint num_scales, uint num_feats, cv::Size size) : xf_sqr_norm(num_scales) - , xyf(Fft::freq_size(size), 1, num_scales) + , xyf(Fft::freq_size(size), num_feats, num_scales) , ifft_res(num_scales, size) , k(num_scales, size) {} @@ -153,20 +164,20 @@ 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 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); void train(cv::Mat input_rgb, cv::Mat input_gray, double interp_factor); double findMaxReponse(uint &max_idx, cv::Point2d &new_location) const; + double sub_grid_angle(uint max_index); }; #endif //KCF_HEADER_6565467831231