-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcapturecontroller.hpp
88 lines (74 loc) · 2.09 KB
/
capturecontroller.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
81
82
83
84
85
86
87
88
#ifndef CAPTURECONTROLLER_HPP
#define CAPTURECONTROLLER_HPP
#include <QObject>
#include <QThread>
#include <opencv2/core.hpp>
namespace cv {
class VideoCapture;
}
class QReadWriteLock;
class CaptureController;
class CaptureWorker : public QObject
{
Q_OBJECT
public:
explicit CaptureWorker(const QString &device, CaptureController *captureController, QObject *parent = nullptr);
/**
* @brief stop Stops capture and exits doWork() loop
*/
void stop();
signals:
void frameReady();
void workDone();
public slots:
void doWork();
private:
friend class CaptureController;
QString m_device;
cv::VideoCapture *m_capture;
CaptureController *m_captureController;
cv::Mat m_frame;
bool m_loopRunning;
bool m_useUndistort;
cv::Mat m_intrinsic;
cv::Mat m_distCoeffs;
};
class CaptureController : public QObject
{
Q_OBJECT
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
public:
explicit CaptureController(QObject *parent = nullptr);
~CaptureController();
const cv::Mat frameRef() const;
cv::Mat frameCopy() const;
/**
* @brief The Status enum
*/
enum class Status {
Starting, ///< Capture is in startup
Started, ///< Capture successfully started and frameReady() signals is emitting
Stopped, ///< Initial state or after @see stop() was called
EofOrDisconnected, ///< Video file ended or camera was disconnected
Failed ///< After Starting if it wasn't successful
};
Q_ENUM(Status)
Status status() const;
void enableUndistort(const cv::Mat &intrinsic, const cv::Mat &distCoeffs);
public slots:
void start(const QString &device);
void stop();
signals:
void statusChanged();
void frameReady();
//void statisticsReady(QVariant ?
private:
friend class CaptureWorker;
CaptureWorker* m_worker;
QThread m_workerThread;
mutable QReadWriteLock* m_lock;
mutable QReadWriteLock* m_undistortLock;
void setStatus(Status status);
Status m_status;
};
#endif // CAPTURECONTROLLER_HPP