Skip to content

Commit 424307b

Browse files
committed
silght changes for better reading
1 parent b902017 commit 424307b

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

sort-c++/KalmanTracker.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ void KalmanTracker::init_kf(StateType stateMat)
1414
int measureNum = 4;
1515
kf = KalmanFilter(stateNum, measureNum, 0);
1616

17-
//Mat processNoise(stateNum, 1, CV_32F);
1817
measurement = Mat::zeros(measureNum, 1, CV_32F);
1918

2019
kf.transitionMatrix = *(Mat_<float>(stateNum, stateNum) <<
@@ -30,17 +29,16 @@ void KalmanTracker::init_kf(StateType stateMat)
3029
setIdentity(kf.processNoiseCov, Scalar::all(1e-2));
3130
setIdentity(kf.measurementNoiseCov, Scalar::all(1e-1));
3231
setIdentity(kf.errorCovPost, Scalar::all(1));
33-
34-
//randn(kf.statePost, Scalar::all(0), Scalar::all(1));
3532

33+
// initialize state vector with bounding box in [cx,cy,s,r] style
3634
kf.statePost.at<float>(0, 0) = stateMat.x + stateMat.width / 2;
3735
kf.statePost.at<float>(1, 0) = stateMat.y + stateMat.height / 2;
3836
kf.statePost.at<float>(2, 0) = stateMat.area();
3937
kf.statePost.at<float>(3, 0) = stateMat.width / stateMat.height;
4038
}
4139

4240

43-
// Advances the state vector and returns the predicted bounding box estimate.
41+
// Predict the estimated bounding box.
4442
StateType KalmanTracker::predict()
4543
{
4644
// predict
@@ -58,7 +56,7 @@ StateType KalmanTracker::predict()
5856
}
5957

6058

61-
// Updates the state vector with observed bbox.
59+
// Update the state vector with observed bounding box.
6260
void KalmanTracker::update(StateType stateMat)
6361
{
6462
m_time_since_update = 0;
@@ -77,13 +75,15 @@ void KalmanTracker::update(StateType stateMat)
7775
}
7876

7977

78+
// Return the current state vector
8079
StateType KalmanTracker::get_state()
8180
{
8281
Mat s = kf.statePost;
8382
return get_rect_xysr(s.at<float>(0, 0), s.at<float>(1, 0), s.at<float>(2, 0), s.at<float>(3, 0));
8483
}
8584

8685

86+
// Convert bounding box from [cx,cy,s,r] to [x,y,w,h] style.
8787
StateType KalmanTracker::get_rect_xysr(float cx, float cy, float s, float r)
8888
{
8989
float w = sqrt(s * r);
@@ -103,7 +103,7 @@ StateType KalmanTracker::get_rect_xysr(float cx, float cy, float s, float r)
103103

104104
/*
105105
// --------------------------------------------------------------------
106-
// Kalman Filter Demonstrating
106+
// Kalman Filter Demonstrating, a 2-d ball demo
107107
// --------------------------------------------------------------------
108108
109109
const int winHeight = 600;

sort-c++/main.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ typedef struct TrackingBox
4747
}TrackingBox;
4848

4949

50-
// Computes IOU between two Boxes
50+
// Computes IOU between two bounding boxes
5151
double GetIOU(Rect_<float> bb_test, Rect_<float> bb_gt)
5252
{
5353
float in = (bb_test & bb_gt).area();
@@ -60,7 +60,7 @@ double GetIOU(Rect_<float> bb_test, Rect_<float> bb_gt)
6060
}
6161

6262

63-
63+
// global variables for counting
6464
#define CNUM 20
6565
int total_frames = 0;
6666
double total_time = 0.0;
@@ -88,18 +88,7 @@ void TestSORT(string seqName, bool display)
8888
{
8989
cout << "Processing " << seqName << "..." << endl;
9090

91-
// 1. read detection file
92-
ifstream detectionFile;
93-
string detFileName = "data/" + seqName + "/det.txt";
94-
detectionFile.open(detFileName);
95-
96-
if (!detectionFile.is_open())
97-
{
98-
cerr << "Error: can not find file " << detFileName << endl;
99-
return;
100-
}
101-
102-
// randomly generate colors, only for display
91+
// 0. randomly generate colors, only for display
10392
RNG rng(0xFFFFFFFF);
10493
Scalar_<int> randColor[CNUM];
10594
for (int i = 0; i < CNUM; i++)
@@ -114,6 +103,17 @@ void TestSORT(string seqName, bool display)
114103
display = false;
115104
}
116105

106+
// 1. read detection file
107+
ifstream detectionFile;
108+
string detFileName = "data/" + seqName + "/det.txt";
109+
detectionFile.open(detFileName);
110+
111+
if (!detectionFile.is_open())
112+
{
113+
cerr << "Error: can not find file " << detFileName << endl;
114+
return;
115+
}
116+
117117
string detLine;
118118
istringstream ss;
119119
vector<TrackingBox> detData;
@@ -134,14 +134,14 @@ void TestSORT(string seqName, bool display)
134134
}
135135
detectionFile.close();
136136

137+
// 2. group detData by frame
137138
int maxFrame = 0;
138-
for (auto tb : detData)
139+
for (auto tb : detData) // find max frame number
139140
{
140141
if (maxFrame < tb.frame)
141142
maxFrame = tb.frame;
142143
}
143144

144-
// 2. group detData by frame
145145
vector<vector<TrackingBox>> detFrameData;
146146
vector<TrackingBox> tempVec;
147147
for (int fi = 0; fi < maxFrame; fi++)
@@ -350,7 +350,7 @@ void TestSORT(string seqName, bool display)
350350
for (auto tb : frameTrackingResult)
351351
resultsFile << tb.frame << "," << tb.id << "," << tb.box.x << "," << tb.box.y << "," << tb.box.width << "," << tb.box.height << ",1,-1,-1,-1" << endl;
352352

353-
if (display)
353+
if (display) // read image, draw results and show them
354354
{
355355
ostringstream oss;
356356
oss << imgPath << setw(6) << setfill('0') << fi + 1;

0 commit comments

Comments
 (0)