From 61c86a6cffb5c71beee1c271f69672854f80df3f Mon Sep 17 00:00:00 2001 From: Shanigen Date: Thu, 27 Sep 2018 12:47:18 +0200 Subject: [PATCH] Integration of the visual debug, with zero changes to the tracker's API. --- main_vot.cpp | 7 ++++++- src/kcf.cpp | 33 +++++++++++++++++++++++++++++++++ src/kcf.h | 3 ++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/main_vot.cpp b/main_vot.cpp index eddb39f..edcc834 100644 --- a/main_vot.cpp +++ b/main_vot.cpp @@ -43,6 +43,7 @@ int main(int argc, char *argv[]) int option_index = 0; static struct option long_options[] = { {"debug", no_argument, 0, 'd' }, + {"visualDebug", no_argument, 0, 'p'}, {"help", no_argument, 0, 'h' }, {"output", required_argument, 0, 'o' }, {"visualize", optional_argument, 0, 'v' }, @@ -50,7 +51,7 @@ int main(int argc, char *argv[]) {0, 0, 0, 0 } }; - int c = getopt_long(argc, argv, "dhv::f::o:", long_options, &option_index); + int c = getopt_long(argc, argv, "dphv::f::o:", long_options, &option_index); if (c == -1) break; @@ -58,6 +59,10 @@ int main(int argc, char *argv[]) case 'd': tracker.m_debug = true; break; + case 'p': + tracker.m_visual_debug = true; + visualize_delay = 500; + break; case 'h': std::cerr << "Usage: \n" << argv[0] << " [options]\n" diff --git a/src/kcf.cpp b/src/kcf.cpp index 75119bd..32cd950 100644 --- a/src/kcf.cpp +++ b/src/kcf.cpp @@ -321,6 +321,39 @@ double KCF_Tracker::findMaxReponse(uint &max_idx, cv::Point2d &new_location) con } } #endif + + if (m_visual_debug) { + cv::Mat all_responses(cv::Size(p_num_angles * 100, p_num_scales * 100), + d.threadctxs[max_idx].response.plane(0).type(), cv::Scalar::all(0)); + for (size_t i = 0; i < p_num_scales; ++i) { + for (size_t j = 0; j < p_num_angles; ++j) { + cv::Mat in_roi(all_responses, cv::Rect(j * 100, i * 100, 100, 100)); + cv::Mat copy_response = d.threadctxs[p_num_angles * i + j].response.plane(0).clone(); + + copy_response = copy_response(cv::Rect(0, 0, copy_response.cols & -2, copy_response.rows & -2)); + + int cx = copy_response.cols / 2; + int cy = copy_response.rows / 2; + cv::Mat q0(copy_response, cv::Rect(0, 0, cx, cy)); + cv::Mat q1(copy_response, cv::Rect(cx, 0, cx, cy)); + cv::Mat q2(copy_response, cv::Rect(0, cy, cx, cy)); + cv::Mat q3(copy_response, cv::Rect(cx, cy, cx, cy)); + cv::Mat tmp; + q0.copyTo(tmp); + q3.copyTo(q0); + tmp.copyTo(q3); + q1.copyTo(tmp); + q2.copyTo(q1); + tmp.copyTo(q2); + + copy_response.copyTo(in_roi); + } + } + cv::namedWindow("All responses", CV_WINDOW_AUTOSIZE); + cv::imshow("All responses", all_responses); + cv::waitKey(); + } + cv::Point2i &max_response_pt = IF_BIG_BATCH(d.threadctxs[0].max[max_idx].loc, d.threadctxs[max_idx].max.loc); cv::Mat max_response_map = IF_BIG_BATCH(d.threadctxs[0].response.plane(max_idx), d.threadctxs[max_idx].response.plane(0)); diff --git a/src/kcf.h b/src/kcf.h index 42c68f7..4ca1066 100644 --- a/src/kcf.h +++ b/src/kcf.h @@ -59,7 +59,8 @@ class KCF_Tracker { friend ThreadCtx; public: - bool m_debug {false}; + bool m_debug {false}; + bool m_visual_debug {false}; const bool m_use_scale {true}; const bool m_use_color {true}; const bool m_use_subpixel_localization {true}; -- 2.39.2