8 #include "complexmat.cuh"
10 #include "complexmat.hpp"
12 // For compatibility reasons between CuFFT and FFTW, OpenCVfft versions.
13 typedef int *cudaStream_t;
19 ThreadCtx(cv::Size roi, uint num_of_feats, double scale, uint num_of_scales)
22 this->xf_sqr_norm = DynMem(num_of_scales * sizeof(float));
23 this->yf_sqr_norm = DynMem(sizeof(float));
24 this->patch_feats.reserve(uint(num_of_feats));
26 uint cells_size = roi.width * roi.height * sizeof(float);
28 #if !defined(BIG_BATCH) && defined(CUFFT) && (defined(ASYNC) || defined(OPENMP))
29 CudaSafeCall(cudaStreamCreate(&this->stream));
32 #if defined(CUFFT) || defined(FFTW)
33 this->gauss_corr_res = DynMem(cells_size * num_of_scales);
34 this->data_features = DynMem(cells_size * num_of_feats);
36 uint width_freq = roi.width / 2 + 1;
38 this->in_all = cv::Mat(roi.height * num_of_scales, roi.width, CV_32F, this->gauss_corr_res.hostMem());
39 this->fw_all = cv::Mat(roi.height * num_of_feats, roi.width, CV_32F, this->data_features.hostMem());
41 uint width_freq = roi.width;
43 this->in_all = cv::Mat(roi, CV_32F);
46 this->data_i_features = DynMem(cells_size * num_of_feats);
47 this->data_i_1ch = DynMem(cells_size * num_of_scales);
49 this->ifft2_res = cv::Mat(roi, CV_32FC(num_of_feats), this->data_i_features.hostMem());
50 this->response = cv::Mat(roi, CV_32FC(num_of_scales), this->data_i_1ch.hostMem());
52 this->patch_feats.reserve(num_of_feats);
55 this->zf.create(roi.height, width_freq, num_of_feats, num_of_scales, this->stream);
56 this->kzf.create(roi.height, width_freq, num_of_scales, this->stream);
57 this->kf.create(roi.height, width_freq, num_of_scales, this->stream);
59 this->zf.create(roi.height, width_freq, num_of_feats, num_of_scales);
60 this->kzf.create(roi.height, width_freq, num_of_scales);
61 this->kf.create(roi.height, width_freq, num_of_scales);
64 if (num_of_scales > 1) {
65 this->max_responses.reserve(num_of_scales);
66 this->max_locs.reserve(num_of_scales);
67 this->response_maps.reserve(num_of_scales);
70 ThreadCtx(ThreadCtx &&) = default;
73 #if !defined(BIG_BATCH) && defined(CUFFT) && (defined(ASYNC) || defined(OPENMP))
74 CudaSafeCall(cudaStreamDestroy(this->stream));
80 std::future<void> async_res;
83 DynMem xf_sqr_norm, yf_sqr_norm;
84 std::vector<cv::Mat> patch_feats;
86 cv::Mat in_all, fw_all, ifft2_res, response;
87 ComplexMat zf, kzf, kf, xyf;
89 DynMem data_i_features, data_i_1ch;
90 // CuFFT and FFTW variables
91 DynMem gauss_corr_res, data_features;
94 cudaStream_t stream = nullptr;
95 ComplexMat model_alphaf, model_xf;
97 // Variables used during non big batch mode and in big batch mode with ThreadCtx in p_threadctxs in kcf on zero index.
99 double max_val, max_response;
101 // Big batch variables
102 // Stores value of responses, location of maximal response and response maps for each scale
103 std::vector<double> max_responses;
104 std::vector<cv::Point2i> max_locs;
105 std::vector<cv::Mat> response_maps;
108 #endif // SCALE_VARS_HPP