diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-07-16 23:44:31 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-07-16 23:54:27 +0200 |
commit | 754ae1a54132eb41332267fc70a42595017c5a6e (patch) | |
tree | 78e3dc7284d396f22d69230661176218f73f18f7 /tracker-aruco | |
parent | 16bb3e13dd2a7ed8fa3652e313d592dd81c73a07 (diff) |
gui, tracker/{aruco,pt}, api: detect whether widget is visible on screen
Sadly, it's only implemented right now on win32.
Remove "set enabled" code for the video widget since it only works for
explicit window minimization, not covering by other windows.
Diffstat (limited to 'tracker-aruco')
-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 |
6 files changed, 108 insertions, 109 deletions
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; +}; |