-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMOG2.cpp
49 lines (41 loc) · 1.03 KB
/
MOG2.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
#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>
#include <time.h>
using namespace std;
using namespace cv;
int main(void) {
Mat frame;
Mat back, fore, oldfore;
VideoCapture cap("C:\\Users\\Administrator\\Desktop\\Study\\4학년\\공프기\\OpenCV\\TrafficExample\\traffic.mp4");
int start = 0;
BackgroundSubtractorMOG2 bg;
namedWindow("Frame");
namedWindow("Background");
namedWindow("Foreground");
namedWindow("oldForeground");
while (1) {
cap >> frame;
if (!frame.data) {
cout << "end" << endl;
break;
}
//foreground 계산
bg(frame, fore);
bg.getBackgroundImage(back);
erode(fore, fore, Mat());
dilate(fore, fore, Mat());
if (start == 0) {
oldfore = fore.clone();
start = 1;
}
else
oldfore += fore.clone(); //oldfore는 그냥 차들이 지나간 영역을 계속 더하는 역할.
imshow("Frame", frame);
// imshow("Foreground", fore);
imshow("Background", back);
//imshow("oldForeground", oldfore);
if (waitKey(1) >= 0) break;
}
return 0;
}