forked from Epipolarna/Tracking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracking.cpp
123 lines (101 loc) · 4.46 KB
/
tracking.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
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
#include "Modules/FrameList.h"
#include "Modules/BackgroundModelling/BackgroundModel.h"
#include "Modules/BackgroundModelling_simple/BackgroundModel_simple.h"
#include "Modules/ForegroundProcessing/ForegroundProcessor.h"
#include "Modules/ObjectIdentification/Identification.h"
#include "Modules/Prediction/Kalman.h"
#include "Modules/Evaluation/Evaluation.h"
#include "Modules/Profiler.h"
#define PROFILER_INIT() ProfilerClock c;
#define PROFILER_RESET() c.reset();
#define PROFILE(string) frameList.setTime(string, c.getTime()); c.lap();
#define PROFILE_TOTALTIME() frameList.setTime("Total Time", c.getTotalTime());
#define PROFILE_FPS() frameList.setTime("FPS", c.getFPS());
void sampleDown(Mat & source, Mat & destination, int stepSize);
void stepWiseFromFrame(FrameList & frameList, int frameNumber);
int main()
{
PROFILER_INIT();
FrameList frameList(10); // Keep a history of up to 100 frames (might be used by some modules)
// Modules
//BackgroundModelling_simple::BackgroundModel backgroundModel;
BackgroundModelling::BackgroundModel backgroundModel;
ForegroundProcessing::ForegroundProcessor foregroundProcessor;
Identification::Identifier identifier;
Prediction::Kalman kalmanFilter;
Evaluation evaluate(&frameList, 20);
// Init
foregroundProcessor.setAlgortihm(ForegroundProcessing::SLOW); //Use slow, toggle shadows in the init command
foregroundProcessor.init(3, 2, 125, 4, false);
foregroundProcessor.initShadow(0.5, 0.5, 0.3, 0.99);
identifier.init(Identification::Ultimate);
evaluate.readXML2FrameList("clip1.xml");
//evaluate.readXML2FrameList("CAVIAR1/fosne2gt.xml");
int waitForBGConvergence = 60;
// Load frame source
//frameList.open("CAVIAR1/OneStopNoEnter2front.mpg");
//frameList.open("clip1.mpeg");
frameList.open("camera1.mov");
//frameList.open("Renova_20080420_083025_Cam10_0000.mpeg");
//Record video
VideoWriter demo("trackingDemo.mpeg", CV_FOURCC('P','I','M','1'), 20, frameList.movieSize*2);
// Create windows
namedWindow("Info",CV_WINDOW_AUTOSIZE);
namedWindow("Background",CV_WINDOW_AUTOSIZE);
namedWindow("Foreground",CV_WINDOW_AUTOSIZE);
namedWindow("Tracking",CV_WINDOW_AUTOSIZE);
namedWindow("Raw image", CV_WINDOW_AUTOSIZE);
//namedWindow("BackgroundModel",CV_WINDOW_AUTOSIZE);
namedWindow("Evaluation", CV_WINDOW_AUTOSIZE);
while (frameList.queryNextFrame())
{
PROFILER_RESET();
sampleDown(frameList.getLatestFrame().image, frameList.getLatestFrame().image, 1); // Speed up by sampling down the image
// Do the nessecary processing
backgroundModel.update(frameList.getFrames()); PROFILE("BackgroundModel");
if (frameList.getCurrentFrameNumber() > waitForBGConvergence) //Wait for convergence
foregroundProcessor.segmentForeground(frameList.getLatestFrame()); PROFILE("ForegroundSeg.");
identifier.identify(frameList.getFrames()); PROFILE("Identification");
kalmanFilter.predict(frameList.getLatestFrame()); PROFILE("Kalman Prediction");
evaluate.currentFrame(); PROFILE("Evaluation");
// Display result
frameList.display("Tracking");
frameList.displayBackground("Background");
if (frameList.getCurrentFrameNumber() > waitForBGConvergence) //Wait for convergence
frameList.displayForeground("Foreground");
evaluate.displayInfo("Evaluation");
// Give the GUI time to render
waitKey(1); PROFILE("Display");
// Write current frame (and info) to file
demo << frameList.getLatestFrame().demoImage;
// Optional pause between each frame
//stepWiseFromFrame(frameList, 55);
PROFILE("QueryNextFrame");
PROFILE_TOTALTIME();
PROFILE("FPS");
PROFILE_FPS();
// Evaluate accuracy and precision
evaluate.MOTA();
evaluate.MOTP();
// Display info
frameList.displayInfo("Info");
}
evaluate.displaySequenceInfo("Evaluation");
waitKey(0);
return 0;
}
void stepWiseFromFrame(FrameList & frameList, int frameNumber)
{
if (frameList.getCurrentFrameNumber() > frameNumber)
waitKey(0);
}
void sampleDown(Mat & source, Mat & destination, int stepSize)
{
Mat temp = source.clone();
destination = Mat(temp.size().height/stepSize, temp.size().width/stepSize, CV_8UC3);
for(int r1=0, r2=0; r1 < temp.size().height; r1+=stepSize, r2++){
for(int c1=0, c2=0; c1 < temp.size().width; c1+=stepSize, c2++){
destination.at<Vec3b>(r2, c2) = temp.at<Vec3b>(r1, c1);
}
}
}