@@ -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.
4442StateType 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 .
6260void 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
8079StateType 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.
8787StateType 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
109109const int winHeight = 600;
0 commit comments