-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaskMat.cpp
71 lines (54 loc) · 1.38 KB
/
MaskMat.cpp
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
//openCV
#include "cv.hpp"
#include "opencv2/opencv.hpp"
//C
#include "RoadDetection.h"
#include <stdio.h>
//C++
#include <iostream>
#include <sstream>
using namespace std;
using namespace cv;
int main(void){
char* videoFilename = "C:\\Users\\Administrator\\Desktop\\Study\\4Çгâ\\°øÇÁ±â\\OpenCV\\TrafficExample\\traffic.mp4";
Mat frame, fore, back, mask;
VideoCapture cap(videoFilename);
int fps = cap.get(CV_CAP_PROP_FPS);
int frame_rate = fps;
int keyboard = 0;
BackgroundSubtractorMOG2 fgbg;
cap >> frame;
if (!cap.isOpened()) {
//error in opening the video input
cerr << "Unable to open video file: " << videoFilename << endl;
exit(EXIT_FAILURE);
}
while (1) {
//read the current frame
if (!cap.read(frame)) {
cerr << "Unable to read next frame." << endl;
cerr << "Exiting..." << endl;
exit(EXIT_FAILURE);
}
//foreground
//fgbg2(frame, fore2);
//cvtColor(frame, frame, CV_BGR2YUV);
fgbg(frame, fore);
//background
fgbg.getBackgroundImage(back);
//gray, binary
mask = LabBgrMask(frame, back);
imshow("ORIGIN", frame);
imshow("MASK", mask);
imshow("FORE", fore);
if (keyboard == 32) {
if (frame_rate == fps)
frame_rate = 0;
else if (frame_rate == 0)
frame_rate = fps;
}
else if (keyboard == 27)
break;
keyboard = (char)waitKey(frame_rate);
}
}