diff options
-rw-r--r-- | gui/ui.cpp | 28 | ||||
-rw-r--r-- | gui/ui.h | 5 | ||||
-rw-r--r-- | opentrack/is-window-visible.hpp | 26 | ||||
-rw-r--r-- | tracker-aruco/ar_video_widget.cpp | 69 | ||||
-rw-r--r-- | tracker-aruco/ar_video_widget.h | 35 | ||||
-rw-r--r-- | tracker-aruco/ftnoir_tracker_aruco.cpp | 8 | ||||
-rw-r--r-- | tracker-aruco/ftnoir_tracker_aruco.h | 4 | ||||
-rw-r--r-- | tracker-aruco/pt_video_widget.cpp | 63 | ||||
-rw-r--r-- | tracker-aruco/pt_video_widget.h | 38 | ||||
-rw-r--r-- | tracker-pt/pt_video_widget.cpp | 29 | ||||
-rw-r--r-- | tracker-pt/pt_video_widget.h | 18 |
11 files changed, 161 insertions, 162 deletions
@@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2015, Stanislaw Halik <sthalik@misaki.pl> +/* Copyright (c) 2013-2016, Stanislaw Halik <sthalik@misaki.pl> * Permission to use, copy, modify, and/or distribute this * software for any purpose with or without fee is hereby granted, @@ -124,8 +124,6 @@ MainWindow::MainWindow() : register_shortcuts(); - connect(this, &MainWindow::emit_minimized, this, &MainWindow::mark_minimized, Qt::QueuedConnection); - ui.btnStartTracker->setFocus(); } @@ -558,30 +556,6 @@ void MainWindow::restore_from_tray(QSystemTrayIcon::ActivationReason) activateWindow(); // for Windows } -void MainWindow::changeEvent(QEvent* e) -{ - if (e->type() == QEvent::WindowStateChange) - { - const bool is_minimized = windowState() & Qt::WindowMinimized; - - if (s.tray_enabled && is_minimized) - { - if (!tray) - ensure_tray(); - hide(); - } - - emit_minimized(is_minimized); - } - - QMainWindow::changeEvent(e); -} - -void MainWindow::mark_minimized(bool is_minimized) -{ - ui.video_frame->setEnabled(!is_minimized); -} - void MainWindow::maybe_start_profile_from_executable() { if (!work) @@ -69,8 +69,6 @@ class MainWindow : public QMainWindow, private State return modules.filters().value(ui.iconcomboFilter->currentIndex(), nullptr); } - void changeEvent(QEvent* e) override; - void load_settings(); void load_mappings(); void updateButtonState(bool running, bool inertialp); @@ -104,14 +102,11 @@ private slots: void startTracker(); void stopTracker(); void reload_options(); - void mark_minimized(bool is_minimized); signals: void emit_start_tracker(); void emit_stop_tracker(); void emit_toggle_tracker(); void emit_restart_tracker(); - - void emit_minimized(bool); public: MainWindow(); ~MainWindow(); diff --git a/opentrack/is-window-visible.hpp b/opentrack/is-window-visible.hpp new file mode 100644 index 00000000..300e541a --- /dev/null +++ b/opentrack/is-window-visible.hpp @@ -0,0 +1,26 @@ +#ifdef _WIN32 + +#include <windows.h> +#include <QWidget> +#include <QRect> +#include <QDebug> + +template<typename=void> +bool is_window_visible(const QWidget* widget) +{ + const QWidget* window = widget->window(); + + if (!window) + return true; + + const QPoint p = widget->mapToGlobal(widget->pos()); + const QSize s = widget->size(); + POINT pt = { p.x() + s.width()/2, p.y() + s.height()/2 }; + + return WindowFromPoint(pt) == (HWND) widget->winId(); +} + +#else +template<typename=void> +bool is_window_visible(const QWidget* widget) { return true; } +#endif diff --git a/tracker-aruco/ar_video_widget.cpp b/tracker-aruco/ar_video_widget.cpp deleted file mode 100644 index 2e87fdca..00000000 --- a/tracker-aruco/ar_video_widget.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright (c) 2014 Stanislaw Halik - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - */ - -#include "ar_video_widget.h" - -void ArucoVideoWidget::update_image(const cv::Mat& frame) -{ - QMutexLocker foo(&mtx); - if (!fresh) - { - _frame = frame.clone(); - fresh = true; - } -} - -void ArucoVideoWidget::update_and_repaint() -{ - QImage qframe; - - { - QMutexLocker foo(&mtx); - if (_frame.cols*_frame.rows <= 0 || !fresh) - return; - fresh = false; - qframe = QImage(_frame.cols, _frame.rows, QImage::Format_RGB888); - uchar* data = qframe.bits(); - const unsigned pitch = qframe.bytesPerLine(); - unsigned char *input = _frame.data; - const unsigned chans = _frame.channels(); - const unsigned rows = _frame.rows, cols = _frame.cols; - const unsigned step = _frame.step; - for (unsigned y = 0; y < rows; y++) - { - const unsigned step_ = y * step; - const unsigned pitch_ = y * pitch; - for (unsigned x = 0; x < cols; x++) - { - data[pitch_ + x * 3 + 0] = input[step_ + x * chans + 2]; - data[pitch_ + x * 3 + 1] = input[step_ + x * chans + 1]; - data[pitch_ + x * 3 + 2] = input[step_ + x * chans + 0]; - } - } - } - - qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation); - - { - QMutexLocker foo(&mtx); - texture = qframe; - } - - update(); -} - -void ArucoVideoWidget::paintEvent(QPaintEvent* e) -{ - QMutexLocker foo(&mtx); - QPainter(this).drawImage(e->rect(), texture); -} - -ArucoVideoWidget::ArucoVideoWidget(QWidget* parent): QWidget(parent), fresh(false) -{ - connect(&timer, SIGNAL(timeout()), this, SLOT(update_and_repaint())); - timer.start(60); -} diff --git a/tracker-aruco/ar_video_widget.h b/tracker-aruco/ar_video_widget.h deleted file mode 100644 index ea14dfbf..00000000 --- a/tracker-aruco/ar_video_widget.h +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright (c) 2014 Stanislaw Halik - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - */ - -#pragma once - -#include <QTimer> -#include <QWidget> -#include <QMutex> -#include <QMutexLocker> -#include <QPainter> -#include <QPaintEvent> -#include <opencv2/core.hpp> -#include <opencv2/imgproc.hpp> -#include <opencv2/calib3d.hpp> - -class ArucoVideoWidget : public QWidget -{ - Q_OBJECT -private: - QMutex mtx; - QImage texture; - QTimer timer; - cv::Mat _frame; - bool fresh; -private slots: - void update_and_repaint(); -public: - ArucoVideoWidget(QWidget *parent); - void update_image(const cv::Mat& frame); - void paintEvent( QPaintEvent*) override; -}; diff --git a/tracker-aruco/ftnoir_tracker_aruco.cpp b/tracker-aruco/ftnoir_tracker_aruco.cpp index b078affc..de26c420 100644 --- a/tracker-aruco/ftnoir_tracker_aruco.cpp +++ b/tracker-aruco/ftnoir_tracker_aruco.cpp @@ -7,9 +7,11 @@ #include "ftnoir_tracker_aruco.h" #include "opentrack/plugin-api.hpp" -#include <opencv2/core/core.hpp> -#include <opencv2/highgui/highgui.hpp> +#include <opencv2/core.hpp> +#include <opencv2/highgui.hpp> #include <opencv2/videoio.hpp> +#include <opencv2/imgproc.hpp> +#include <opencv2/calib3d.hpp> #include "opentrack-compat/camera-names.hpp" #include "opentrack-compat/sleep.hpp" @@ -71,7 +73,7 @@ Tracker::~Tracker() void Tracker::start_tracker(QFrame* videoframe) { videoframe->show(); - videoWidget = new ArucoVideoWidget(videoframe); + videoWidget = new PTVideoWidget(videoframe); QHBoxLayout* layout_ = new QHBoxLayout(); layout_->setContentsMargins(0, 0, 0, 0); layout_->addWidget(videoWidget); diff --git a/tracker-aruco/ftnoir_tracker_aruco.h b/tracker-aruco/ftnoir_tracker_aruco.h index 94a96e4c..a8032067 100644 --- a/tracker-aruco/ftnoir_tracker_aruco.h +++ b/tracker-aruco/ftnoir_tracker_aruco.h @@ -8,7 +8,7 @@ #pragma once #include "ui_aruco-trackercontrols.h" -#include "ar_video_widget.h" +#include "pt_video_widget.h" #include "opentrack-compat/options.hpp" #include "trans_calib.h" #include "opentrack/plugin-api.hpp" @@ -79,7 +79,7 @@ private: QMutex mtx; volatile bool stop; QHBoxLayout* layout; - ArucoVideoWidget* videoWidget; + PTVideoWidget* videoWidget; settings s; double pose[6]; cv::Mat frame, grayscale, color; diff --git a/tracker-aruco/pt_video_widget.cpp b/tracker-aruco/pt_video_widget.cpp new file mode 100644 index 00000000..38d7a5e8 --- /dev/null +++ b/tracker-aruco/pt_video_widget.cpp @@ -0,0 +1,63 @@ +/* Copyright (c) 2012 Patrick Ruoff + * Copyright (c) 2014-2016 Stanislaw Halik <sthalik@misaki.pl> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ + +#include "pt_video_widget.h" +#include <opencv2/imgproc.hpp> + +#include "opentrack/is-window-visible.hpp" + +PTVideoWidget::PTVideoWidget(QWidget* parent) : + QWidget(parent), + freshp(false) +{ + connect(&timer, SIGNAL(timeout()), this, SLOT(update_and_repaint())); + timer.start(50); +} + +void PTVideoWidget::update_image(const cv::Mat& frame) +{ + QMutexLocker foo(&mtx); + + if (!freshp) + { + if (_frame.cols != frame.cols || _frame.rows != frame.rows) + { + _frame = cv::Mat(frame.rows, frame.cols, CV_8U); + _frame2 = cv::Mat(frame.rows, frame.cols, CV_8U); + } + frame.copyTo(_frame); + freshp = true; + } +} + +void PTVideoWidget::paintEvent(QPaintEvent* e) +{ + QMutexLocker foo(&mtx); + QPainter painter(this); + painter.drawImage(e->rect(), texture); +} + +void PTVideoWidget::update_and_repaint() +{ + if (is_window_visible(this)) + { + QMutexLocker foo(&mtx); + if (_frame.empty() || !freshp) + return; + cv::cvtColor(_frame, _frame2, cv::COLOR_RGB2BGR); + + if (_frame3.cols != width() || _frame3.rows != height()) + _frame3 = cv::Mat(height(), width(), CV_8U); + + cv::resize(_frame2, _frame3, cv::Size(width(), height()), 0, 0, cv::INTER_NEAREST); + + texture = QImage((const unsigned char*) _frame3.data, _frame3.cols, _frame3.rows, QImage::Format_RGB888); + freshp = false; + update(); + } +} diff --git a/tracker-aruco/pt_video_widget.h b/tracker-aruco/pt_video_widget.h new file mode 100644 index 00000000..c2957876 --- /dev/null +++ b/tracker-aruco/pt_video_widget.h @@ -0,0 +1,38 @@ +/* Copyright (c) 2012 Patrick Ruoff + * Copyright (c) 2014-2016 Stanislaw Halik <sthalik@misaki.pl> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ + +#pragma once + +#include <QObject> +#include <QWidget> +#include <opencv2/core/core.hpp> +#include <memory> +#include <QPainter> +#include <QPaintEvent> +#include <QTimer> +#include <QMutex> +#include <QMutexLocker> +#include <QDebug> + +class PTVideoWidget final : public QWidget +{ + Q_OBJECT + +public: + PTVideoWidget(QWidget *parent); + void update_image(const cv::Mat &frame); +protected slots: + void paintEvent(QPaintEvent* e) override; + void update_and_repaint(); +private: + QMutex mtx; + QImage texture; + QTimer timer; + cv::Mat _frame, _frame2, _frame3; + bool freshp; +}; diff --git a/tracker-pt/pt_video_widget.cpp b/tracker-pt/pt_video_widget.cpp index 99f86eb2..38d7a5e8 100644 --- a/tracker-pt/pt_video_widget.cpp +++ b/tracker-pt/pt_video_widget.cpp @@ -1,20 +1,28 @@ /* Copyright (c) 2012 Patrick Ruoff - * Copyright (c) 2015 Stanislaw Halik <sthalik@misaki.pl> + * Copyright (c) 2014-2016 Stanislaw Halik <sthalik@misaki.pl> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. - * - * 20130312, WVR: Add 7 lines to resizeGL after resize_frame. This should lower CPU-load. */ #include "pt_video_widget.h" #include <opencv2/imgproc.hpp> +#include "opentrack/is-window-visible.hpp" + +PTVideoWidget::PTVideoWidget(QWidget* parent) : + QWidget(parent), + freshp(false) +{ + connect(&timer, SIGNAL(timeout()), this, SLOT(update_and_repaint())); + timer.start(50); +} + void PTVideoWidget::update_image(const cv::Mat& frame) { QMutexLocker foo(&mtx); - + if (!freshp) { if (_frame.cols != frame.cols || _frame.rows != frame.rows) @@ -27,20 +35,27 @@ void PTVideoWidget::update_image(const cv::Mat& frame) } } +void PTVideoWidget::paintEvent(QPaintEvent* e) +{ + QMutexLocker foo(&mtx); + QPainter painter(this); + painter.drawImage(e->rect(), texture); +} + void PTVideoWidget::update_and_repaint() { - if (static_cast<QWidget*>(parent())->isEnabled()) + if (is_window_visible(this)) { QMutexLocker foo(&mtx); if (_frame.empty() || !freshp) return; cv::cvtColor(_frame, _frame2, cv::COLOR_RGB2BGR); - + if (_frame3.cols != width() || _frame3.rows != height()) _frame3 = cv::Mat(height(), width(), CV_8U); cv::resize(_frame2, _frame3, cv::Size(width(), height()), 0, 0, cv::INTER_NEAREST); - + texture = QImage((const unsigned char*) _frame3.data, _frame3.cols, _frame3.rows, QImage::Format_RGB888); freshp = false; update(); diff --git a/tracker-pt/pt_video_widget.h b/tracker-pt/pt_video_widget.h index d9144ac0..c2957876 100644 --- a/tracker-pt/pt_video_widget.h +++ b/tracker-pt/pt_video_widget.h @@ -1,5 +1,5 @@ /* Copyright (c) 2012 Patrick Ruoff - * Copyright (c) 2014 Stanislaw Halik <sthalik@misaki.pl> + * Copyright (c) 2014-2016 Stanislaw Halik <sthalik@misaki.pl> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -19,25 +19,15 @@ #include <QMutexLocker> #include <QDebug> -class PTVideoWidget : public QWidget +class PTVideoWidget final : public QWidget { Q_OBJECT public: - PTVideoWidget(QWidget *parent) : - QWidget(parent), - freshp(false) - { - connect(&timer, SIGNAL(timeout()), this, SLOT(update_and_repaint())); - timer.start(50); - } + PTVideoWidget(QWidget *parent); void update_image(const cv::Mat &frame); protected slots: - void paintEvent( QPaintEvent* e ) { - QMutexLocker foo(&mtx); - QPainter painter(this); - painter.drawImage(e->rect(), texture); - } + void paintEvent(QPaintEvent* e) override; void update_and_repaint(); private: QMutex mtx; |