diff options
Diffstat (limited to 'tracker-pt/ftnoir_tracker_pt_dialog.cpp')
| -rw-r--r-- | tracker-pt/ftnoir_tracker_pt_dialog.cpp | 208 |
1 files changed, 161 insertions, 47 deletions
diff --git a/tracker-pt/ftnoir_tracker_pt_dialog.cpp b/tracker-pt/ftnoir_tracker_pt_dialog.cpp index 98e8e424..d67f79a7 100644 --- a/tracker-pt/ftnoir_tracker_pt_dialog.cpp +++ b/tracker-pt/ftnoir_tracker_pt_dialog.cpp @@ -7,28 +7,39 @@ */ #include "ftnoir_tracker_pt_dialog.h" -#include "cv/video-property-page.hpp" +#include "compat/math.hpp" +#include "video/camera.hpp" -#include "compat/camera-names.hpp" -#include <opencv2/core.hpp> #include <QString> +#include <QtGlobal> #include <QDebug> -TrackerDialog_PT::TrackerDialog_PT() - : tracker(nullptr), - timer(this), - trans_calib(1, 2, 0) +using namespace options; + +static void init_resources() { Q_INIT_RESOURCE(tracker_pt_base); } + +namespace pt_impl { + +TrackerDialog_PT::TrackerDialog_PT(const QString& module_name) : + s(module_name), + tracker(nullptr), + timer(this), + trans_calib(1, 2) { + init_resources(); + ui.setupUi(this); - ui.camdevice_combo->addItems(get_camera_names()); + for (const QString& str : video::camera_names()) + ui.camdevice_combo->addItem(str); tie_setting(s.camera_name, ui.camdevice_combo); tie_setting(s.cam_res_x, ui.res_x_spin); tie_setting(s.cam_res_y, ui.res_y_spin); tie_setting(s.cam_fps, ui.fps_spin); + tie_setting(s.use_mjpeg, ui.use_mjpeg); - tie_setting(s.threshold, ui.threshold_slider); + tie_setting(s.threshold_slider, ui.threshold_slider); tie_setting(s.min_point_size, ui.mindiam_spin); tie_setting(s.max_point_size, ui.maxdiam_spin); @@ -63,7 +74,7 @@ TrackerDialog_PT::TrackerDialog_PT() tie_setting(s.auto_threshold, ui.auto_threshold); - connect( ui.tcalib_button,SIGNAL(toggled(bool)), this,SLOT(startstop_trans_calib(bool))); + connect(ui.tcalib_button,SIGNAL(toggled(bool)), this, SLOT(startstop_trans_calib(bool))); connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); @@ -76,15 +87,94 @@ TrackerDialog_PT::TrackerDialog_PT() timer.setInterval(250); connect(&calib_timer, &QTimer::timeout, this, &TrackerDialog_PT::trans_calib_step); - calib_timer.setInterval(100); + calib_timer.setInterval(35); poll_tracker_info_impl(); - connect(this, &TrackerDialog_PT::poll_tracker_info, this, &TrackerDialog_PT::poll_tracker_info_impl, Qt::QueuedConnection); + constexpr pt_color_type color_types[] = { + pt_color_bt709, + pt_color_hardware, + pt_color_red_only, + pt_color_green_only, + pt_color_blue_only, + pt_color_red_chromakey, + pt_color_green_chromakey, + pt_color_blue_chromakey, + pt_color_cyan_chromakey, + pt_color_yellow_chromakey, + pt_color_magenta_chromakey, + }; + + for (unsigned k = 0; k < std::size(color_types); k++) + ui.blob_color->setItemData(k, int(color_types[k])); + + 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<slider_value>(), 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_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)); + }); + + // refresh threshold display on auto-threshold checkbox state change + tie_setting(s.auto_threshold, this, [this](bool) { s.threshold_slider.notify_(); }); + + tie_setting(s.enable_point_filter, ui.enable_point_filter); + tie_setting(s.point_filter_coefficient, ui.point_filter_slider); + tie_setting(s.point_filter_limit, ui.point_filter_limit_slider); + connect(&s.point_filter_coefficient, value_::value_changed<slider_value>(), + ui.point_filter_label, [this] { ui.point_filter_label->setValue(*s.point_filter_coefficient); } ); + connect(&s.point_filter_limit, value_::value_changed<slider_value>(), ui.point_filter_limit_label, + [this] { ui.point_filter_limit_label->setValue(*s.point_filter_limit); }, Qt::QueuedConnection); + ui.point_filter_label->setValue(*s.point_filter_coefficient); + ui.point_filter_limit_label->setValue(*s.point_filter_limit); + + tie_setting(s.point_filter_deadzone, ui.point_filter_deadzone_slider); + ui.point_filter_deadzone_label->setValue(*s.point_filter_deadzone); + + connect(&s.point_filter_deadzone, value_::value_changed<slider_value>(), ui.point_filter_deadzone_label, + [this] { ui.point_filter_deadzone_label->setValue(*s.point_filter_deadzone); }, Qt::QueuedConnection); +} + +QString TrackerDialog_PT::threshold_display_text(int threshold_value) +{ + if (!s.auto_threshold) + return tr("Brightness %1/255").arg(threshold_value); + else + { + pt_camera_info info; + int w = s.cam_res_x, h = s.cam_res_y; + + if (w * h <= 0) + { + w = 640; + h = 480; + } + + if (tracker && tracker->get_cam_info(info) && info.res_x * info.res_y != 0) + { + w = info.res_x; + h = info.res_y; + } + + double value = (double)pt_point_extractor::threshold_radius_value(w, h, threshold_value); + + return tr("LED radius %1 pixels").arg(value, 0, 'f', 2); + } } void TrackerDialog_PT::startstop_trans_calib(bool start) { + QMutexLocker l(&calibrator_mutex); + if (start) { qDebug() << "pt: starting translation calibration"; @@ -101,17 +191,28 @@ void TrackerDialog_PT::startstop_trans_calib(bool start) calib_timer.stop(); qDebug() << "pt: stopping translation calibration"; { - cv::Vec3f tmp; - unsigned nsamples; - std::tie(tmp, nsamples) = trans_calib.get_estimate(); + auto [tmp, nsamples] = trans_calib.get_estimate(); s.t_MH_x = int(tmp[0]); s.t_MH_y = int(tmp[1]); s.t_MH_z = int(tmp[2]); - static constexpr unsigned min_samples = 80; - const QString sample_feedback = nsamples >= min_samples - ? tr("%1 samples. Over %2, good!").arg(nsamples).arg(min_samples) - : tr("%1 samples. Try for at least %2 for a precise calibration.").arg(nsamples).arg(min_samples); + constexpr int min_yaw_samples = 15; + constexpr int min_pitch_samples = 15; + constexpr int min_samples = min_yaw_samples+min_pitch_samples; + + // Don't bother counting roll samples. Roll calibration is hard enough + // that it's a hidden unsupported feature anyway. + + QString sample_feedback; + if (nsamples[0] < min_yaw_samples) + sample_feedback = tr("%1 yaw samples. Yaw more to %2 samples for stable calibration.").arg(nsamples[0]).arg(min_yaw_samples); + else if (nsamples[1] < min_pitch_samples) + sample_feedback = tr("%1 pitch samples. Pitch more to %2 samples for stable calibration.").arg(nsamples[1]).arg(min_pitch_samples); + else + { + const int nsamples_total = nsamples[0] + nsamples[1]; + sample_feedback = tr("%1 samples. Over %2, good!").arg(nsamples_total).arg(min_samples); + } ui.sample_count_display->setText(sample_feedback); } @@ -119,18 +220,17 @@ void TrackerDialog_PT::startstop_trans_calib(bool start) ui.tx_spin->setEnabled(!start); ui.ty_spin->setEnabled(!start); ui.tz_spin->setEnabled(!start); - ui.tcalib_button->setText(progn( - if (start) - return tr("Stop calibration"); - else - return tr("Start calibration"); - )); + + if (start) + ui.tcalib_button->setText(tr("Stop calibration")); + else + ui.tcalib_button->setText(tr("Start calibration")); } void TrackerDialog_PT::poll_tracker_info_impl() { - CamInfo info; - if (tracker && tracker->get_cam_info(&info)) + pt_camera_info info; + if (tracker && tracker->get_cam_info(info)) { ui.caminfo_label->setText(tr("%1x%2 @ %3 FPS").arg(info.res_x).arg(info.res_y).arg(iround(info.fps))); @@ -145,35 +245,37 @@ void TrackerDialog_PT::poll_tracker_info_impl() } } -void TrackerDialog_PT::set_camera_settings_available(const QString& camera_name) +void TrackerDialog_PT::set_camera_settings_available(const QString& /* camera_name */) { - const bool avail = video_property_page::should_show_dialog(camera_name); - ui.camera_settings->setEnabled(avail); + ui.camera_settings->setEnabled(true); } void TrackerDialog_PT::show_camera_settings() { - const int idx = ui.camdevice_combo->currentIndex(); - if (tracker) - { - if (tracker->camera) - { - cv::VideoCapture& cap = *tracker->camera; + tracker->open_camera_dialog_flag = true; + else + (void)video::show_dialog(s.camera_name); +} - CamInfo info; - bool status; - std::tie(status, info) = tracker->camera.get_info(); - if (status) - video_property_page::show_from_capture(cap, info.idx); - } +void TrackerDialog_PT::chroma_key_controls_enable(const QString&) +{ + bool enabled = false; + QVariant data = ui.blob_color->currentData(); + if (data.isValid()) + { + pt_color_type blob_color = pt_color_type(data.toInt()); + enabled = blob_color >= pt_color_red_chromakey && blob_color <= pt_color_magenta_chromakey; } - else - video_property_page::show(idx); + 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() { + QMutexLocker l(&calibrator_mutex); + if (tracker) { Affine X_CM = tracker->pose(); @@ -203,14 +305,26 @@ void TrackerDialog_PT::register_tracker(ITracker *t) { tracker = static_cast<Tracker_PT*>(t); ui.tcalib_button->setEnabled(true); - poll_tracker_info(); + poll_tracker_info_impl(); timer.start(); } void TrackerDialog_PT::unregister_tracker() { - tracker = NULL; + tracker = nullptr; ui.tcalib_button->setEnabled(false); - poll_tracker_info(); + poll_tracker_info_impl(); timer.stop(); } + +void TrackerDialog_PT::set_buttons_visible(bool x) +{ + ui.buttonBox->setVisible(x); +} + +void TrackerDialog_PT::reload() +{ + s.b->reload(); +} + +} // ns pt_impl |
