-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrameConverter.hpp
80 lines (68 loc) · 2.69 KB
/
FrameConverter.hpp
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
/*
* LiveFit
* Copyright (C) 2016 The University of Georgia
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef FRAMECONVERTER_HPP
#define FRAMECONVERTER_HPP
#include <QBasicTimer>
#include <QObject>
#include <QSize>
#include "ColorSpace.hpp"
#include <opencv2/core/mat.hpp>
/**
* @brief Recieves frames (as cv::Mat), processes them (ideally asynchronously)
* and emits them as a QImage (i.e. for use in a QWidget)
*/
class FrameConverter : public QObject
{
Q_OBJECT
/** Process a frame at each tick of this timer */
QBasicTimer mTimer;
/** The current frame to process into a QImage */
cv::Mat currentFrame;
/** The current ColorSpace of the frame we are processing */
ColorSpace currentCS;
/** Whether we should process all frames, or drop some to keep framerate */
bool processAll = true;
/** The resolution of the frames that we are processing */
QSize frameSize;
/** Delete a cv::Mat object */
static void matDeleter(void *mat) { delete static_cast<cv::Mat*>(mat); }
public:
explicit FrameConverter(QObject *parent = 0);
/** Set whether we should process all frames, or drop some */
void setProcessAll(bool all) { processAll = all; }
~FrameConverter();
signals:
/** Emitted when we have a QImage from processing ready for display */
void imageReady(const QImage &);
public slots:
/** Add a new frame to be processed; if not processAll this frame may yet be dropped. */
void processFrame(const cv::Mat &frame, enum ColorSpace);
/** Set the resolution of the frames we are processing */
void setFrameSize(QSize size);
/** Stop processing frames */
void stop();
private:
/** Queue a new frame to be processed (depends on processAll if it gets processed). */
void queue(const cv::Mat & frame, ColorSpace cs);
/** Actually process a frame. Resultant QImage gets emitted by imageReady() */
void process(cv::Mat frame, ColorSpace cs);
/** Called each time that mTimer ticks... we call process on the queue in here. */
void timerEvent(QTimerEvent *ev);
};
#endif // FRAMECONVERTER_HPP