-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideothread.h
123 lines (96 loc) · 3.01 KB
/
videothread.h
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
115
116
117
118
119
120
121
122
123
#ifndef VIDEOTHREAD_H
#define VIDEOTHREAD_H
//Qt Headers
#include <QThread>
#include <QStringList>
#include <QtCore>
#include <QDateTime>
#include <QFileInfo>
//Windows headers
#include "Windows.h"
//OpenCV Headers
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/video.hpp>
#include <opencv2/imgproc/imgproc.hpp>
//C++ Headers
#include <iostream>
#include <ctime>
#include "WeightedMovingVarianceBGS.h"
using namespace std;
using namespace cv;
class videoThread : public QThread
{
Q_OBJECT
public:
explicit videoThread(QObject *parent = 0);
//Thread Control functions
void run(); //Overwrite qthread 'run' function as the main function of this thread. When thread starts, it starts here
void resume(); //Self defined resume and pause functions. Use QMutex.
void pause(); //Used for pausing and resuming thread when a dialog needs to collect user preference
bool Stop; //No built-in thread stop function. Use a flag to denote whether to stop.
bool pauseFlag; //To help determine whether the resizing process is stopped by user or finished naturally
string videoFileName;
Mat frame;
double H ; //Horizontal distance
double D ; //Diameter of horizontal pipe
int fps;
string videoSaveAddress;
private:
QMutex sync; //QThread control. lock or unlock
QWaitCondition pauseCond; //QThread pause condition
WeightedMovingVarianceBGS* bgs;
Mat background;
Mat bgModel;
VideoCapture capture;
VideoWriter wtr;
int width;
int height;
int totalFrameNumber;
int fpsMod;
Mat subFigure;
Mat prev_subFigure;
string getSaveVideoAddress(string tempFileName);
Mat trainedSubfigure;
vector<Point> contour;
Mat img_closing;
const double THRESHOLD_WHITE = 0.002;
int morph_size = 10;
Mat element = getStructuringElement( MORPH_RECT, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) );
void init();
bool detectMotion();
vector<vector<Point> > contours;
void deleteSmallContours(int contour_size);
bool overflowDetected;
double compareHistogram(Mat img1, Mat img2);
int correct[3];
double measureOverflow(Mat& subClosing);
double prev2_A = 0;
double prev2_B = 0;
double prev2_C = 0;
double prev_A = 0;
double prev_B = 0;
double prev_C = 0;
double prev_area = 0;
double prev2_area = 0;
double prev_v = 0;
double prev2_v = 0;
const int TARGET_FPS = 5;
const int TARGET_RESOLUTION_HEIGHT = 854;
const int TARGET_RESOLUTION_WIDTH = 480;
const int MOTION_THRESHOLD = 0.0001;
const Scalar redColor = cv::Scalar( 0, 0, 255 );
int findContoursOnMotion();
void checkOverflow(int contour_size, int cnt);
Mat and_mask;
vector<Vec4i> hierarchy;
Mat subClosing;
int prepareMeasurement();
signals:
void showResult(Mat);
void flowRate(int, double);
void videoProgress(double);
void finished(bool);
public slots:
};
#endif // VIDEOTHREAD_H