From 535e81402a65fa410e98899cd1780784d2f9815a Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 13 Oct 2017 15:06:21 +0200 Subject: tracker/pt: add threshold slider state description Isolate point radius code and reuse it. --- tracker-pt/FTNoIR_PT_Controls.ui | 64 ++++++++++++++++++++++++++-------------- tracker-pt/point_extractor.cpp | 22 ++++++++++---- tracker-pt/point_extractor.h | 2 ++ 3 files changed, 60 insertions(+), 28 deletions(-) diff --git a/tracker-pt/FTNoIR_PT_Controls.ui b/tracker-pt/FTNoIR_PT_Controls.ui index 1132d156..ac85b2cb 100644 --- a/tracker-pt/FTNoIR_PT_Controls.ui +++ b/tracker-pt/FTNoIR_PT_Controls.ui @@ -9,8 +9,8 @@ 0 0 - 412 - 616 + 411 + 630 @@ -458,8 +458,8 @@ Point extraction - - + + 0 @@ -467,15 +467,15 @@ - Max size + Threshold - maxdiam_spin + threshold_slider - - + + 0 @@ -483,15 +483,15 @@ - Threshold + Min size - threshold_slider + mindiam_spin - - + + 0 @@ -499,10 +499,10 @@ - Min size + Max size - mindiam_spin + maxdiam_spin @@ -537,8 +537,8 @@ - - + + 0 @@ -546,12 +546,12 @@ - Automatic threshold + Enable, slider sets point size - - + + 0 @@ -559,11 +559,11 @@ - Enable, slider sets point size + Automatic threshold - + @@ -585,7 +585,7 @@ - + @@ -607,6 +607,26 @@ + + + + + 0 + 0 + + + + + + + + + + + Value + + + diff --git a/tracker-pt/point_extractor.cpp b/tracker-pt/point_extractor.cpp index 9030b520..adb23d52 100644 --- a/tracker-pt/point_extractor.cpp +++ b/tracker-pt/point_extractor.cpp @@ -101,6 +101,18 @@ void PointExtractor::separate_channels(cv::Mat const& orig, const int* order, in ch[k].convertTo(ch_float[k], CV_32F); } +double PointExtractor::threshold_radius_value(int w, int h, int threshold) +{ + double cx = w / 640., cy = h / 480.; + + const double min_radius = 1.75 * cx; + const double max_radius = 15 * cy; + + const double radius = std::fmax(0., (max_radius-min_radius) * threshold / 255 + min_radius); + + return radius; +} + void PointExtractor::extract_points(const cv::Mat& frame, cv::Mat& preview_frame, std::vector& points) { using std::sqrt; @@ -122,7 +134,7 @@ void PointExtractor::extract_points(const cv::Mat& frame, cv::Mat& preview_frame case pt_color_floppy_filter: { // weight for blue color - static constexpr float B = .8; + static constexpr float B = .667; static constexpr int from_to[] = { 0, 0, @@ -162,6 +174,8 @@ void PointExtractor::extract_points(const cv::Mat& frame, cv::Mat& preview_frame break; } + //cv::imshow("capture", frame_gray); + //cv::waitKey(1); const double region_size_min = s.min_point_size; const double region_size_max = s.max_point_size; @@ -186,12 +200,8 @@ void PointExtractor::extract_points(const cv::Mat& frame, cv::Mat& preview_frame (int const*) &hist_size, &ranges); - const double cx = frame.cols / 640., cy = frame.rows / 480.; - - const double min_radius = 1.75 * cx; - const double max_radius = 15 * cy; + const double radius = threshold_radius_value(frame.cols, frame.rows, s.threshold); - const double radius = fmax(0., (max_radius-min_radius) * s.threshold / 255 + min_radius); float const* restrict_ptr ptr = reinterpret_cast(hist.ptr(0)); const unsigned area = uround(3 * M_PI * radius*radius); const unsigned sz = unsigned(hist.cols * hist.rows); diff --git a/tracker-pt/point_extractor.h b/tracker-pt/point_extractor.h index 8fd521c3..fd32e94b 100644 --- a/tracker-pt/point_extractor.h +++ b/tracker-pt/point_extractor.h @@ -39,6 +39,8 @@ public: PointExtractor(); settings_pt s; + + static double threshold_radius_value(int w, int h, int threshold); private: static constexpr int max_blobs = 16; -- cgit v1.2.3