diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2013-03-22 21:48:28 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-03-22 21:51:09 +0100 |
commit | 4f05cb2af239ca8471b77c9f1d1c32e8c4cd3abc (patch) | |
tree | 338d3891b0c7710558aea3820d42af6eedfb0af9 /ftnoir_tracker_pt/video_widget.cpp | |
parent | 4f00c4c74d213a37a4b1a3313e50ce2b4dd51271 (diff) |
Remove .bat files, actually finish rename this time
Diffstat (limited to 'ftnoir_tracker_pt/video_widget.cpp')
-rw-r--r-- | ftnoir_tracker_pt/video_widget.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/ftnoir_tracker_pt/video_widget.cpp b/ftnoir_tracker_pt/video_widget.cpp new file mode 100644 index 00000000..c2b41da1 --- /dev/null +++ b/ftnoir_tracker_pt/video_widget.cpp @@ -0,0 +1,98 @@ +/* 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 <QDebug>
+
+using namespace cv;
+using namespace std;
+using namespace boost;
+
+// ----------------------------------------------------------------------------
+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;
+
+ 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();
+ }
+ }
+ glFlush();
+}
+
+
+void VideoWidget::resize_frame()
+{
+ if (!qframe.isNull())
+ resized_qframe = qframe.scaled(this->size(), Qt::KeepAspectRatio);
+}
+
+
+void VideoWidget::update(Mat frame, shared_ptr< vector<Vec2f> > points)
+{
+ this->frame = frame;
+ this->points = points;
+
+ // 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();
+}
|