-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraToolBox.h
More file actions
114 lines (89 loc) · 3.36 KB
/
CameraToolBox.h
File metadata and controls
114 lines (89 loc) · 3.36 KB
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 CAMERATOOLBOX_H
#define CAMERATOOLBOX_H
#include <QQuickItem>
#include <QCameraInfo>
#include <QList>
#include <QAbstractVideoSurface>
#include <QVideoSurfaceFormat>
#include <QSize>
#include <QMutex>
#include <QWaitCondition>
#include <QVariant>
#include <opencv2/highgui/highgui.hpp>
#include "VideoCaptureThread.h"
#include "ImageProcessThread.h"
/**
* @brief Let QMetaType know the type provided,
* then QVariant need it to customize it's type.
*/
Q_DECLARE_METATYPE(cv::Mat)
/**
* @brief QML wrapper for OpenCV camera access
*/
class CameraToolBox : public QQuickItem {
Q_OBJECT
Q_DISABLE_COPY(CameraToolBox)
Q_PROPERTY(QAbstractVideoSurface* videoSurface READ getVideoSurface WRITE setVideoSurface)
//Q_PROPERTY(QSize size READ getSize WRITE setSize NOTIFY sizeChanged)
Q_PROPERTY(QSize size READ getSize NOTIFY sizeChanged)
public:
/**
* @brief Creates a new cv camera with the given QML parent
*
* @param parent The QML parent
*/
CameraToolBox(QQuickItem* parent = 0);
/**
* @brief Destroys this cv camera
*/
~CameraToolBox();
/**
* @brief Gets the video surface associated with this camera
*
* @return The video surface associated with this camera
*/
QAbstractVideoSurface* getVideoSurface() const;
/**
* @brief Gives a video surface for this camera to draw on
*
* @param surface The new surface to draw on
*/
void setVideoSurface(QAbstractVideoSurface* videoSurface);
QSize getSize() const;
QMutex* lock;
QWaitCondition* conImageReady;
private:
const QVideoFrame::PixelFormat VIDEO_OUTPUT_FORMAT = QVideoFrame::PixelFormat::Format_ARGB32;
QSize size; ///< The desired camera resolution
VideoCaptureWrapper* camera = NULL; ///< The camera object
VideoCaptureThread* thread_capture = NULL; ///< Thread to run camera image acquisition
ImageProcessThread* thread_process = NULL; ///< Thread to process captured image
QVideoFrame* videoFrame = NULL; ///< Object that contains the image buffer to be presented to the video surface
QAbstractVideoSurface* videoSurface = NULL; ///< Object that presents the videoFrame to the outside world
bool exportCvImage = true; ///< Whether to export the CV image
cv::Mat cvImage; ///< Buffer to export the camera image to
unsigned char* cvImageBuf = NULL; ///< Actual physical buffer for cv::Mat, it is helpless without it
/**
* @brief Closes and opens the desired camera with possibly new parameters
*/
void update();
/**
* @brief Allocates an appropriately sized cv::Mat depending on the output size
*/
void allocateCvImage();
/**
* @brief Allocates an appropriately sized and formatted QVideoFrame
*/
void allocateVideoFrame();
signals:
/**
* @brief Emitted after the camera image size has changed
*/
void sizeChanged();
private slots:
/**
* @brief Callback for when image from the camera is received
*/
void imageReceived();
};
#endif // CAMERATOOLBOX_H