diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2013-04-27 11:54:48 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-04-27 11:54:48 +0200 |
commit | c7c3bfc9a1558864b06319918900090c7564c6d2 (patch) | |
tree | aa53e2e9395c0197d2ab46585a15293a2423cfd8 | |
parent | bf45260ce8f235e593a22cdbdf9bcd98d508ae7f (diff) |
Get rid of last remnants of QOpenGL
-rw-r--r-- | CMakeLists.txt | 7 | ||||
-rw-r--r-- | ftnoir_tracker_ht/ftnoir_tracker_ht.cpp | 2 | ||||
-rw-r--r-- | ftnoir_tracker_ht/video_widget.cpp | 63 | ||||
-rw-r--r-- | ftnoir_tracker_ht/video_widget.h | 30 | ||||
-rw-r--r-- | ftnoir_tracker_pt/video_widget.cpp | 109 | ||||
-rw-r--r-- | ftnoir_tracker_pt/video_widget.h | 27 |
6 files changed, 62 insertions, 176 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c4b44d5c..7bd7b261 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ include_directories(${CMAKE_SOURCE_DIR}) if(NOT SDK_FACEAPI_ONLY) find_package(OpenCV REQUIRED) - find_package(Qt4 COMPONENTS QtCore QtGui QtDesigner QtXml QtOpenGL QtNetwork REQUIRED) + find_package(Qt4 COMPONENTS QtCore QtGui QtDesigner QtXml QtNetwork REQUIRED) macro(QT4_WRAP_CPP outfiles) # get include dirs QT4_GET_MOC_FLAGS(moc_flags) @@ -308,9 +308,9 @@ endif() endif() IF(CMAKE_BUILD_TYPE MATCHES DEBUG) - SET(MY_QT_LIBS ${QT_QTCORE_LIBRARY_DEBUG} ${QT_QTGUI_LIBRARY_DEBUG} ${QT_QTNETWORK_LIBRARY_DEBUG} ${QT_QTXML_LIBRARY_DEBUG} ${QT_QTOPENGL_LIBRARY_DEBUG}) + SET(MY_QT_LIBS ${QT_QTCORE_LIBRARY_DEBUG} ${QT_QTGUI_LIBRARY_DEBUG} ${QT_QTNETWORK_LIBRARY_DEBUG} ${QT_QTXML_LIBRARY_DEBUG}) ELSE() - SET(MY_QT_LIBS ${QT_QTCORE_LIBRARY_RELEASE} ${QT_QTGUI_LIBRARY_RELEASE} ${QT_QTNETWORK_LIBRARY_RELEASE} ${QT_QTXML_LIBRARY_RELEASE} ${QT_QTOPENGL_LIBRARY_RELEASE}) + SET(MY_QT_LIBS ${QT_QTCORE_LIBRARY_RELEASE} ${QT_QTGUI_LIBRARY_RELEASE} ${QT_QTNETWORK_LIBRARY_RELEASE} ${QT_QTXML_LIBRARY_RELEASE}) ENDIF() add_library(ftnoir-csv SHARED ${ftnoir-csv-c}) @@ -613,7 +613,6 @@ if(NOT SDK_FACEAPI_ONLY) "${qt-dirname}/QtCore4.dll" "${qt-dirname}/QtGui4.dll" "${qt-dirname}/QtNetwork4.dll" - "${qt-dirname}/QtOpenGL4.dll" "${qt-dirname}/QtSvg4.dll" "${qt-dirname}/QtXml4.dll" DESTINATION . diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp index b13e605d..d88699a9 100644 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp +++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp @@ -226,7 +226,7 @@ bool Tracker::GiveHeadPoseData(double *data) shm->timer = 0; if (shm->frame.width > 0) { - videoWidget->updateImage(shm->frame.frame, shm->frame.width, shm->frame.height); + videoWidget->update_image(shm->frame.frame, shm->frame.width, shm->frame.height); //memcpy(foo, shm->frame.frame, shm->frame.width * shm->frame.height * 3); fresh = true; shm->frame.width = 0; diff --git a/ftnoir_tracker_ht/video_widget.cpp b/ftnoir_tracker_ht/video_widget.cpp index 51d92967..01f2516a 100644 --- a/ftnoir_tracker_ht/video_widget.cpp +++ b/ftnoir_tracker_ht/video_widget.cpp @@ -11,59 +11,16 @@ using namespace std; -// ---------------------------------------------------------------------------- -void VideoWidget::initializeGL() +void VideoWidget::update_image(unsigned char *frame, int width, int height) { - 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(resized_qframe); - glDisable(GL_DEPTH_TEST); - glBegin(GL_QUADS); - glVertex2f(0,0); - glVertex2f(1,0); - glVertex2f(1,1); - glVertex2f(0,1); - glEnd(); -} - -void VideoWidget::paintGL() -{ - QMutexLocker lck(&mtx); - if (resized_qframe.size() == size() || (resized_qframe.width() <= width() && resized_qframe.height() <= height())) - { - glDrawPixels(resized_qframe.width(), resized_qframe.height(), GL_RGB, GL_UNSIGNED_BYTE, resized_qframe.bits()); - } - else - glClear(GL_DEPTH_BUFFER_BIT); - glFlush(); -} - -void VideoWidget::resize_frame(QImage& qframe) -{ - QMutexLocker lck(&mtx); - if (qframe.size() == size() || (qframe.width() <= width() && qframe.height() <= height())) - resized_qframe = qframe.copy(); + QMutexLocker((QMutex*)&mtx); + QImage qframe = QImage(frame, width, height, 3 * width, QImage::Format_RGB888).rgbSwapped().mirrored(); + if (qframe.size() == size() || (qframe.width() <= this->width() && qframe.height() <= this->height())) + qframe = qframe.mirrored(); else - resized_qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation).copy(); -} - - -void VideoWidget::updateImage(unsigned char *frame, int width, int height) -{ - QImage foo = QImage(frame, width, height, 3 * width, QImage::Format_RGB888).rgbSwapped().mirrored(); - resize_frame(foo); -} - -void VideoWidget::update() { - updateGL(); + qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation).mirrored(); + QPainter painter(&qframe); + painter.setPen(Qt::blue); + painter.setBrush(Qt::blue); + pixmap = QPixmap::fromImage(qframe); } diff --git a/ftnoir_tracker_ht/video_widget.h b/ftnoir_tracker_ht/video_widget.h index adc57335..51acc35e 100644 --- a/ftnoir_tracker_ht/video_widget.h +++ b/ftnoir_tracker_ht/video_widget.h @@ -8,35 +8,31 @@ #ifndef VIDEOWIDGET_H #define VIDEOWIDGET_H -#include <QGLWidget> #include <QTime> -#include <QFrame> -#include <QImage> +#include <memory> #include <QWidget> #include <QMutex> #include <QMutexLocker> +#include <QLabel> +#include <QPainter> + // ---------------------------------------------------------------------------- -class VideoWidget : public QGLWidget +class VideoWidget : public QLabel { Q_OBJECT public: - VideoWidget(QWidget *parent) : QGLWidget(parent) { -#if !defined(_WIN32) - setAttribute(Qt::WA_NativeWindow, true); -#endif + VideoWidget(QWidget *parent) : QLabel(parent), mtx() { } - - void initializeGL(); - void resizeGL(int w, int h); - void paintGL(); - - void updateImage(unsigned char* frame, int width, int height); - void update(); + void update_image(unsigned char* frame, int width, int height); +protected slots: + void paintEvent( QPaintEvent* e ) { + setPixmap(pixmap); + QLabel::paintEvent(e); + } private: - void resize_frame(QImage& qframe); - QImage resized_qframe; QMutex mtx; + QPixmap pixmap; }; #endif // VIDEOWIDGET_H diff --git a/ftnoir_tracker_pt/video_widget.cpp b/ftnoir_tracker_pt/video_widget.cpp index 1b8b4a7a..fe2b2e34 100644 --- a/ftnoir_tracker_pt/video_widget.cpp +++ b/ftnoir_tracker_pt/video_widget.cpp @@ -12,98 +12,39 @@ using namespace cv;
using namespace std;
-// ----------------------------------------------------------------------------
-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()
-{
- QMutexLocker((QMutex*)&mtx);
- if (resized_qframe.size() == size() || (resized_qframe.width() <= width() && resized_qframe.height() <= height())) {
- glDrawPixels(resized_qframe.width(), resized_qframe.height(), GL_RGB, GL_UNSIGNED_BYTE, resized_qframe.bits());
- if (points.get() != NULL)
- {
- const int crosshair_radius = 10;
- const int crosshair_thickness = 1;
-
- glColor3f(1.0, 0.0, 0.0);
- glLineWidth(crosshair_thickness);
- int x,y;
- for (vector<Vec2f>::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();
- }
- }
- } else {
- glClear(GL_DEPTH_BUFFER_BIT);
- }
- glFlush();
-}
-
-
-void VideoWidget::resize_frame()
-{
-#ifdef _WIN32
- if (qframe.size() == size() || (qframe.width() <= width() && qframe.height() <= height()))
- resized_qframe = qframe.mirrored();
- else
- resized_qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation).mirrored();
-#else
- if (qframe.size() == size() || (qframe.width() <= width() && qframe.height() <= height()))
- resized_qframe = qframe.copy();
- else
- resized_qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation);
-#endif
-}
-
-void VideoWidget::update()
-{
- updateGL();
-}
-
void VideoWidget::update_image(Mat frame, std::auto_ptr< vector<Vec2f> > points)
{
QMutexLocker((QMutex*)&mtx);
this->frame = frame;
this->points = points;
+
+ QImage qframe;
// convert to QImage
if (frame.channels() == 3)
qframe = QImage((const unsigned char*)(frame.data), frame.cols, frame.rows, frame.cols * 3, QImage::Format_RGB888).rgbSwapped();
else if (frame.channels() == 1)
- qframe = QImage((const unsigned char*)(frame.data), frame.cols, frame.rows, frame.cols, QImage::Format_Indexed8);
- resize_frame();
+ qframe = QImage((const unsigned char*)(frame.data), frame.cols, frame.rows, frame.cols, QImage::Format_Indexed8).convertToFormat(QImage::Format_RGB888);
+ if (qframe.size() == size() || (qframe.width() <= width() && qframe.height() <= height()))
+ {
+ ;;;
+ }
+ else
+ qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation);
+ QPainter painter(&qframe);
+ painter.setPen(Qt::blue);
+ painter.setBrush(Qt::blue);
+ if (points.get() != NULL) {
+ const int crosshair_radius = 10;
+ for (vector<Vec2f>::iterator iter = points->begin();
+ iter != points->end();
+ ++iter)
+ {
+ int x = (*iter)[0];
+ int y = (*iter)[1];
+ painter.drawLine(QLine(x-crosshair_radius, y, x+crosshair_radius, y));
+ painter.drawLine(QLine(x, y-crosshair_radius, x, y+crosshair_radius));
+ }
+ }
+ pixmap = QPixmap::fromImage(qframe);
}
diff --git a/ftnoir_tracker_pt/video_widget.h b/ftnoir_tracker_pt/video_widget.h index bb567478..a68d8028 100644 --- a/ftnoir_tracker_pt/video_widget.h +++ b/ftnoir_tracker_pt/video_widget.h @@ -8,42 +8,35 @@ #ifndef VIDEOWIDGET_H
#define VIDEOWIDGET_H
-#include <QGLWidget>
#include <QTime>
#include <opencv2/opencv.hpp>
#include <memory>
#include <QWidget>
#include <QMutex>
#include <QMutexLocker>
+#include <QLabel>
+#include <QPainter>
// ----------------------------------------------------------------------------
-class VideoWidget : public QGLWidget
+class VideoWidget : public QLabel
{
Q_OBJECT
public:
- VideoWidget(QWidget *parent) : QGLWidget(parent), mtx() {
-#if !defined(_WIN32)
- setAttribute(Qt::WA_NativeWindow, true);
-#endif
+ VideoWidget(QWidget *parent) : QLabel(parent), mtx() {
}
-
- void initializeGL();
- void resizeGL(int w, int h);
- void paintGL();
-
void update_image(cv::Mat frame, std::auto_ptr< std::vector<cv::Vec2f> > points);
- void update();
+protected slots:
+ void paintEvent( QPaintEvent* e ) {
+ setPixmap(pixmap);
+ QLabel::paintEvent(e);
+ }
private:
- void resize_frame();
-
cv::Mat frame;
- QImage qframe;
- QImage resized_qframe;
QMutex mtx;
-
std::auto_ptr< std::vector<cv::Vec2f> > points;
+ QPixmap pixmap;
};
#endif // VIDEOWIDGET_H
|