LiveFit
Track and plot projectiles for in-class demonstration
FrameConverter.hpp
1 /*
2  * LiveFit
3  * Copyright (C) 2016 The University of Georgia
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef FRAMECONVERTER_HPP
21 #define FRAMECONVERTER_HPP
22 
23 #include <QBasicTimer>
24 #include <QObject>
25 #include <QSize>
26 
27 #include "ColorSpace.hpp"
28 
29 #include <opencv2/core/mat.hpp>
30 
35 class FrameConverter : public QObject
36 {
37  Q_OBJECT
38 
40  QBasicTimer mTimer;
42  cv::Mat currentFrame;
44  ColorSpace currentCS;
46  bool processAll = true;
48  QSize frameSize;
49 
51  static void matDeleter(void *mat) { delete static_cast<cv::Mat*>(mat); }
52 
53 public:
54  explicit FrameConverter(QObject *parent = 0);
55 
57  void setProcessAll(bool all) { processAll = all; }
58 
59  ~FrameConverter();
60 signals:
62  void imageReady(const QImage &);
63 
64 public slots:
66  void processFrame(const cv::Mat &frame, enum ColorSpace);
68  void setFrameSize(QSize size);
70  void stop();
71 private:
73  void queue(const cv::Mat & frame, ColorSpace cs);
75  void process(cv::Mat frame, ColorSpace cs);
77  void timerEvent(QTimerEvent *ev);
78 };
79 
80 #endif // FRAMECONVERTER_HPP
void process(cv::Mat frame, ColorSpace cs)
Actually process a frame.
Definition: FrameConverter.cpp:61
void timerEvent(QTimerEvent *ev)
Called each time that mTimer ticks...
Definition: FrameConverter.cpp:77
QBasicTimer mTimer
Process a frame at each tick of this timer.
Definition: FrameConverter.hpp:40
void setFrameSize(QSize size)
Set the resolution of the frames we are processing.
Definition: FrameConverter.cpp:47
void queue(const cv::Mat &frame, ColorSpace cs)
Queue a new frame to be processed (depends on processAll if it gets processed).
Definition: FrameConverter.cpp:52
void processFrame(const cv::Mat &frame, enum ColorSpace)
Add a new frame to be processed; if not processAll this frame may yet be dropped. ...
Definition: FrameConverter.cpp:38
cv::Mat currentFrame
The current frame to process into a QImage.
Definition: FrameConverter.hpp:42
ColorSpace currentCS
The current ColorSpace of the frame we are processing.
Definition: FrameConverter.hpp:44
void setProcessAll(bool all)
Set whether we should process all frames, or drop some.
Definition: FrameConverter.hpp:57
static void matDeleter(void *mat)
Delete a cv::Mat object.
Definition: FrameConverter.hpp:51
QSize frameSize
The resolution of the frames that we are processing.
Definition: FrameConverter.hpp:48
void stop()
Stop processing frames.
Definition: FrameConverter.cpp:87
bool processAll
Whether we should process all frames, or drop some to keep framerate.
Definition: FrameConverter.hpp:46
void imageReady(const QImage &)
Emitted when we have a QImage from processing ready for display.
Recieves frames (as cv::Mat), processes them (ideally asynchronously) and emits them as a QImage (i...
Definition: FrameConverter.hpp:35