-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlauvideoglwidget.h
114 lines (95 loc) · 2.55 KB
/
lauvideoglwidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef LAUVIDEOGLWIDGET_H
#define LAUVIDEOGLWIDGET_H
#include <QTime>
#include <QImage>
#include <QScreen>
#include <QObject>
#include <QVideoFrame>
#include <QApplication>
#include <QOpenGLWidget>
#include <QOpenGLBuffer>
#include <QOpenGLTexture>
#include <QDesktopWidget>
#include <QGuiApplication>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLFramebufferObject>
#include <QOpenGLPixelTransferOptions>
#ifdef Q_OS_WIN
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
#endif
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
class LAUVideoGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
public:
explicit LAUVideoGLWidget(QWidget *parent = NULL) : QOpenGLWidget(parent), videoTexture(NULL), counter(0) { ; }
~LAUVideoGLWidget();
virtual bool isValid() const
{
return (wasInitialized());
}
bool wasInitialized() const
{
return (vertexArrayObject.isCreated());
}
#ifdef Q_OS_WIN
void setVideoRecorder(cv::VideoWriter **handle)
{
recorder = handle;
}
#endif
void setFrame(const QVideoFrame &frame);
void setFrame(QImage frame);
virtual QImage grabImage()
{
if (videoTexture) {
makeCurrent();
QImage image(videoTexture->width(), videoTexture->height(), QImage::Format_RGBA8888);
videoTexture->bind();
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, image.bits());
videoTexture->release();
return (image);
}
return (QImage());
}
virtual void process() { ; }
virtual void initialize();
virtual void resize(int w, int h);
virtual void paint();
protected:
void initializeGL()
{
initialize();
}
void resizeGL(int w, int h)
{
resize(w, h);
}
void paintGL()
{
paint();
}
#ifdef Q_OS_WIN
cv::VideoWriter **recorder;
#endif
QOpenGLVertexArrayObject vertexArrayObject;
QOpenGLBuffer quadVertexBuffer, quadIndexBuffer;
QOpenGLShaderProgram program;
QOpenGLTexture *videoTexture;
int localWidth, localHeight;
qreal devicePixelRatio;
private:
int counter;
QTime time;
};
#endif // LAUVIDEOGLWIDGET_H