]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blob - src/threadctx.hpp
Restrict access to ThreadCtx variables
[hercules2020/kcf.git] / src / threadctx.hpp
1 #ifndef SCALE_VARS_HPP
2 #define SCALE_VARS_HPP
3
4 #include <future>
5 #include "dynmem.hpp"
6 #include "kcf.h"
7
8 #ifdef CUFFT
9 #include "complexmat.cuh"
10 #else
11 #include "complexmat.hpp"
12 #endif
13
14 class KCF_Tracker;
15
16 struct ThreadCtx {
17   public:
18     ThreadCtx(cv::Size roi, uint num_of_feats, double scale, uint num_of_scales)
19         : scale(scale)
20         , gc(num_of_scales)
21     {
22         uint cells_size = roi.width * roi.height * sizeof(float);
23
24 #if defined(CUFFT) || defined(FFTW)
25         this->gauss_corr_res = DynMem(cells_size * num_of_scales);
26         this->data_features = DynMem(cells_size * num_of_feats);
27
28         uint width_freq = roi.width / 2 + 1;
29
30         this->in_all = cv::Mat(roi.height * num_of_scales, roi.width, CV_32F, this->gauss_corr_res.hostMem());
31         this->fw_all = cv::Mat(roi.height * num_of_feats, roi.width, CV_32F, this->data_features.hostMem());
32 #else
33         uint width_freq = roi.width;
34
35         this->in_all = cv::Mat(roi, CV_32F);
36 #endif
37
38         this->data_i_features = DynMem(cells_size * num_of_feats);
39         this->data_i_1ch = DynMem(cells_size * num_of_scales);
40
41         this->ifft2_res = cv::Mat(roi, CV_32FC(num_of_feats), this->data_i_features.hostMem());
42         this->response = cv::Mat(roi, CV_32FC(num_of_scales), this->data_i_1ch.hostMem());
43
44 #ifdef CUFFT
45         this->zf.create(roi.height, width_freq, num_of_feats, num_of_scales);
46         this->kzf.create(roi.height, width_freq, num_of_scales);
47         this->kf.create(roi.height, width_freq, num_of_scales);
48 #else
49         this->zf.create(roi.height, width_freq, num_of_feats, num_of_scales);
50         this->kzf.create(roi.height, width_freq, num_of_scales);
51         this->kf.create(roi.height, width_freq, num_of_scales);
52 #endif
53
54 #ifdef BIG_BATCH
55         if (num_of_scales > 1) {
56             this->max_responses.reserve(num_of_scales);
57             this->max_locs.reserve(num_of_scales);
58             this->response_maps.reserve(num_of_scales);
59         }
60 #endif
61     }
62     ThreadCtx(ThreadCtx &&) = default;
63
64     const double scale;
65 #ifdef ASYNC
66     std::future<void> async_res;
67 #endif
68
69     class gaussian_correlation_data {
70         friend void KCF_Tracker::gaussian_correlation(struct ThreadCtx &vars, const ComplexMat &xf, const ComplexMat &yf, double sigma, bool auto_correlation);
71         DynMem xf_sqr_norm;
72         DynMem yf_sqr_norm{sizeof(float)};
73
74       public:
75         gaussian_correlation_data(uint num_of_scales) : xf_sqr_norm(num_of_scales * sizeof(float)) {}
76     } gc;
77
78     cv::Mat in_all, fw_all, ifft2_res, response;
79     ComplexMat zf, kzf, kf, xyf;
80
81     DynMem data_i_features, data_i_1ch;
82     // CuFFT and FFTW variables
83     DynMem gauss_corr_res, data_features;
84
85     // CuFFT variables
86     ComplexMat model_alphaf, model_xf;
87
88     // Variables used during non big batch mode and in big batch mode with ThreadCtx in p_threadctxs in kcf  on zero index.
89     cv::Point2i max_loc;
90     double max_val, max_response;
91
92 #ifdef BIG_BATCH
93     // Stores value of responses, location of maximal response and response maps for each scale
94     std::vector<double> max_responses;
95     std::vector<cv::Point2i> max_locs;
96     std::vector<cv::Mat> response_maps;
97 #endif
98 };
99
100 #endif // SCALE_VARS_HPP