diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-10-02 13:45:38 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-10-02 13:45:38 +0200 |
commit | 4a2f89042595a5caefc1ee286b6ddca8e7714adc (patch) | |
tree | 8e9ae4c1dc79610f386fa2683a4861efe6394939 /ftnoir_tracker_pt | |
parent | fa12408b959a856c53d9aeadede060530e1ccbd3 (diff) |
pt: experimental auto threshold support
Sponsored-by: TrackHat
Diffstat (limited to 'ftnoir_tracker_pt')
-rw-r--r-- | ftnoir_tracker_pt/FTNoIR_PT_Controls.ui | 106 | ||||
-rw-r--r-- | ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp | 2 | ||||
-rw-r--r-- | ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h | 4 | ||||
-rw-r--r-- | 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 @@ <rect> <x>0</x> <y>0</y> - <width>405</width> - <height>593</height> + <width>419</width> + <height>575</height> </rect> </property> <property name="sizePolicy"> @@ -299,52 +299,30 @@ <string>Point extraction</string> </property> <layout class="QGridLayout" name="gridLayout_7"> - <item row="0" column="1" colspan="2"> - <widget class="QSlider" name="threshold_slider"> + <item row="3" column="1"> + <widget class="QSpinBox" name="maxdiam_spin"> <property name="toolTip"> - <string>Intensity threshold for point extraction</string> - </property> - <property name="maximum"> - <number>255</number> - </property> - <property name="pageStep"> - <number>1</number> - </property> - <property name="value"> - <number>127</number> - </property> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="tickPosition"> - <enum>QSlider::TicksBothSides</enum> - </property> - <property name="tickInterval"> - <number>25</number> + <string>Maximum point diameter</string> </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_7"> - <property name="text"> - <string>Min size</string> + <property name="suffix"> + <string> px</string> </property> - <property name="buddy"> - <cstring>mindiam_spin</cstring> + <property name="maximum"> + <number>1024</number> </property> </widget> </item> - <item row="0" column="0"> - <widget class="QLabel" name="label"> + <item row="3" column="0"> + <widget class="QLabel" name="label_8"> <property name="text"> - <string>Threshold</string> + <string>Max size</string> </property> <property name="buddy"> - <cstring>threshold_slider</cstring> + <cstring>maxdiam_spin</cstring> </property> </widget> </item> - <item row="1" column="1"> + <item row="2" column="1"> <widget class="QSpinBox" name="mindiam_spin"> <property name="toolTip"> <string>Minimum point diameter</string> @@ -357,26 +335,62 @@ </property> </widget> </item> + <item row="1" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Threshold</string> + </property> + <property name="buddy"> + <cstring>threshold_slider</cstring> + </property> + </widget> + </item> <item row="2" column="0"> - <widget class="QLabel" name="label_8"> + <widget class="QLabel" name="label_7"> <property name="text"> - <string>Max size</string> + <string>Min size</string> </property> <property name="buddy"> - <cstring>maxdiam_spin</cstring> + <cstring>mindiam_spin</cstring> </property> </widget> </item> - <item row="2" column="1"> - <widget class="QSpinBox" name="maxdiam_spin"> + <item row="1" column="1" colspan="2"> + <widget class="QSlider" name="threshold_slider"> <property name="toolTip"> - <string>Maximum point diameter</string> - </property> - <property name="suffix"> - <string> px</string> + <string>Intensity threshold for point extraction</string> </property> <property name="maximum"> - <number>1024</number> + <number>255</number> + </property> + <property name="pageStep"> + <number>1</number> + </property> + <property name="value"> + <number>127</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="tickPosition"> + <enum>QSlider::TicksBothSides</enum> + </property> + <property name="tickInterval"> + <number>25</number> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label_11"> + <property name="text"> + <string>Automatic threshold</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QCheckBox" name="auto_threshold"> + <property name="text"> + <string>Enable, ignore slider</string> </property> </widget> </item> 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<bool> dynamic_pose; value<int> init_phase_timeout; + value<bool> 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<cv::Vec2f> 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<cv::Vec2f> PointExtractor::extract_points(cv::Mat& frame) std::vector<simple_blob> blobs; std::vector<std::vector<cv::Point>> 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; |