I wan to use Opencv Kalman filter implementation for smooth some noise points. So I\'ve tried to code a simple test for it.
Let\'s say I have an observation (a point
I didn't set the transition and measurement matrix.
I have found standard state-space values for those matrix in this excellent MATLAB documentation page.
For those people who still have problem in using OpenCV Kalman filtering
The above posted code works well after small modification. Instead of setting transition matrix to Identity, you can set as follows.
Modification
KF.transitionMatrix = *(Mat_<float>(4, 4) << 1,0,1,0, 0,1,0,1, 0,0,1,0, 0,0,0,1);
Output
After every prediction, you should copy the predicted state (statePre) into the corrected state (statePost). This should also be done for the state covariance (errorCovPre -> errorCovPost). This prevents the filter from getting stuck in a state when no corrections are executed. The reason is that predict() makes use of the state values stored in statePost, that do not change if no corrections are called.
Your kalmanPredict function will then be as follows:
Point kalmanPredict()
{
Mat prediction = KF.predict();
Point predictPt(prediction.at<float>(0),prediction.at<float>(1));
KF.statePre.copyTo(KF.statePost);
KF.errorCovPre.copyTo(KF.errorCovPost);
return predictPt;
}