#include <future>
#include "dynmem.hpp"
#include "kcf.h"
-
-#ifdef CUFFT
-#include "complexmat.cuh"
-#else
#include "complexmat.hpp"
-#endif
+#include <vector>
class KCF_Tracker;
+template <typename T>
+class ScaleRotVector : public std::vector<T> {
+public:
+ ScaleRotVector(const std::vector<double> &scales, const std::vector<double> &angles)
+ : scales(scales)
+ , angles(angles)
+ {}
+
+ uint getIdx(uint scale_idx, uint angle_idx) const { return angles.size() * scale_idx + angle_idx; }
+ uint getScaleIdx(uint idx) const { return idx / angles.size(); }
+ uint getAngleIdx(uint idx) const { return idx % angles.size(); }
+ T& operator()(uint scale_idx, uint angle_idx) { return std::vector<T>::at(getIdx(scale_idx, angle_idx)); }
+ double scale(uint idx) const { return scales[getScaleIdx(idx)]; }
+ double angle(uint idx) const { return angles[getAngleIdx(idx)]; }
+private:
+ const std::vector<double> scales, angles;
+};
+
struct ThreadCtx {
public:
- ThreadCtx(cv::Size roi, uint num_channels, uint num_of_scales
-#ifndef BIG_BATCH
+ ThreadCtx(cv::Size roi, uint num_features
+#ifdef BIG_BATCH
+ , const std::vector<double> &scales
+ , const std::vector<double> &angles
+#else
, double scale
+ , double angle
#endif
)
: roi(roi)
- , num_channels(num_channels)
- , num_of_scales(num_of_scales)
-#ifndef BIG_BATCH
+ , num_features(num_features)
+ , num_scales(IF_BIG_BATCH(scales.size(), 1))
+ , num_angles(IF_BIG_BATCH(angles.size(), 1))
+#ifdef BIG_BATCH
+ , max(scales, angles)
+ , dbg_patch(scales, angles)
+ {
+ max.resize(scales.size() * angles.size());
+ dbg_patch.resize(scales.size() * angles.size());
+ }
+#else
, scale(scale)
+ , angle(angle)
+ {}
#endif
- {}
+
ThreadCtx(ThreadCtx &&) = default;
+ void track(const KCF_Tracker &kcf, cv::Mat &input_rgb, cv::Mat &input_gray);
private:
cv::Size roi;
- uint num_channels;
- uint num_of_scales;
+ uint num_features;
+ uint num_scales;
+ uint num_angles;
cv::Size freq_size = Fft::freq_size(roi);
+ MatScaleFeats patch_feats{num_scales * num_angles, num_features, roi};
+ MatScaleFeats temp{num_scales * num_angles, num_features, roi};
+
+ KCF_Tracker::GaussianCorrelation gaussian_correlation{num_scales * num_angles, num_features, roi};
+
+ MatScales ifft2_res{num_scales * num_angles, roi};
+
+ ComplexMat zf{uint(freq_size.height), uint(freq_size.width), num_features, num_scales * num_angles};
+ ComplexMat kzf{uint(freq_size.height), uint(freq_size.width), 1, num_scales * num_angles};
+
public:
#ifdef ASYNC
std::future<void> async_res;
#endif
- KCF_Tracker::GaussianCorrelation gaussian_correlation{Fft::freq_size(roi), num_of_scales};
-
-#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)};
-
- 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};
+ MatScales response{num_scales * num_angles, roi};
- // 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;
- double max_val, max_response;
+ struct Max {
+ cv::Point2i loc;
+ double response;
+ };
#ifdef BIG_BATCH
- // Stores value of responses, location of maximal response and response maps for each scale
- 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};
+ ScaleRotVector<Max> max;
+ ScaleRotVector<cv::Mat> dbg_patch; // images for visual debugging
#else
- const double scale;
+ Max max;
+ const double scale, angle;
+ cv::Mat dbg_patch; // image for visual debugging
#endif
};