-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDifference.cpp~
executable file
·62 lines (51 loc) · 1.6 KB
/
Difference.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
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include "cv.h"
#include "cvaux.h"
#include "highgui.h"
using namespace std;
/* ****************** *
* Global Variables *
* ****************** */
static int WIDTH = 1280;
static int DELAY = 40;
static int HEIGHT = 960;
int main(int argc, char * argv[])
{
// Select A Video
string filename = "data/d3.avi";
string filename2 = "data/background1.jpg";
CvCapture * vid1 = cvCaptureFromFile(filename.c_str());
// Error Check Video
if (!vid1) {
printf("Could not open video file%s", filename.c_str());
exit(0);
}
// Create a window to display the video
cvNamedWindow( "mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow( "mainWin", 100, 100 );
// Differencing Algorithm
IplImage * frame = cvCreateImage( cvSize(WIDTH, HEIGHT), IPL_DEPTH_8U, 3 );
IplImage * bwframe = cvCreateImage( cvSize(WIDTH, HEIGHT), IPL_DEPTH_8U, 1);
IplImage * difference = cvCreateImage( cvSize(WIDTH, HEIGHT), IPL_DEPTH_8U, 1 );
IplImage * bg = cvLoadImage(filename2.c_str(), 0);
vid1 = cvCaptureFromFile(filename.c_str());
for (int i = 0; i < 449; i++) {
frame = cvQueryFrame( vid1 );
if (i > 47) {
cvCvtColor(frame, bwframe, CV_RGB2GRAY);
cvAbsDiff(bwframe, bg, difference);
cvThreshold(difference, difference, 50, 255, CV_THRESH_BINARY);
cvShowImage( "mainWin", difference);
cvWaitKey(DELAY);
}
}
cvWaitKey(0);
// Exit Status
cout << "Program Completed" << endl;
}