From 864910a1fb753629d2852a91ffae4ebba374358c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 15 Oct 2013 08:52:25 +0200 Subject: fix trackers for qt5 Assorted changes: - make filenames unique, since automoc made a boo-boo - adjust include paths, "QtGui" -> "" - use std::shared_ptr in c++11 mode (thanks Patrick!) - make class names unique, automoc sucks, but saves typing - add a dummy class in one file since moronic automoc thinks every target contains Q_OBJECTS!!! --- FTNoIR_Tracker_PT/boost-compat.h | 3 +- FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp | 6 +- FTNoIR_Tracker_PT/ftnoir_tracker_pt.h | 9 +- FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h | 2 +- FTNoIR_Tracker_PT/pt_video_widget.cpp | 52 ++++++++ FTNoIR_Tracker_PT/pt_video_widget.h | 64 ++++++++++ FTNoIR_Tracker_PT/video_widget.cpp | 145 ----------------------- FTNoIR_Tracker_PT/video_widget.h | 95 --------------- compat/qt-bug-appeasement.cpp | 1 + facetracknoir/qt-moc.h | 10 ++ ftnoir_protocol_fg/ftnoir_protocol_fg_dialog.cpp | 1 + ftnoir_tracker_aruco/ar_video_widget.cpp | 30 +++++ ftnoir_tracker_aruco/ar_video_widget.h | 39 ++++++ ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp | 2 +- ftnoir_tracker_aruco/ftnoir_tracker_aruco.h | 5 +- ftnoir_tracker_aruco/video_widget.cpp | 30 ----- ftnoir_tracker_aruco/video_widget.h | 39 ------ ftnoir_tracker_ht/ftnoir_tracker_ht.cpp | 2 +- ftnoir_tracker_ht/ftnoir_tracker_ht.h | 4 +- ftnoir_tracker_ht/ht_video_widget.cpp | 30 +++++ ftnoir_tracker_ht/ht_video_widget.h | 39 ++++++ ftnoir_tracker_ht/video_widget.cpp | 30 ----- ftnoir_tracker_ht/video_widget.h | 39 ------ 23 files changed, 280 insertions(+), 397 deletions(-) create mode 100644 FTNoIR_Tracker_PT/pt_video_widget.cpp create mode 100644 FTNoIR_Tracker_PT/pt_video_widget.h delete mode 100644 FTNoIR_Tracker_PT/video_widget.cpp delete mode 100644 FTNoIR_Tracker_PT/video_widget.h create mode 100644 compat/qt-bug-appeasement.cpp create mode 100644 facetracknoir/qt-moc.h create mode 100644 ftnoir_tracker_aruco/ar_video_widget.cpp create mode 100644 ftnoir_tracker_aruco/ar_video_widget.h delete mode 100644 ftnoir_tracker_aruco/video_widget.cpp delete mode 100644 ftnoir_tracker_aruco/video_widget.h create mode 100644 ftnoir_tracker_ht/ht_video_widget.cpp create mode 100644 ftnoir_tracker_ht/ht_video_widget.h delete mode 100644 ftnoir_tracker_ht/video_widget.cpp delete mode 100644 ftnoir_tracker_ht/video_widget.h diff --git a/FTNoIR_Tracker_PT/boost-compat.h b/FTNoIR_Tracker_PT/boost-compat.h index aea5e1a2..b5be237a 100644 --- a/FTNoIR_Tracker_PT/boost-compat.h +++ b/FTNoIR_Tracker_PT/boost-compat.h @@ -1,6 +1,5 @@ #pragma once #include -#define shared_ptr auto_ptr namespace boost { - using std::auto_ptr; + using std::shared_ptr; }; diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp index d4741101..745d98e9 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp @@ -12,10 +12,6 @@ #include #include -#ifdef OPENTRACK_API -# define VideoWidget VideoWidget2 -#endif - using namespace std; using namespace cv; using namespace boost; @@ -192,7 +188,7 @@ void Tracker::update_show_video_widget() { const int VIDEO_FRAME_WIDTH = 252; const int VIDEO_FRAME_HEIGHT = 189; - video_widget = new VideoWidget(video_frame, this); + video_widget = new PTVideoWidget(video_frame, this); QHBoxLayout* video_layout = new QHBoxLayout(); video_layout->setContentsMargins(0, 0, 0, 0); video_layout->addWidget(video_widget); diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h index 7dcfc8bb..2430f5f0 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h @@ -11,15 +11,13 @@ #ifdef OPENTRACK_API # include "ftnoir_tracker_base/ftnoir_tracker_base.h" # include "facetracknoir/global-settings.h" -#else -# include "..\ftnoir_tracker_base\ftnoir_tracker_base.h" #endif #include "ftnoir_tracker_pt_settings.h" #include "frame_observer.h" #include "camera.h" #include "point_extractor.h" #include "point_tracker.h" -#include "video_widget.h" +#include "pt_video_widget.h" #include "timer.h" #include @@ -82,7 +80,6 @@ protected: // --- tracking chain --- #ifdef OPENTRACK_API -#define VideoWidget VideoWidget2 CVCamera camera; #else VICamera camera; @@ -101,7 +98,9 @@ protected: void update_show_video_widget(); bool show_video_widget; - VideoWidget* video_widget; +#ifdef OPENTRACK_API + PTVideoWidget* video_widget; +#endif QFrame* video_frame; // --- misc --- diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h index 14df7ede..3e1af50a 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h @@ -16,7 +16,7 @@ #include "ftnoir_tracker_pt_settings.h" #include "ftnoir_tracker_pt.h" #include "trans_calib.h" -#include "video_widget.h" +#include "pt_video_widget.h" #include "ui_FTNoIR_PT_Controls.h" #include diff --git a/FTNoIR_Tracker_PT/pt_video_widget.cpp b/FTNoIR_Tracker_PT/pt_video_widget.cpp new file mode 100644 index 00000000..03c42fc7 --- /dev/null +++ b/FTNoIR_Tracker_PT/pt_video_widget.cpp @@ -0,0 +1,52 @@ +/* Copyright (c) 2012 Patrick Ruoff + * + * 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 +#include + +using namespace cv; +using namespace std; + +void PTVideoWidget::update_image(const cv::Mat& frame) +{ + QMutexLocker foo(&mtx); + QImage qframe = QImage(frame.cols, frame.rows, QImage::Format_RGB888); + uchar* data = qframe.bits(); + const int pitch = qframe.bytesPerLine(); + for (int y = 0; y < frame.rows; y++) + for (int x = 0; x < frame.cols; x++) + { + const int pos = 3 * (y*frame.cols + x); + data[y * pitch + x * 3 + 0] = frame.data[pos + 2]; + data[y * pitch + x * 3 + 1] = frame.data[pos + 1]; + data[y * pitch + x * 3 + 2] = frame.data[pos + 0]; + } + qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation); + pixmap = QPixmap::fromImage(qframe); +} + +// ---------------------------------------------------------------------------- +VideoWidgetDialog::VideoWidgetDialog(QWidget *parent, FrameProvider* provider) + : QDialog(parent), + video_widget(NULL) +{ + const int VIDEO_FRAME_WIDTH = 640; + const int VIDEO_FRAME_HEIGHT = 480; + + video_widget = new PTVideoWidget(this, provider); + + QHBoxLayout* layout = new QHBoxLayout(); + layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(video_widget); + if (this->layout()) delete this->layout(); + setLayout(layout); + resize(VIDEO_FRAME_WIDTH, VIDEO_FRAME_HEIGHT); +} diff --git a/FTNoIR_Tracker_PT/pt_video_widget.h b/FTNoIR_Tracker_PT/pt_video_widget.h new file mode 100644 index 00000000..e67e6d57 --- /dev/null +++ b/FTNoIR_Tracker_PT/pt_video_widget.h @@ -0,0 +1,64 @@ +/* Copyright (c) 2012 Patrick Ruoff + * + * 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 "frame_observer.h" +#include +#include +#include +#include +#ifndef OPENTRACK_API +# include +# include +#else +# include "FTNoIR_Tracker_PT/boost-compat.h" +# if defined(_WIN32) +# include +# endif +#endif +#include +#include +#include + +class PTVideoWidget : public QWidget, public FrameObserver +{ + Q_OBJECT + +public: + PTVideoWidget(QWidget *parent, FrameProvider* provider) : QWidget(parent), /* to avoid linker errors */ FrameObserver(provider) { + connect(&timer, SIGNAL(timeout()), this, SLOT(update())); + timer.start(45); + } + void update_image(const cv::Mat &frame); + void update_frame_and_points() {} +protected slots: + void paintEvent( QPaintEvent* e ) { + QMutexLocker foo(&mtx); + QPainter painter(this); + painter.drawPixmap(e->rect(), pixmap, e->rect()); + } +private: + QMutex mtx; + QPixmap pixmap; + QTimer timer; +}; + +// ---------------------------------------------------------------------------- +// A VideoWidget embedded in a dialog frame +class VideoWidgetDialog : public QDialog +{ + Q_OBJECT +public: + VideoWidgetDialog(QWidget *parent, FrameProvider* provider); + virtual ~VideoWidgetDialog() {} + + PTVideoWidget* get_video_widget() { return video_widget; } + +private: + PTVideoWidget* video_widget; +}; diff --git a/FTNoIR_Tracker_PT/video_widget.cpp b/FTNoIR_Tracker_PT/video_widget.cpp deleted file mode 100644 index 0d31620f..00000000 --- a/FTNoIR_Tracker_PT/video_widget.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* Copyright (c) 2012 Patrick Ruoff - * - * 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 "video_widget.h" - -#include -#include - -using namespace cv; -using namespace std; -#ifndef OPENTRACK_API -using namespace boost; -#endif -#ifndef OPENTRACK_API -// ---------------------------------------------------------------------------- -void VideoWidget::initializeGL() -{ - glClearColor(0.0, 0.0, 0.0, 0.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} - -void VideoWidget::resizeGL(int w, int h) -{ - // setup 1 to 1 projection - glViewport(0, 0, w, h); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0, w, 0, h, -1, 1); - resize_frame(); - glDisable(GL_DEPTH_TEST); - glBegin(GL_QUADS); - glVertex2f(0,0); - glVertex2f(1,0); - glVertex2f(1,1); - glVertex2f(0,1); - glEnd(); -} - -void VideoWidget::paintGL() -{ - glClear(GL_COLOR_BUFFER_BIT); - if (!resized_qframe.isNull()) - { - glDrawPixels(resized_qframe.width(), resized_qframe.height(), GL_RGBA, GL_UNSIGNED_BYTE, resized_qframe.bits()); - - const int crosshair_radius = 10; - const int crosshair_thickness = 1; - - if (points) - { - glColor3f(1.0, 0.0, 0.0); - glLineWidth(crosshair_thickness); - int x,y; - for (vector::iterator iter = points->begin(); - iter != points->end(); - ++iter) - { - x = (*iter)[0] * resized_qframe.width() + resized_qframe.width()/2.0 + 0.5; - y = (*iter)[1] * resized_qframe.width() + resized_qframe.height()/2.0 + 0.5; - - glBegin(GL_LINES); - glVertex2i(x-crosshair_radius, y); - glVertex2i(x+crosshair_radius, y); - glEnd(); - glBegin(GL_LINES); - glVertex2i(x, y-crosshair_radius); - glVertex2i(x, y+crosshair_radius); - glEnd(); - } - } - } - glFlush(); -} - - -void VideoWidget::resize_frame() -{ - if (!qframe.isNull()) - resized_qframe = qframe.scaled(this->size(), Qt::KeepAspectRatio); -} - - -void VideoWidget::update_frame_and_points() -{ - if (!get_frame_and_points(frame, points)) return; - - // convert to QImage - if (frame.channels() == 3) - qframe = QImage((const unsigned char*)(frame.data), frame.cols, frame.rows, frame.step, QImage::Format_RGB888).rgbSwapped(); - else if (frame.channels() == 1) - qframe = QImage((const unsigned char*)(frame.data), frame.cols, frame.rows, frame.step, QImage::Format_Indexed8); - qframe = QGLWidget::convertToGLFormat(qframe); - - resize_frame(); - updateGL(); -} - -#else -void VideoWidget2::update_image(const cv::Mat& frame) -{ - QMutexLocker foo(&mtx); - QImage qframe = QImage(frame.cols, frame.rows, QImage::Format_RGB888); - uchar* data = qframe.bits(); - const int pitch = qframe.bytesPerLine(); - for (int y = 0; y < frame.rows; y++) - for (int x = 0; x < frame.cols; x++) - { - const int pos = 3 * (y*frame.cols + x); - data[y * pitch + x * 3 + 0] = frame.data[pos + 2]; - data[y * pitch + x * 3 + 1] = frame.data[pos + 1]; - data[y * pitch + x * 3 + 2] = frame.data[pos + 0]; - } - qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation); - pixmap = QPixmap::fromImage(qframe); -} -#endif - -// ---------------------------------------------------------------------------- -VideoWidgetDialog::VideoWidgetDialog(QWidget *parent, FrameProvider* provider) - : QDialog(parent), - video_widget(NULL) -{ - const int VIDEO_FRAME_WIDTH = 640; - const int VIDEO_FRAME_HEIGHT = 480; - -#ifdef OPENTRACK_API - video_widget = new VideoWidget2(this, provider); -#else - video_widget = new VideoWidget(this, provider); -#endif - - QHBoxLayout* layout = new QHBoxLayout(); - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(video_widget); - if (this->layout()) delete this->layout(); - setLayout(layout); - resize(VIDEO_FRAME_WIDTH, VIDEO_FRAME_HEIGHT); -} diff --git a/FTNoIR_Tracker_PT/video_widget.h b/FTNoIR_Tracker_PT/video_widget.h deleted file mode 100644 index 3164dacc..00000000 --- a/FTNoIR_Tracker_PT/video_widget.h +++ /dev/null @@ -1,95 +0,0 @@ -/* Copyright (c) 2012 Patrick Ruoff - * - * 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. - */ - -#ifndef VIDEOWIDGET_H -#define VIDEOWIDGET_H - -#include "frame_observer.h" - -#include -#include -#include -#ifndef OPENTRACK_API -# include -# include -#else -# include "FTNoIR_Tracker_PT/boost-compat.h" -# if defined(_WIN32) -# include -# endif -#endif -#include -#include -#include - -#ifndef OPENTRACK_API -// ---------------------------------------------------------------------------- -// OpenGL based widget to display an OpenCV image with some points on top -class VideoWidget : public QGLWidget, public FrameObserver -{ - Q_OBJECT - -public: - VideoWidget(QWidget *parent, FrameProvider* provider) : QGLWidget(parent), FrameObserver(provider) {} - - virtual void initializeGL(); - virtual void resizeGL(int w, int h); - virtual void paintGL(); - - void update_frame_and_points(); - -private: - void resize_frame(); - - cv::Mat frame; - QImage qframe; - QImage resized_qframe; - - boost::shared_ptr< std::vector > points; -}; -#else -/* Qt moc likes to skip over preprocessor directives -sh */ -class VideoWidget2 : public QWidget, public FrameObserver -{ - Q_OBJECT - -public: - VideoWidget2(QWidget *parent, FrameProvider* provider) : QWidget(parent), /* to avoid linker errors */ FrameObserver(provider) { - connect(&timer, SIGNAL(timeout()), this, SLOT(update())); - timer.start(45); - } - void update_image(const cv::Mat &frame); - void update_frame_and_points() {} -protected slots: - void paintEvent( QPaintEvent* e ) { - QMutexLocker foo(&mtx); - QPainter painter(this); - painter.drawPixmap(e->rect(), pixmap, e->rect()); - } -private: - QMutex mtx; - QPixmap pixmap; - QTimer timer; -}; -#endif - -// ---------------------------------------------------------------------------- -// A VideoWidget embedded in a dialog frame -class VideoWidgetDialog : public QDialog -{ - Q_OBJECT -public: - VideoWidgetDialog(QWidget *parent, FrameProvider* provider); - virtual ~VideoWidgetDialog() {} - - VideoWidget2* get_video_widget() { return video_widget; } - -private: - VideoWidget2* video_widget; -}; - -#endif // VIDEOWIDGET_H diff --git a/compat/qt-bug-appeasement.cpp b/compat/qt-bug-appeasement.cpp new file mode 100644 index 00000000..9a86ac0a --- /dev/null +++ b/compat/qt-bug-appeasement.cpp @@ -0,0 +1 @@ +#include "facetracknoir/qt-moc.h" diff --git a/facetracknoir/qt-moc.h b/facetracknoir/qt-moc.h new file mode 100644 index 00000000..467370f9 --- /dev/null +++ b/facetracknoir/qt-moc.h @@ -0,0 +1,10 @@ +#include + +// this file exists only such that cmake qt automoc is appeased + +class AutomocMe { + Q_OBJECT +private: + virtual void foo() = 0; + AutomocMe() = delete; +}; diff --git a/ftnoir_protocol_fg/ftnoir_protocol_fg_dialog.cpp b/ftnoir_protocol_fg/ftnoir_protocol_fg_dialog.cpp index f479ce76..cefc9bf8 100644 --- a/ftnoir_protocol_fg/ftnoir_protocol_fg_dialog.cpp +++ b/ftnoir_protocol_fg/ftnoir_protocol_fg_dialog.cpp @@ -26,6 +26,7 @@ * It is based on the (Linux) example made by Melchior FRANZ. * ********************************************************************************/ #include "ftnoir_protocol_fg.h" +#include #include #include "facetracknoir/global-settings.h" diff --git a/ftnoir_tracker_aruco/ar_video_widget.cpp b/ftnoir_tracker_aruco/ar_video_widget.cpp new file mode 100644 index 00000000..6a4572a0 --- /dev/null +++ b/ftnoir_tracker_aruco/ar_video_widget.cpp @@ -0,0 +1,30 @@ +/* Copyright (c) 2012 Patrick Ruoff + * + * 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" + +#include + +using namespace std; + +void ArucoVideoWidget::update_image(unsigned char *frame, int width, int height) +{ + QMutexLocker foo(&mtx); + QImage qframe = QImage(width, height, QImage::Format_RGB888); + uchar* data = qframe.bits(); + const int pitch = qframe.bytesPerLine(); + for (int y = 0; y < height; y++) + for (int x = 0; x < width; x++) + { + const int pos = 3 * (y*width + x); + data[y * pitch + x * 3 + 0] = frame[pos + 2]; + data[y * pitch + x * 3 + 1] = frame[pos + 1]; + data[y * pitch + x * 3 + 2] = frame[pos + 0]; + } + qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation); + pixmap = QPixmap::fromImage(qframe); +} diff --git a/ftnoir_tracker_aruco/ar_video_widget.h b/ftnoir_tracker_aruco/ar_video_widget.h new file mode 100644 index 00000000..dd0c16ac --- /dev/null +++ b/ftnoir_tracker_aruco/ar_video_widget.h @@ -0,0 +1,39 @@ +/* Copyright (c) 2012 Patrick Ruoff + * + * 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. + */ + +#ifndef VIDEOWIDGET_H +#define VIDEOWIDGET_H + +#include +#include +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +class ArucoVideoWidget : public QWidget +{ + Q_OBJECT + +public: + ArucoVideoWidget(QWidget *parent) : QWidget(parent), mtx() { + } + void update_image(unsigned char* frame, int width, int height); +protected slots: + void paintEvent( QPaintEvent* e ) { + QMutexLocker foo(&mtx); + QPainter painter(this); + painter.drawPixmap(e->rect(), pixmap, e->rect()); + } +private: + QMutex mtx; + QPixmap pixmap; +}; + +#endif // VIDEOWIDGET_H diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp index 8025e956..c735b479 100644 --- a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp +++ b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp @@ -148,7 +148,7 @@ Tracker::~Tracker() void Tracker::StartTracker(QFrame* videoframe) { videoframe->show(); - videoWidget = new VideoWidget(videoframe); + videoWidget = new ArucoVideoWidget(videoframe); QHBoxLayout* layout = new QHBoxLayout(); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(videoWidget); diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h index 98aba2cf..ddbdd179 100644 --- a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h +++ b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h @@ -10,12 +10,13 @@ #include "ftnoir_tracker_base/ftnoir_tracker_base.h" #include "ui_aruco-trackercontrols.h" -#include "video_widget.h" +#include "ar_video_widget.h" #include #include #include #include #include +#include #include class Tracker : public QThread, public ITracker @@ -31,7 +32,7 @@ public: private: QMutex mtx; QTimer timer; - VideoWidget* videoWidget; + ArucoVideoWidget* videoWidget; QHBoxLayout* layout; volatile bool fresh, stop; float fov; diff --git a/ftnoir_tracker_aruco/video_widget.cpp b/ftnoir_tracker_aruco/video_widget.cpp deleted file mode 100644 index 84cba6a3..00000000 --- a/ftnoir_tracker_aruco/video_widget.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (c) 2012 Patrick Ruoff - * - * 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 "video_widget.h" - -#include - -using namespace std; - -void VideoWidget::update_image(unsigned char *frame, int width, int height) -{ - QMutexLocker foo(&mtx); - QImage qframe = QImage(width, height, QImage::Format_RGB888); - uchar* data = qframe.bits(); - const int pitch = qframe.bytesPerLine(); - for (int y = 0; y < height; y++) - for (int x = 0; x < width; x++) - { - const int pos = 3 * (y*width + x); - data[y * pitch + x * 3 + 0] = frame[pos + 2]; - data[y * pitch + x * 3 + 1] = frame[pos + 1]; - data[y * pitch + x * 3 + 2] = frame[pos + 0]; - } - qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation); - pixmap = QPixmap::fromImage(qframe); -} diff --git a/ftnoir_tracker_aruco/video_widget.h b/ftnoir_tracker_aruco/video_widget.h deleted file mode 100644 index 87b6278a..00000000 --- a/ftnoir_tracker_aruco/video_widget.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (c) 2012 Patrick Ruoff - * - * 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. - */ - -#ifndef VIDEOWIDGET_H -#define VIDEOWIDGET_H - -#include -#include -#include -#include -#include -#include -#include - -// ---------------------------------------------------------------------------- -class VideoWidget : public QWidget -{ - Q_OBJECT - -public: - VideoWidget(QWidget *parent) : QWidget(parent), mtx() { - } - void update_image(unsigned char* frame, int width, int height); -protected slots: - void paintEvent( QPaintEvent* e ) { - QMutexLocker foo(&mtx); - QPainter painter(this); - painter.drawPixmap(e->rect(), pixmap, e->rect()); - } -private: - QMutex mtx; - QPixmap pixmap; -}; - -#endif // VIDEOWIDGET_H diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp index 27817a0c..b4fd03f6 100644 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp +++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp @@ -165,7 +165,7 @@ Tracker::~Tracker() void Tracker::StartTracker(QFrame* videoframe) { videoframe->show(); - videoWidget = new VideoWidget(videoframe); + videoWidget = new HTVideoWidget(videoframe); QHBoxLayout* layout = new QHBoxLayout(); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(videoWidget); diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.h b/ftnoir_tracker_ht/ftnoir_tracker_ht.h index 5b8eb508..96607411 100644 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.h +++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.h @@ -12,7 +12,7 @@ #include "ftnoir_tracker_base/ftnoir_tracker_base.h" #include "headtracker-ftnoir.h" #include "ui_ht-trackercontrols.h" -#include "video_widget.h" +#include "ht_video_widget.h" #include "compat/compat.h" #include #include @@ -31,7 +31,7 @@ private: QTimer timer; PortableLockedShm lck_shm; QProcess subprocess; - VideoWidget* videoWidget; + HTVideoWidget* videoWidget; QHBoxLayout* layout; volatile bool fresh; private slots: diff --git a/ftnoir_tracker_ht/ht_video_widget.cpp b/ftnoir_tracker_ht/ht_video_widget.cpp new file mode 100644 index 00000000..4d7d66a2 --- /dev/null +++ b/ftnoir_tracker_ht/ht_video_widget.cpp @@ -0,0 +1,30 @@ +/* Copyright (c) 2012 Patrick Ruoff + * + * 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 "ht_video_widget.h" + +#include + +using namespace std; + +void HTVideoWidget::update_image(unsigned char *frame, int width, int height) +{ + QMutexLocker foo(&mtx); + QImage qframe = QImage(width, height, QImage::Format_RGB888); + uchar* data = qframe.bits(); + const int pitch = qframe.bytesPerLine(); + for (int y = 0; y < height; y++) + for (int x = 0; x < width; x++) + { + const int pos = 3 * (y*width + x); + data[y * pitch + x * 3 + 0] = frame[pos + 2]; + data[y * pitch + x * 3 + 1] = frame[pos + 1]; + data[y * pitch + x * 3 + 2] = frame[pos + 0]; + } + qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation); + pixmap = QPixmap::fromImage(qframe); +} diff --git a/ftnoir_tracker_ht/ht_video_widget.h b/ftnoir_tracker_ht/ht_video_widget.h new file mode 100644 index 00000000..b1182d8b --- /dev/null +++ b/ftnoir_tracker_ht/ht_video_widget.h @@ -0,0 +1,39 @@ +/* Copyright (c) 2012 Patrick Ruoff + * + * 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. + */ + +#ifndef VIDEOWIDGET_H +#define VIDEOWIDGET_H + +#include +#include +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +class HTVideoWidget : public QWidget +{ + Q_OBJECT + +public: + HTVideoWidget(QWidget *parent) : QWidget(parent), mtx() { + } + void update_image(unsigned char* frame, int width, int height); +protected slots: + void paintEvent( QPaintEvent* e ) { + QMutexLocker foo(&mtx); + QPainter painter(this); + painter.drawPixmap(e->rect(), pixmap, e->rect()); + } +private: + QMutex mtx; + QPixmap pixmap; +}; + +#endif // VIDEOWIDGET_H diff --git a/ftnoir_tracker_ht/video_widget.cpp b/ftnoir_tracker_ht/video_widget.cpp deleted file mode 100644 index 84cba6a3..00000000 --- a/ftnoir_tracker_ht/video_widget.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (c) 2012 Patrick Ruoff - * - * 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 "video_widget.h" - -#include - -using namespace std; - -void VideoWidget::update_image(unsigned char *frame, int width, int height) -{ - QMutexLocker foo(&mtx); - QImage qframe = QImage(width, height, QImage::Format_RGB888); - uchar* data = qframe.bits(); - const int pitch = qframe.bytesPerLine(); - for (int y = 0; y < height; y++) - for (int x = 0; x < width; x++) - { - const int pos = 3 * (y*width + x); - data[y * pitch + x * 3 + 0] = frame[pos + 2]; - data[y * pitch + x * 3 + 1] = frame[pos + 1]; - data[y * pitch + x * 3 + 2] = frame[pos + 0]; - } - qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation); - pixmap = QPixmap::fromImage(qframe); -} diff --git a/ftnoir_tracker_ht/video_widget.h b/ftnoir_tracker_ht/video_widget.h deleted file mode 100644 index 87b6278a..00000000 --- a/ftnoir_tracker_ht/video_widget.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (c) 2012 Patrick Ruoff - * - * 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. - */ - -#ifndef VIDEOWIDGET_H -#define VIDEOWIDGET_H - -#include -#include -#include -#include -#include -#include -#include - -// ---------------------------------------------------------------------------- -class VideoWidget : public QWidget -{ - Q_OBJECT - -public: - VideoWidget(QWidget *parent) : QWidget(parent), mtx() { - } - void update_image(unsigned char* frame, int width, int height); -protected slots: - void paintEvent( QPaintEvent* e ) { - QMutexLocker foo(&mtx); - QPainter painter(this); - painter.drawPixmap(e->rect(), pixmap, e->rect()); - } -private: - QMutex mtx; - QPixmap pixmap; -}; - -#endif // VIDEOWIDGET_H -- cgit v1.2.3