]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blob - src/threadctx.hpp
d1095f262a54c06682b3770f36d1e0b8dfbcff67
[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_channels, uint num_of_scales
19 #ifndef BIG_BATCH
20               , double scale
21 #endif
22              )
23         : roi(roi)
24         , num_channels(num_channels)
25         , num_of_scales(num_of_scales)
26 #ifndef BIG_BATCH
27         , scale(scale)
28 #endif
29     {}
30
31     ThreadCtx(ThreadCtx &&) = default;
32
33 private:
34     cv::Size roi;
35     uint num_channels;
36     uint num_of_scales;
37     cv::Size freq_size = Fft::freq_size(roi);
38
39 public:
40 #ifdef ASYNC
41     std::future<void> async_res;
42 #endif
43
44     KCF_Tracker::GaussianCorrelation gaussian_correlation{Fft::freq_size(roi), num_of_scales, num_channels};
45
46 #if defined(CUFFT) || defined(FFTW) // TODO: Why this ifdef?
47     MatDynMem in_all{roi.height * int(num_of_scales), roi.width, CV_32F};
48 #else
49     MatDynMem in_all{roi, CV_32F};
50 #endif
51     MatDynMem fw_all{roi.height * int(num_channels), roi.width, CV_32F};
52     MatDynMem ifft2_res{roi, CV_32FC(num_channels)};
53     MatDynMem response{roi, CV_32FC(num_of_scales)};
54
55     ComplexMat zf{uint(freq_size.height), uint(freq_size.width), num_channels, num_of_scales};
56     ComplexMat kzf{uint(freq_size.height), uint(freq_size.width), num_of_scales};
57
58     // Variables used during non big batch mode and in big batch mode with ThreadCtx in p_threadctxs in kcf  on zero index.
59     cv::Point2i max_loc;
60     double max_val, max_response;
61
62 #ifdef BIG_BATCH
63     // Stores value of responses, location of maximal response and response maps for each scale
64     std::vector<double> max_responses = std::vector<double>(num_of_scales);
65     std::vector<cv::Point2i> max_locs = std::vector<cv::Point2i>(num_of_scales);
66     std::vector<cv::Mat> response_maps = std::vector<cv::Mat>(num_of_scales);
67 #else
68     const double scale;
69 #endif
70 };
71
72 #endif // SCALE_VARS_HPP