From 0081061e580c4933b0c7731496916df2cfc0a95c Mon Sep 17 00:00:00 2001 From: Tom Brazier Date: Wed, 31 May 2023 15:09:16 +0100 Subject: Added a slider to control the strength of the color matching for chroma key --- tracker-pt/FTNoIR_PT_Controls.ui | 449 +++++++++++++++++--------------- tracker-pt/ftnoir_tracker_pt_dialog.cpp | 22 +- tracker-pt/ftnoir_tracker_pt_dialog.h | 2 +- tracker-pt/lang/nl_NL.ts | 4 + tracker-pt/lang/ru_RU.ts | 4 + tracker-pt/lang/stub.ts | 4 + tracker-pt/lang/zh_CN.ts | 4 + tracker-pt/module/point_extractor.cpp | 18 +- tracker-pt/pt-settings.hpp | 1 + 9 files changed, 288 insertions(+), 220 deletions(-) diff --git a/tracker-pt/FTNoIR_PT_Controls.ui b/tracker-pt/FTNoIR_PT_Controls.ui index fc1e0392..02e696e3 100644 --- a/tracker-pt/FTNoIR_PT_Controls.ui +++ b/tracker-pt/FTNoIR_PT_Controls.ui @@ -10,7 +10,7 @@ 0 0 413 - 604 + 628 @@ -79,53 +79,86 @@ Camera settings - - + + - - + + 0 0 + + WhatsThisCursor + + + This should be 56° or 76° for the PS3 Eye, dependent upon the physical lens setting. It's only neccessary to get position correspond to real-world values. + - FPS + Diagonal field of view - - fps_spin + + + + + + + 0 + 0 + + + + Dynamic pose (for caps only, never clips) - - + + - + 0 0 + + WhatsThisCursor + - Desired capture width + <html><head/><body><p>For LEDs, 'Natural' is the fastest grayscale mode thanks to optimized SIMD code. Color key allows to track regular pieces of colored paper.</p></body></html> - - px + + Color channels used - - 2000 + + + + + + + 0 + 0 + - - 10 + + Open - - + + + + + + + + + 0 @@ -136,29 +169,78 @@ WhatsThisCursor - This should be 56° or 76° for the PS3 Eye, dependent upon the physical lens setting. It's only neccessary to get position correspond to real-world values. + Enable MJPEG compression for high-speed cameras other than the PS3 Eye. Windows only. - Diagonal field of view + MJPEG compression - - + + - + 0 0 - - Desired capture framerate + + FPS + + + fps_spin + + + + + + + + 0 + 0 + + + + Width + + + + + + + Chroma key includes overexposed pixels + + + + + + + + 0 + 0 + + + + Camera settings (when available) + + + + + + + + 0 + 0 + - Hz + ms + + + 50 - 2000 + 5000 @@ -175,21 +257,30 @@ - - + + 0 0 - - Open + + Desired capture width + + + px + + + 2000 + + + 10 - - + + 0 @@ -197,7 +288,7 @@ - Height + Dynamic pose timeout @@ -214,44 +305,51 @@ - - + + - + 0 0 - - ms + + Device - - 50 + + camdevice_combo - - 5000 + + + + + + + 0 + 0 + + + + Height - - + + 0 0 - - ° - - - + + Desired capture framerate - - 10 + + Hz - 90 + 2000 @@ -320,29 +418,25 @@ - - + + - + 0 0 - - Width + + ° - - - - - - - 0 - 0 - + + - - Camera settings (when available) + + 10 + + + 90 @@ -368,99 +462,45 @@ - - - - - 0 - 0 - - - - WhatsThisCursor - - - <html><head/><body><p>For LEDs, 'Natural' is the fastest grayscale mode thanks to optimized SIMD code. Color key allows to track regular pieces of colored paper.</p></body></html> - - - Color channels used - - - - - - - - 0 - 0 - - - - Dynamic pose (for caps only, never clips) - - - - - - - - 0 - 0 - - - - Device - - - camdevice_combo - - - - - - - - 0 - 0 - - - - Dynamic pose timeout - - - - - - - - 0 - 0 - - - - WhatsThisCursor - - - Enable MJPEG compression for high-speed cameras other than the PS3 Eye. Windows only. - - - MJPEG compression - - - - + - Chroma key includes overexposed pixels + Chroma key strength - - - - - + + + + + 5 + + + 40 + + + Qt::Horizontal + + + + + + + true + + + QAbstractSpinBox::NoButtons + + + 0.500000000000000 + + + 4.000000000000000 + + + + @@ -616,6 +656,26 @@ + + + + + 0 + 0 + + + + + + + + + + + Value + + + @@ -638,26 +698,6 @@ - - - - - 0 - 0 - - - - - - - - - - - Value - - - @@ -693,7 +733,7 @@ QTabWidget::Rounded - 0 + 2 false @@ -1649,55 +1689,55 @@ Don't roll or change position. Status - - + + - + 0 0 - Extracted Points: + - - + + - + 0 0 - Camera Info: + - - + + - + 0 0 - + Extracted Points: - - + + - + 0 0 - + Camera Info: @@ -1727,10 +1767,11 @@ Don't roll or change position. fps_spin use_mjpeg fov - dynamic_pose init_phase_timeout + dynamic_pose camera_settings blob_color + chroma_key_overexposed auto_threshold threshold_slider mindiam_spin @@ -1740,27 +1781,23 @@ Don't roll or change position. clip_theight_spin clip_bheight_spin clip_blength_spin + tx_spin + ty_spin + tz_spin + tcalib_button cap_length_spin cap_width_spin cap_height_spin m1x_spin - m1y_spin - m1z_spin m2x_spin + m1y_spin m2y_spin + m1z_spin m2z_spin - tx_spin - ty_spin - tz_spin - tcalib_button enable_point_filter point_filter_slider point_filter_limit_slider point_filter_deadzone_slider - maxdiam_spin - mindiam_spin - auto_threshold - threshold_slider diff --git a/tracker-pt/ftnoir_tracker_pt_dialog.cpp b/tracker-pt/ftnoir_tracker_pt_dialog.cpp index f3025a0c..d67f79a7 100644 --- a/tracker-pt/ftnoir_tracker_pt_dialog.cpp +++ b/tracker-pt/ftnoir_tracker_pt_dialog.cpp @@ -110,9 +110,15 @@ TrackerDialog_PT::TrackerDialog_PT(const QString& module_name) : tie_setting(s.blob_color, ui.blob_color); + tie_setting(s.chroma_key_strength, ui.chroma_key_strength_slider); + connect(&s.chroma_key_strength, value_::value_changed(), ui.chroma_key_strength_label, + [this] { ui.chroma_key_strength_label->setValue(*s.chroma_key_strength); }); + ui.chroma_key_strength_label->setValue(*s.chroma_key_strength); + tie_setting(s.chroma_key_overexposed, ui.chroma_key_overexposed); - connect(ui.blob_color, &QComboBox::currentTextChanged, this, &TrackerDialog_PT::chroma_key_overexp_enable); - chroma_key_overexp_enable(""); + connect(ui.blob_color, &QComboBox::currentTextChanged, this, &TrackerDialog_PT::chroma_key_controls_enable); + + chroma_key_controls_enable(""); tie_setting(s.threshold_slider, ui.threshold_value_display, [this](const slider_value& val) { return threshold_display_text(int(val)); @@ -252,16 +258,18 @@ void TrackerDialog_PT::show_camera_settings() (void)video::show_dialog(s.camera_name); } -void TrackerDialog_PT::chroma_key_overexp_enable(const QString&) +void TrackerDialog_PT::chroma_key_controls_enable(const QString&) { + bool enabled = false; QVariant data = ui.blob_color->currentData(); - if (!data.isValid()) - ui.chroma_key_overexposed->setEnabled(false); - else + if (data.isValid()) { pt_color_type blob_color = pt_color_type(data.toInt()); - ui.chroma_key_overexposed->setEnabled(blob_color >= pt_color_red_chromakey && blob_color <= pt_color_magenta_chromakey); + enabled = blob_color >= pt_color_red_chromakey && blob_color <= pt_color_magenta_chromakey; } + ui.chroma_key_strength_slider->setEnabled(enabled); + ui.chroma_key_strength_label->setEnabled(enabled); + ui.chroma_key_overexposed->setEnabled(enabled); } void TrackerDialog_PT::trans_calib_step() diff --git a/tracker-pt/ftnoir_tracker_pt_dialog.h b/tracker-pt/ftnoir_tracker_pt_dialog.h index ea631949..79cd91bd 100644 --- a/tracker-pt/ftnoir_tracker_pt_dialog.h +++ b/tracker-pt/ftnoir_tracker_pt_dialog.h @@ -39,7 +39,7 @@ public slots: void poll_tracker_info_impl(); void set_camera_settings_available(const QString& camera_name); void show_camera_settings(); - void chroma_key_overexp_enable(const QString&); + void chroma_key_controls_enable(const QString&); protected: QString threshold_display_text(int threshold_value); diff --git a/tracker-pt/lang/nl_NL.ts b/tracker-pt/lang/nl_NL.ts index 33542d79..fc44b0f1 100644 --- a/tracker-pt/lang/nl_NL.ts +++ b/tracker-pt/lang/nl_NL.ts @@ -308,6 +308,10 @@ Don't roll or change position. Chroma key includes overexposed pixels + + Chroma key strength + + pt_impl::TrackerDialog_PT diff --git a/tracker-pt/lang/ru_RU.ts b/tracker-pt/lang/ru_RU.ts index 7714689d..7ff4657e 100644 --- a/tracker-pt/lang/ru_RU.ts +++ b/tracker-pt/lang/ru_RU.ts @@ -313,6 +313,10 @@ ROLL или X/Y-смещения. Chroma key includes overexposed pixels + + Chroma key strength + + pt_impl::TrackerDialog_PT diff --git a/tracker-pt/lang/stub.ts b/tracker-pt/lang/stub.ts index 3c90c586..3dbe208d 100644 --- a/tracker-pt/lang/stub.ts +++ b/tracker-pt/lang/stub.ts @@ -308,6 +308,10 @@ Don't roll or change position. Chroma key includes overexposed pixels + + Chroma key strength + + pt_impl::TrackerDialog_PT diff --git a/tracker-pt/lang/zh_CN.ts b/tracker-pt/lang/zh_CN.ts index 43164b09..3519d719 100644 --- a/tracker-pt/lang/zh_CN.ts +++ b/tracker-pt/lang/zh_CN.ts @@ -308,6 +308,10 @@ Don't roll or change position. Chroma key includes overexposed pixels + + Chroma key strength + + pt_impl::TrackerDialog_PT diff --git a/tracker-pt/module/point_extractor.cpp b/tracker-pt/module/point_extractor.cpp index f62ea836..11a12d5e 100644 --- a/tracker-pt/module/point_extractor.cpp +++ b/tracker-pt/module/point_extractor.cpp @@ -167,32 +167,38 @@ void PointExtractor::color_to_grayscale(const cv::Mat& frame, cv::Mat1b& output) } case pt_color_red_chromakey: { - filter_single_channel(frame, 1, -0.5, -0.5, s.chroma_key_overexposed, output); + float non_key_coeff = -0.5 * *s.chroma_key_strength; + filter_single_channel(frame, 1, non_key_coeff, non_key_coeff, s.chroma_key_overexposed, output); break; } case pt_color_green_chromakey: { - filter_single_channel(frame, -0.5, 1, -0.5, s.chroma_key_overexposed, output); + float non_key_coeff = -0.5 * *s.chroma_key_strength; + filter_single_channel(frame, non_key_coeff, 1, non_key_coeff, s.chroma_key_overexposed, output); break; } case pt_color_blue_chromakey: { - filter_single_channel(frame, -0.5, -0.5, 1, s.chroma_key_overexposed, output); + float non_key_coeff = -0.5 * *s.chroma_key_strength; + filter_single_channel(frame, non_key_coeff, non_key_coeff, 1, s.chroma_key_overexposed, output); break; } case pt_color_cyan_chromakey: { - filter_single_channel(frame, -1, 0.5, 0.5, s.chroma_key_overexposed, output); + float non_key_coeff = -1.0 * *s.chroma_key_strength; + filter_single_channel(frame, non_key_coeff, 0.5, 0.5, s.chroma_key_overexposed, output); break; } case pt_color_yellow_chromakey: { - filter_single_channel(frame, 0.5, 0.5, -1, s.chroma_key_overexposed, output); + float non_key_coeff = -1.0 * *s.chroma_key_strength; + filter_single_channel(frame, 0.5, 0.5, non_key_coeff, s.chroma_key_overexposed, output); break; } case pt_color_magenta_chromakey: { - filter_single_channel(frame, 0.5, -1, 0.5, s.chroma_key_overexposed, output); + float non_key_coeff = -1.0 * *s.chroma_key_strength; + filter_single_channel(frame, 0.5, non_key_coeff, 0.5, s.chroma_key_overexposed, output); break; } case pt_color_hardware: diff --git a/tracker-pt/pt-settings.hpp b/tracker-pt/pt-settings.hpp index 29bb348f..5d16d973 100644 --- a/tracker-pt/pt-settings.hpp +++ b/tracker-pt/pt-settings.hpp @@ -65,6 +65,7 @@ struct pt_settings final : options::opts value auto_threshold { b, "automatic-threshold", true }; value blob_color { b, "blob-color", pt_color_bt709 }; value use_mjpeg { b, "use-mjpeg", false }; + value chroma_key_strength{ b, "chroma-key-strength", { 1.0, 0.5, 4. } }; value chroma_key_overexposed{ b, "chroma-key-overexposed", false }; value threshold_slider { b, "threshold-slider", { 128, 0, 255 } }; -- cgit v1.2.3