]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/commitdiff
Simplify fit scale computation, cleanup
authorMichal Sojka <michal.sojka@cvut.cz>
Wed, 12 Sep 2018 19:54:58 +0000 (21:54 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Wed, 12 Sep 2018 19:54:58 +0000 (21:54 +0200)
src/kcf.cpp
src/kcf.h

index 0caf99ccc3c66d8842e9e47209ad63430f547d28..a42a425cdc1079e1f04006c8f6fdf11d88bee1ae 100644 (file)
@@ -98,12 +98,8 @@ void KCF_Tracker::init(cv::Mat &img, const cv::Rect &bbox, int fit_size_x, int f
             std::cerr << "Error: Fit size is not multiple of HOG cell size (" << p_cell_size << ")" << std::endl;
             std::exit(EXIT_FAILURE);
         }
-        double tmp = (p_pose.w * (1. + p_padding) / p_cell_size) * p_cell_size;
-        if (fabs(tmp - fit_size_x) > p_floating_error)
-            p_scale_factor_x = fit_size_x / tmp;
-        tmp = (p_pose.h * (1. + p_padding) / p_cell_size) * p_cell_size;
-        if (fabs(tmp - fit_size_y) > p_floating_error)
-            p_scale_factor_y = fit_size_y / tmp;
+        p_scale_factor_x = (double)fit_size_x / round(p_pose.w * (1. + p_padding));
+        p_scale_factor_y = (double)fit_size_y / round(p_pose.h * (1. + p_padding));
         std::cout << "resizing image horizontaly by factor of " << p_scale_factor_x << " and verticaly by factor of "
                   << p_scale_factor_y << std::endl;
         p_fit_to_pw2 = true;
@@ -114,16 +110,15 @@ void KCF_Tracker::init(cv::Mat &img, const cv::Rect &bbox, int fit_size_x, int f
                 cv::resize(input_gray, input_gray, cv::Size(0, 0), p_scale_factor_x, p_scale_factor_y, cv::INTER_AREA);
                 cv::resize(input_rgb, input_rgb, cv::Size(0, 0), p_scale_factor_x, p_scale_factor_y, cv::INTER_AREA);
             } else {
-                cv::resize(input_gray, input_gray, cv::Size(0, 0), p_scale_factor_x, p_scale_factor_y,
-                           cv::INTER_LINEAR);
+                cv::resize(input_gray, input_gray, cv::Size(0, 0), p_scale_factor_x, p_scale_factor_y, cv::INTER_LINEAR);
                 cv::resize(input_rgb, input_rgb, cv::Size(0, 0), p_scale_factor_x, p_scale_factor_y, cv::INTER_LINEAR);
             }
         }
     }
 
     // compute win size + fit to fhog cell size
-    p_windows_size.width = int(round(p_pose.w * (1. + p_padding) / p_cell_size) * p_cell_size);
-    p_windows_size.height = int(round(p_pose.h * (1. + p_padding) / p_cell_size) * p_cell_size);
+    p_windows_size.width = round(p_pose.w * (1. + p_padding) / p_cell_size) * p_cell_size;
+    p_windows_size.height = round(p_pose.h * (1. + p_padding) / p_cell_size) * p_cell_size;
 
     p_num_of_feats = 31;
     if (m_use_color) p_num_of_feats += 3;
index 079d1221d0110d5fced20bef18fe930a583c46c0..7b3e6838110daeebd2ef683552dad10d9436a564 100644 (file)
--- a/src/kcf.h
+++ b/src/kcf.h
@@ -111,7 +111,7 @@ private:
     const double p_downscale_factor = 0.5;
     double p_scale_factor_x = 1;
     double p_scale_factor_y = 1;
-    double p_floating_error = 0.0001;
+    const double p_floating_error = 0.0001;
 
     double p_padding = 1.5;
     double p_output_sigma_factor = 0.1;