let Kalman handle the missing measurements (bug #1380)

This commit is contained in:
Vadim Pisarevsky 2012-10-12 14:01:36 +04:00
parent 2abb67cc92
commit cb58e5a3a4
2 changed files with 8 additions and 1 deletions

View File

@ -172,6 +172,9 @@ cvKalmanPredict( CvKalman* kalman, const CvMat* control )
cvGEMM( kalman->temp1, kalman->transition_matrix, 1, kalman->process_noise_cov, 1,
kalman->error_cov_pre, CV_GEMM_B_T );
/* handle the case when there will be measurement before the next predict */
cvCopy(kalman->state_pre, kalman->state_post);
return kalman->state_pre;
}
@ -261,6 +264,9 @@ const Mat& KalmanFilter::predict(const Mat& control)
// P'(k) = temp1*At + Q
gemm(temp1, transitionMatrix, 1, processNoiseCov, 1, errorCovPre, GEMM_2_T);
// handle the case when there will be measurement before the next predict.
statePre.copyTo(statePost);
return statePre;
}

View File

@ -82,7 +82,8 @@ int main(int, char**)
line( img, statePt, measPt, Scalar(0,0,255), 3, CV_AA, 0 );
line( img, statePt, predictPt, Scalar(0,255,255), 3, CV_AA, 0 );
KF.correct(measurement);
if(theRNG().uniform(0,4) != 0)
KF.correct(measurement);
randn( processNoise, Scalar(0), Scalar::all(sqrt(KF.processNoiseCov.at<float>(0, 0))));
state = KF.transitionMatrix*state + processNoise;