From 4a2f89042595a5caefc1ee286b6ddca8e7714adc Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 2 Oct 2015 13:45:38 +0200 Subject: pt: experimental auto threshold support Sponsored-by: TrackHat --- ftnoir_tracker_pt/FTNoIR_PT_Controls.ui | 106 ++++++++++++++----------- ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp | 2 + ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h | 4 +- ftnoir_tracker_pt/point_extractor.cpp | 16 +++- 4 files changed, 79 insertions(+), 49 deletions(-) diff --git a/ftnoir_tracker_pt/FTNoIR_PT_Controls.ui b/ftnoir_tracker_pt/FTNoIR_PT_Controls.ui index 62add856..32dcdef1 100644 --- a/ftnoir_tracker_pt/FTNoIR_PT_Controls.ui +++ b/ftnoir_tracker_pt/FTNoIR_PT_Controls.ui @@ -9,8 +9,8 @@ 0 0 - 405 - 593 + 419 + 575 @@ -299,52 +299,30 @@ Point extraction - - + + - Intensity threshold for point extraction - - - 255 - - - 1 - - - 127 - - - Qt::Horizontal - - - QSlider::TicksBothSides - - - 25 + Maximum point diameter - - - - - - Min size + + px - - mindiam_spin + + 1024 - - + + - Threshold + Max size - threshold_slider + maxdiam_spin - + Minimum point diameter @@ -357,26 +335,62 @@ + + + + Threshold + + + threshold_slider + + + - + - Max size + Min size - maxdiam_spin + mindiam_spin - - + + - Maximum point diameter - - - px + Intensity threshold for point extraction - 1024 + 255 + + + 1 + + + 127 + + + Qt::Horizontal + + + QSlider::TicksBothSides + + + 25 + + + + + + + Automatic threshold + + + + + + + Enable, ignore slider diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp index 12d108ac..da7a6113 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp @@ -62,6 +62,8 @@ TrackerDialog_PT::TrackerDialog_PT() tie_setting(s.dynamic_pose, ui.dynamic_pose); tie_setting(s.init_phase_timeout, ui.init_phase_timeout); + tie_setting(s.auto_threshold, ui.auto_threshold); + connect( ui.tcalib_button,SIGNAL(toggled(bool)), this,SLOT(startstop_trans_calib(bool)) ); connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h b/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h index af2f5978..57e68d0e 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h @@ -33,6 +33,7 @@ struct settings_pt : opts value dynamic_pose; value init_phase_timeout; + value auto_threshold; settings_pt() : opts("tracker-pt"), @@ -62,7 +63,8 @@ struct settings_pt : opts cap_z(b, "cap-z", 100), fov(b, "camera-fov", 56), dynamic_pose(b, "dynamic-pose-resolution", true), - init_phase_timeout(b, "init-phase-timeout", 500) + init_phase_timeout(b, "init-phase-timeout", 500), + auto_threshold(b, "automatic-threshold", false) {} }; diff --git a/ftnoir_tracker_pt/point_extractor.cpp b/ftnoir_tracker_pt/point_extractor.cpp index fcdbbaed..0501a5c6 100644 --- a/ftnoir_tracker_pt/point_extractor.cpp +++ b/ftnoir_tracker_pt/point_extractor.cpp @@ -31,8 +31,6 @@ std::vector PointExtractor::extract_points(cv::Mat& frame) const int region_size_min = s.min_point_size; const int region_size_max = s.max_point_size; - const int thres = s.threshold; - struct simple_blob { double radius; @@ -56,12 +54,26 @@ std::vector PointExtractor::extract_points(cv::Mat& frame) std::vector blobs; std::vector> contours; + + const int thres = s.threshold; + if (!s.auto_threshold) { cv::Mat frame_bin_; cv::threshold(frame_gray, frame_bin_, thres, 255, cv::THRESH_BINARY); frame_bin.setTo(170, frame_bin_); cv::findContours(frame_bin_, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); } + else + { + cv::Mat frame_bin_, tmp; + int scale = frame_gray.cols > 400 ? 2 : 1; + constexpr int size = 3; + static cv::Mat kernel = cv::getGaussianKernel(size * scale + 1, CV_32F); + cv::sepFilter2D(frame_gray, tmp, -1, kernel, kernel); + cv::threshold(tmp, frame_bin_, 0, 255, CV_THRESH_BINARY|CV_THRESH_OTSU); + frame_bin.setTo(170, frame_bin_); + cv::findContours(frame_bin_, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); + } int cnt = 0; -- cgit v1.2.3