From: Michal Sojka Date: Sat, 13 Oct 2018 14:19:13 +0000 (+0200) Subject: Add support for tracking of multiple angles X-Git-Url: https://rtime.felk.cvut.cz/gitweb/hercules2020/kcf.git/commitdiff_plain/0ff83353d3dffe0e298059953d254489acbeeb2b Add support for tracking of multiple angles --- diff --git a/src/kcf.cpp b/src/kcf.cpp index d58ee8a..f35a658 100644 --- a/src/kcf.cpp +++ b/src/kcf.cpp @@ -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); diff --git a/src/kcf.h b/src/kcf.h index 76abc5e..8d6973c 100644 --- a/src/kcf.h +++ b/src/kcf.h @@ -110,7 +110,7 @@ private: double p_min_max_scale[2]; std::vector p_scales; - const uint p_num_angles = 1; + const uint p_num_angles = 3; const int p_angle_step = 10; std::vector p_angles;