VAT  3.0
Video Analysis Tool
CameraThread.h
1 #ifndef CAMERATHREAD_H
2 #define CAMERATHREAD_H
3 
4 #include <QThread>
5 #include <opencv2/opencv.hpp>
6 #include <opencv/highgui.h>
7 #include <QTime>
8 
9 #include <QMutex>
10 
14 
15 #define CAMBUFFER_DROP_OLDEST 0
16 #define CAMBUFFER_DROP_NEWEST 1
17 
21 class CameraBuffer {
22 public:
28  CameraBuffer(int n_frames);
29 
39  bool push(cv::Mat &frame, int time_stamp);
40 
50  bool pop(cv::Mat &frame, int &time_stamp);
51 
57  double usage();
58 
59 private:
60  int max_size;
61  int size;
62  int head;
63  int tail;
64  int drop_technique;
65  cv::Mat *frames;
66  int *times;
67 };
68 
72 
73 #define BUFFER_SIZE 10
74 
79 class CameraThread : public QThread
80 {
81  Q_OBJECT
82 public:
89  explicit CameraThread(QObject *parent = 0);
90 
95  void stop();
96 
103  void setup(int device_ID);
104 
112  void setup(QString URL);
113 
123  cv::Mat &get_frame(int &time_stamp);
124 
130  double buffer_usage();
131 
132 signals:
133 
134 public slots:
135 
136 private:
137  void run();
138 
139  QString mediaURL;
140  int deviceID;
141  cv::VideoCapture camera;
142  CameraBuffer *buffer;
143  QTime marca_pasos;
144  QMutex camera_mutex;
145 };
146 
147 #endif // CAMERATHREAD_H
bool push(cv::Mat &frame, int time_stamp)
Image frame insertion to the buffer method.
Definition: CameraThread.cpp:19
The CameraThread class is used as a Thread class to parallelly capture video frames from camera...
Definition: CameraThread.h:79
CameraBuffer(int n_frames)
CameraBuffer constructor.
Definition: CameraThread.cpp:9
double usage()
Buffer occupation ratio method.
Definition: CameraThread.cpp:53
bool pop(cv::Mat &frame, int &time_stamp)
Image frame recovery from the buffer method.
Definition: CameraThread.cpp:42
The CameraBuffer class is used to store captured frames from camera before use them.
Definition: CameraThread.h:21