struct ThreadCtx {
public:
- ThreadCtx(cv::Size roi, uint num_channels, double scale, uint num_of_scales)
- : scale(scale)
- , gc(num_of_scales)
- {
- uint cells_size = roi.width * roi.height * sizeof(float);
- cv::Size freq_size = Fft::freq_size(roi);
-
-#if defined(CUFFT) || defined(FFTW)
- this->gauss_corr_res = DynMem(cells_size * num_of_scales);
- this->data_features = DynMem(cells_size * num_channels);
-
- this->in_all = cv::Mat(roi.height * num_of_scales, roi.width, CV_32F, this->gauss_corr_res.hostMem());
- this->fw_all = cv::Mat(roi.height * num_channels, roi.width, CV_32F, this->data_features.hostMem());
-#else
- this->in_all = cv::Mat(roi, CV_32F);
+ ThreadCtx(cv::Size roi, uint num_channels, uint num_of_scales
+#ifndef BIG_BATCH
+ , double scale
#endif
-
- this->data_i_features = DynMem(cells_size * num_channels);
- this->data_i_1ch = DynMem(cells_size * num_of_scales);
-
- this->ifft2_res = cv::Mat(roi, CV_32FC(num_channels), this->data_i_features.hostMem());
- this->response = cv::Mat(roi, CV_32FC(num_of_scales), this->data_i_1ch.hostMem());
-
- this->zf.create(freq_size.height, freq_size.width, num_channels, num_of_scales);
- this->kzf.create(freq_size.height, freq_size.width, num_of_scales);
- this->kf.create(freq_size.height, freq_size.width, num_of_scales);
-
-#ifdef BIG_BATCH
- if (num_of_scales > 1) {
- this->max_responses.reserve(num_of_scales);
- this->max_locs.reserve(num_of_scales);
- this->response_maps.reserve(num_of_scales);
- }
+ )
+ : roi(roi)
+ , num_channels(num_channels)
+ , num_of_scales(num_of_scales)
+#ifndef BIG_BATCH
+ , scale(scale)
#endif
- }
+ {}
ThreadCtx(ThreadCtx &&) = default;
- const double scale;
+private:
+ cv::Size roi;
+ uint num_channels;
+ uint num_of_scales;
+ cv::Size freq_size = Fft::freq_size(roi);
+
+public:
#ifdef ASYNC
std::future<void> async_res;
#endif
- class gaussian_correlation_data {
- friend void KCF_Tracker::gaussian_correlation(struct ThreadCtx &vars, const ComplexMat &xf, const ComplexMat &yf, double sigma, bool auto_correlation);
- DynMem xf_sqr_norm;
- DynMem yf_sqr_norm{sizeof(float)};
-
- public:
- gaussian_correlation_data(uint num_of_scales) : xf_sqr_norm(num_of_scales * sizeof(float)) {}
- } gc;
-
- cv::Mat in_all, fw_all, ifft2_res, response;
- ComplexMat zf, kzf, kf, xyf;
+ KCF_Tracker::GaussianCorrelation gaussian_correlation{Fft::freq_size(roi), num_of_scales};
- DynMem data_i_features, data_i_1ch;
- // CuFFT and FFTW variables
- DynMem gauss_corr_res, data_features;
+#if defined(CUFFT) || defined(FFTW) // TODO: Why this ifdef?
+ MatDynMem in_all{roi.height * int(num_of_scales), roi.width, CV_32F};
+#else
+ MatDynMem in_all{roi, CV_32F};
+#endif
+ MatDynMem fw_all{roi.height * int(num_channels), roi.width, CV_32F};
+ MatDynMem ifft2_res{roi, CV_32FC(num_channels)};
+ MatDynMem response{roi, CV_32FC(num_of_scales)};
- // CuFFT variables
- ComplexMat model_alphaf, model_xf;
+ ComplexMat zf{uint(freq_size.height), uint(freq_size.width), num_channels, num_of_scales};
+ ComplexMat kzf{uint(freq_size.height), uint(freq_size.width), num_of_scales};
// Variables used during non big batch mode and in big batch mode with ThreadCtx in p_threadctxs in kcf on zero index.
cv::Point2i max_loc;
#ifdef BIG_BATCH
// Stores value of responses, location of maximal response and response maps for each scale
- std::vector<double> max_responses;
- std::vector<cv::Point2i> max_locs;
- std::vector<cv::Mat> response_maps;
+ std::vector<double> max_responses{num_of_scales};
+ std::vector<cv::Point2i> max_locs{num_of_scales};
+ std::vector<cv::Mat> response_maps{num_of_scales};
+#else
+ const double scale;
#endif
};