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_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 --------------------------- 6 files changed, 73 insertions(+), 72 deletions(-) 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 (limited to 'ftnoir_tracker_aruco') 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 -- cgit v1.2.3