forked from andrewssobral/simple_vehicle_counting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo.cpp
70 lines (55 loc) · 1.69 KB
/
Demo.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
#include <iostream>
#include <opencv2/opencv.hpp>
#include "package_bgs/PBAS/PixelBasedAdaptiveSegmenter.h"
#include "package_tracking/BlobTracking.h"
#include "package_analysis/VehicleCouting.h"
int main(int argc, char **argv)
{
std::cout << "Using OpenCV " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION << std::endl;
/* Open video file */
CvCapture *capture = 0;
capture = cvCaptureFromAVI("dataset/video.avi");
if(!capture){
std::cerr << "Cannot open video!" << std::endl;
return 1;
}
/* Background Subtraction Algorithm */
IBGS *bgs;
bgs = new PixelBasedAdaptiveSegmenter;
/* Blob Tracking Algorithm */
cv::Mat img_blob;
BlobTracking* blobTracking;
blobTracking = new BlobTracking;
/* Vehicle Counting Algorithm */
VehicleCouting* vehicleCouting;
vehicleCouting = new VehicleCouting;
std::cout << "Press 'q' to quit..." << std::endl;
int key = 0;
IplImage *frame;
while(key != 'q')
{
frame = cvQueryFrame(capture);
if(!frame) break;
cv::Mat img_input = cv::cvarrToMat(frame);
cv::imshow("Input", img_input);
// bgs->process(...) internally process and show the foreground mask image
cv::Mat img_mask;
bgs->process(img_input, img_mask);
if(!img_mask.empty())
{
// Perform blob tracking
blobTracking->process(img_input, img_mask, img_blob);
// Perform vehicle counting
vehicleCouting->setInput(img_blob);
vehicleCouting->setTracks(blobTracking->getTracks());
vehicleCouting->process();
}
key = cvWaitKey(1);
}
delete vehicleCouting;
delete blobTracking;
delete bgs;
cvDestroyAllWindows();
cvReleaseCapture(&capture);
return 0;
}