]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/commitdiff
Add support for tracking of multiple angles
authorMichal Sojka <michal.sojka@cvut.cz>
Sat, 13 Oct 2018 14:19:13 +0000 (16:19 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Thu, 18 Oct 2018 13:38:23 +0000 (15:38 +0200)
src/kcf.cpp
src/kcf.h

index d58ee8a9dbac8f9b14bb5608694b846289f652ac..f35a658873606bc879950a6556d811ed929ede4b 100644 (file)
@@ -273,7 +273,7 @@ BBox_c KCF_Tracker::getBBox()
     tmp.cy = p_current_center.y;
     tmp.w = p_init_pose.w * p_current_scale;
     tmp.h = p_init_pose.h * p_current_scale;
-    tmp.a = 0;
+    tmp.a = p_current_angle;
 
     if (p_resize_image)
         tmp.scale(1 / p_downscale_factor);
@@ -646,12 +646,15 @@ cv::Mat KCF_Tracker::cosine_window_function(int dim1, int dim2)
 cv::Mat KCF_Tracker::get_subwindow(const cv::Mat &input, int cx, int cy, int width, int height, double angle) const
 {
     cv::Mat patch;
-    (void)angle;
 
-    int x1 = cx - width / 2;
-    int y1 = cy - height / 2;
-    int x2 = cx + width / 2;
-    int y2 = cy + height / 2;
+    cv::Size sz(width, height);
+    cv::RotatedRect rr(cv::Point2f(cx, cy), sz, angle);
+    cv::Rect bb = rr.boundingRect();
+
+    int x1 = bb.tl().x;
+    int y1 = bb.tl().y;
+    int x2 = bb.br().x;
+    int y2 = bb.br().y;
 
     // out of image
     if (x1 >= input.cols || y1 >= input.rows || x2 < 0 || y2 < 0) {
@@ -692,6 +695,12 @@ cv::Mat KCF_Tracker::get_subwindow(const cv::Mat &input, int cx, int cy, int wid
         //      cv::waitKey();
     }
 
+    cv::Point2f src_pts[4];
+    cv::RotatedRect(cv::Point2f(patch.size()) / 2.0, sz, angle).points(src_pts);
+    cv::Point2f dst_pts[3] = { cv::Point2f(0, height), cv::Point2f(0, 0),  cv::Point2f(width, 0)};
+    auto rot = cv::getAffineTransform(src_pts, dst_pts);
+    cv::warpAffine(patch, patch, rot, sz);
+
     // sanity check
     assert(patch.cols == width && patch.rows == height);
 
index 76abc5ea4ea48989f9dcfe7693268b857bc43d7b..8d6973ce7cb15fc4a5181d821b53ea9a16d437ef 100644 (file)
--- a/src/kcf.h
+++ b/src/kcf.h
@@ -110,7 +110,7 @@ private:
     double p_min_max_scale[2];
     std::vector<double> p_scales;
 
-    const uint p_num_angles = 1;
+    const uint p_num_angles = 3;
     const int p_angle_step = 10;
     std::vector<double> p_angles;