diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-09-22 14:23:03 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-09-22 14:25:28 +0200 |
commit | 76bd17e3c095e2379daf893427cb3d9d277a064e (patch) | |
tree | 44451ebce5c6988597ec098f9a4cdd502b7c0c8d | |
parent | 0a537e04b9b5fb38ea21cc71af78698afb98ff88 (diff) |
tracker/pt: add color extraction modes
-rw-r--r-- | tracker-pt/FTNoIR_PT_Controls.ui | 319 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt_dialog.cpp | 12 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt_settings.h | 13 | ||||
-rw-r--r-- | tracker-pt/point_extractor.cpp | 78 | ||||
-rw-r--r-- | tracker-pt/point_extractor.h | 4 | ||||
-rw-r--r-- | tracker-pt/point_tracker.cpp | 4 | ||||
-rw-r--r-- | tracker-pt/point_tracker.h | 4 |
7 files changed, 326 insertions, 108 deletions
diff --git a/tracker-pt/FTNoIR_PT_Controls.ui b/tracker-pt/FTNoIR_PT_Controls.ui index 8d044654..ea83a215 100644 --- a/tracker-pt/FTNoIR_PT_Controls.ui +++ b/tracker-pt/FTNoIR_PT_Controls.ui @@ -9,8 +9,8 @@ <rect> <x>0</x> <y>0</y> - <width>424</width> - <height>588</height> + <width>412</width> + <height>616</height> </rect> </property> <property name="sizePolicy"> @@ -36,20 +36,81 @@ <property name="sizeConstraint"> <enum>QLayout::SetFixedSize</enum> </property> + <item row="1" column="0" alignment="Qt::AlignVCenter"> + <widget class="QGroupBox" name="groupBox_5"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Status</string> + </property> + <layout class="QGridLayout" name="gridLayout_10"> + <item row="1" column="0"> + <widget class="QLabel" name="label_3"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Extracted Points:</string> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label_38"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Camera Info:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="pointinfo_label"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLabel" name="caminfo_label"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </widget> + </item> <item row="0" column="0"> <widget class="QTabWidget" name="tabWidget"> <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> <property name="locale"> <locale language="English" country="UnitedStates"/> </property> @@ -63,6 +124,12 @@ <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QGroupBox" name="groupBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="title"> <string>Camera settings</string> </property> @@ -70,7 +137,7 @@ <item row="0" column="1"> <widget class="QComboBox" name="camdevice_combo"> <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -82,6 +149,12 @@ </item> <item row="4" column="1"> <widget class="QSpinBox" name="fov"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="suffix"> <string>°</string> </property> @@ -99,7 +172,7 @@ <item row="4" column="0"> <widget class="QLabel" name="label_4"> <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -112,7 +185,7 @@ <item row="1" column="0"> <widget class="QLabel" name="label_36"> <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -125,7 +198,7 @@ <item row="3" column="0"> <widget class="QLabel" name="label_37"> <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -141,7 +214,7 @@ <item row="2" column="1"> <widget class="QSpinBox" name="res_y_spin"> <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -162,6 +235,12 @@ </item> <item row="6" column="0"> <widget class="QLabel" name="label_6"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="text"> <string>Dynamic pose timeout</string> </property> @@ -170,7 +249,7 @@ <item row="3" column="1"> <widget class="QSpinBox" name="fps_spin"> <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -188,6 +267,12 @@ </item> <item row="5" column="1"> <widget class="QCheckBox" name="dynamic_pose"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="text"> <string/> </property> @@ -196,7 +281,7 @@ <item row="1" column="1"> <widget class="QSpinBox" name="res_x_spin"> <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -218,7 +303,7 @@ <item row="2" column="0"> <widget class="QLabel" name="label_41"> <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -230,6 +315,12 @@ </item> <item row="6" column="1"> <widget class="QSpinBox" name="init_phase_timeout"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="suffix"> <string> ms</string> </property> @@ -242,9 +333,9 @@ </widget> </item> <item row="5" column="0"> - <widget class="QLabel" name="label_5"> + <widget class="QLabel" name="label_13"> <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -257,7 +348,7 @@ <item row="0" column="0"> <widget class="QLabel" name="label_2"> <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -285,22 +376,91 @@ </item> <item row="7" column="0"> <widget class="QLabel" name="label_9"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="text"> <string>Camera settings (when available)</string> </property> </widget> </item> + <item row="5" column="0"> + <widget class="QLabel" name="label_511111"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Dynamic pose (for caps only, never clips)</string> + </property> + </widget> + </item> + <item row="8" column="0"> + <widget class="QLabel" name="label_12"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Color channels used</string> + </property> + </widget> + </item> + <item row="8" column="1"> + <widget class="QComboBox" name="blob_color"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <item> + <property name="text"> + <string>Normal</string> + </property> + </item> + <item> + <property name="text"> + <string>Floppy filter</string> + </property> + </item> + <item> + <property name="text"> + <string>Red</string> + </property> + </item> + </widget> + </item> </layout> </widget> </item> <item> <widget class="QGroupBox" name="groupBox_2"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="title"> <string>Point extraction</string> </property> <layout class="QGridLayout" name="gridLayout_7"> <item row="3" column="0"> <widget class="QLabel" name="label_8"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="text"> <string>Max size</string> </property> @@ -311,6 +471,12 @@ </item> <item row="1" column="0"> <widget class="QLabel" name="label"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="text"> <string>Threshold</string> </property> @@ -321,6 +487,12 @@ </item> <item row="2" column="0"> <widget class="QLabel" name="label_7"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="text"> <string>Min size</string> </property> @@ -332,7 +504,7 @@ <item row="1" column="1" colspan="2"> <widget class="QSlider" name="threshold_slider"> <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Maximum"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -362,6 +534,12 @@ </item> <item row="0" column="0"> <widget class="QLabel" name="label_11"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="text"> <string>Automatic threshold</string> </property> @@ -369,6 +547,12 @@ </item> <item row="0" column="1"> <widget class="QCheckBox" name="auto_threshold"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="text"> <string>Enable, slider sets point size</string> </property> @@ -376,6 +560,12 @@ </item> <item row="3" column="1"> <widget class="QDoubleSpinBox" name="maxdiam_spin"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="toolTip"> <string>Maximum point diameter</string> </property> @@ -392,6 +582,12 @@ </item> <item row="2" column="1"> <widget class="QDoubleSpinBox" name="mindiam_spin"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="toolTip"> <string>Minimum point diameter</string> </property> @@ -1147,91 +1343,14 @@ Don't roll or change position.</string> </widget> </widget> </item> - <item row="2" column="0" alignment="Qt::AlignVCenter"> - <widget class="QGroupBox" name="groupBox_5"> + <item row="2" column="0"> + <widget class="QDialogButtonBox" name="buttonBox"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> - <property name="title"> - <string>Status</string> - </property> - <layout class="QGridLayout" name="gridLayout_10"> - <item row="1" column="0"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Extracted Points:</string> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="label_38"> - <property name="text"> - <string>Camera Info:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLabel" name="pointinfo_label"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>120</width> - <height>15</height> - </size> - </property> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLabel" name="caminfo_label"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>120</width> - <height>15</height> - </size> - </property> - <property name="text"> - <string/> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="1" column="0"> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Expanding</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>0</height> - </size> - </property> - </spacer> - </item> - <item row="3" column="0"> - <widget class="QDialogButtonBox" name="buttonBox"> <property name="standardButtons"> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> </property> diff --git a/tracker-pt/ftnoir_tracker_pt_dialog.cpp b/tracker-pt/ftnoir_tracker_pt_dialog.cpp index ccedeb78..fa159d34 100644 --- a/tracker-pt/ftnoir_tracker_pt_dialog.cpp +++ b/tracker-pt/ftnoir_tracker_pt_dialog.cpp @@ -81,6 +81,18 @@ TrackerDialog_PT::TrackerDialog_PT() poll_tracker_info_impl(); connect(this, &TrackerDialog_PT::poll_tracker_info, this, &TrackerDialog_PT::poll_tracker_info_impl, Qt::DirectConnection); + + static constexpr pt_color_type color_types[] = { + pt_color_normal, + pt_color_floppy_filter, + pt_color_red_only, + }; + + static constexpr unsigned color_type_sz = sizeof(color_types) / sizeof(*color_types); + for (unsigned k = 0; k < color_type_sz; k++) + ui.blob_color->setItemData(k, int(color_types[k])); + + tie_setting(s.blob_color, ui.blob_color); } void TrackerDialog_PT::startstop_trans_calib(bool start) diff --git a/tracker-pt/ftnoir_tracker_pt_settings.h b/tracker-pt/ftnoir_tracker_pt_settings.h index 79c1e103..265d382e 100644 --- a/tracker-pt/ftnoir_tracker_pt_settings.h +++ b/tracker-pt/ftnoir_tracker_pt_settings.h @@ -11,6 +11,15 @@ #include "options/options.hpp" using namespace options; +enum pt_color_type +{ + // explicit values, gotta preserve the numbering in .ini + // don't reuse when removing some of the modes + pt_color_normal = 2, + pt_color_red_only = 3, + pt_color_floppy_filter = 4, +}; + struct settings_pt : opts { value<QString> camera_name; @@ -33,6 +42,7 @@ struct settings_pt : opts value<bool> dynamic_pose; value<int> init_phase_timeout; value<bool> auto_threshold; + value<pt_color_type> blob_color; settings_pt() : opts("tracker-pt"), @@ -63,6 +73,7 @@ struct settings_pt : opts fov(b, "camera-fov", 56), dynamic_pose(b, "dynamic-pose-resolution", true), init_phase_timeout(b, "init-phase-timeout", 250), - auto_threshold(b, "automatic-threshold", true) + auto_threshold(b, "automatic-threshold", true), + blob_color(b, "blob-color", pt_color_normal) {} }; diff --git a/tracker-pt/point_extractor.cpp b/tracker-pt/point_extractor.cpp index dc36fbe5..54514111 100644 --- a/tracker-pt/point_extractor.cpp +++ b/tracker-pt/point_extractor.cpp @@ -78,6 +78,28 @@ PointExtractor::PointExtractor() blobs.reserve(max_blobs); } +void PointExtractor::separate_channels(cv::Mat const& orig, const int* order, int order_npairs) +{ + if (unlikely(ch[0].rows != orig.rows || ch[0].cols != orig.cols)) + { + for (unsigned k = 0; k < 3; k++) + { + ch[k] = cv::Mat1b(orig.rows, orig.cols); + ch_float[k] = cv::Mat1f(orig.rows, orig.cols); + } + // extra channel is a scratch buffer + ch_float[3] = cv::Mat1f(orig.rows, orig.cols); + } + + if (order == nullptr) + cv::split(orig, (cv::Mat*) ch); + else + cv::mixChannels(&orig, 1, (cv::Mat*) ch, order_npairs, order, order_npairs); + + for (unsigned k = 0; k < 3; k++) + ch[k].convertTo(ch_float[k], CV_32F); +} + void PointExtractor::extract_points(const cv::Mat& frame, cv::Mat& preview_frame, std::vector<vec2>& points) { using std::sqrt; @@ -92,8 +114,60 @@ void PointExtractor::extract_points(const cv::Mat& frame, cv::Mat& preview_frame frame_blobs = cv::Mat1b(frame.rows, frame.cols); } - // convert to grayscale - cv::cvtColor(frame, frame_gray, cv::COLOR_BGR2GRAY); + const pt_color_type color = s.blob_color; + if (color == pt_color_normal) + { + // convert to grayscale + // this operation is optimized + cv::cvtColor(frame, frame_gray, cv::COLOR_BGR2GRAY); + } + else + { + switch (color) + { + case pt_color_floppy_filter: + { + // weight for blue color + static constexpr float B = .8; + // single channel weight + static constexpr float A = 1./2; + + static constexpr int from_to[] = { + 0, 0, + 1, 1 + }; + + separate_channels(frame, from_to, 2); + + ch_float[2] = ch_float[0] * B * A // blue + + ch_float[1] * (1 - B) * A; // green + ch_float[2].convertTo(frame_gray, CV_8U); + + break; + } + case pt_color_red_only: + { + static constexpr int from_to[] = { + 2, 0 + }; + + separate_channels(frame, from_to, 1); + + static constexpr float R = 3; + + ch_float[1] = ch_float[0] * R; // red + + ch_float[1].convertTo(frame_gray, CV_8U); + + break; + } + default: + once_only(qDebug() << "wrong pt_color_type enum value" << int(color)); + // don't violate POLA + cv::cvtColor(frame, frame_gray, cv::COLOR_BGR2GRAY); + break; + } + } const double region_size_min = s.min_point_size; const double region_size_max = s.max_point_size; diff --git a/tracker-pt/point_extractor.h b/tracker-pt/point_extractor.h index 5fbe9a45..193c06dc 100644 --- a/tracker-pt/point_extractor.h +++ b/tracker-pt/point_extractor.h @@ -46,8 +46,10 @@ private: cv::Mat frame_bin; cv::Mat hist; cv::Mat frame_blobs; - std::vector<blob> blobs; + cv::Mat ch[3], ch_float[4]; + + void separate_channels(cv::Mat const& orig_frame, int const* order = nullptr, int order_cnt = -1); }; } // ns impl diff --git a/tracker-pt/point_tracker.cpp b/tracker-pt/point_tracker.cpp index d2620dce..ae873ef6 100644 --- a/tracker-pt/point_tracker.cpp +++ b/tracker-pt/point_tracker.cpp @@ -33,7 +33,7 @@ static void set_row(mat33& m, int i, const vec3& v) m(i,2) = v[2]; } -PointModel::PointModel(settings_pt& s) +PointModel::PointModel(const settings_pt& s) { set_model(s); // calculate u @@ -47,7 +47,7 @@ PointModel::PointModel(settings_pt& s) P = 1/(s11*s22-s12*s12) * mat22(s22, -s12, -s12, s11); } -void PointModel::set_model(settings_pt& s) +void PointModel::set_model(const settings_pt& s) { switch (s.active_model_panel) { diff --git a/tracker-pt/point_tracker.h b/tracker-pt/point_tracker.h index ebbbc801..2b142632 100644 --- a/tracker-pt/point_tracker.h +++ b/tracker-pt/point_tracker.h @@ -42,8 +42,8 @@ struct PointModel final enum Model { Clip, Cap, Custom }; - PointModel(settings_pt& s); - void set_model(settings_pt& s); + PointModel(const settings_pt& s); + void set_model(const settings_pt& s); void get_d_order(const vec2* points, unsigned* d_order, const vec2& d) const; }; |