Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

if you are using opencv2.4, i got bad news: the kalmanfilter is not usable.

the internal 'measurementMatrix' variable is set to all 0, so the prediction will be always 0, too.

if you are using opencv3.0, you can set it e.g. to Mat.eye(2,1,CvType.CV_32F);

double[][] samplesArr = {{0,0},{1,0},{1,1},{2,1},{2,2}};

Mat meas = new Mat(2,1,CvType.CV_32F);

KalmanFilter kf = new KalmanFilter(4, 2);

Mat mm = Mat.eye(2,4,CvType.CV_32F);
kf.set_measurementMatrix(mm);  // 3.0 only!

for(int i = 0; i < samplesArr.length; i++)
{
    meas.put(0, 0, samplesArr[i]);
    Mat corr = kf.correct(meas);
    Mat pre = kf.predict();
    System.out.println(pre.t().dump());
}

 [java] [0, 0, 0, 0]
 [java] [0.5, 0, 0, 0]
 [java] [0.80000001, 0.60000002, 0, 0]
 [java] [1.5384616, 0.84615386, 0, 0]
 [java] [1.8235294, 1.5588235, 0, 0]

if you are using opencv2.4, i got bad news: the kalmanfilter is not usable.

the internal 'measurementMatrix' variable is set to all 0, so the prediction will be always 0, too.

if you are using opencv3.0, you can set it e.g. to Mat.eye(2,1,CvType.CV_32F);

double[][] samplesArr = {{0,0},{1,0},{1,1},{2,1},{2,2}};

Mat meas = new Mat(2,1,CvType.CV_32F);

KalmanFilter kf = new KalmanFilter(4, 2);

Mat mm = Mat.eye(2,4,CvType.CV_32F);
kf.set_measurementMatrix(mm);  // 3.0 only!
// you'll want to set other Mat's like errorCovPost and processNoiseCov, too,
// to change the 'adaption speed'

for(int i = 0; i < samplesArr.length; i++)
{
    meas.put(0, 0, samplesArr[i]);
    Mat corr = kf.correct(meas);
    Mat pre = kf.predict();
    System.out.println(pre.t().dump());
}

 [java] [0, 0, 0, 0]
 [java] [0.5, 0, 0, 0]
 [java] [0.80000001, 0.60000002, 0, 0]
 [java] [1.5384616, 0.84615386, 0, 0]
 [java] [1.8235294, 1.5588235, 0, 0]

if you are using opencv2.4, i got bad news: the kalmanfilter is not usable.

by default, the internal 'measurementMatrix' variable is set to all 0, your measurement input will be multiplied by that, - you see it's all dead from here on, so the prediction will be always 0, too.

if you are using opencv3.0, you can set it e.g. to Mat.eye(2,1,CvType.CV_32F);

double[][] samplesArr = {{0,0},{1,0},{1,1},{2,1},{2,2}};

Mat meas = new Mat(2,1,CvType.CV_32F);

KalmanFilter kf = new KalmanFilter(4, 2);

Mat mm = Mat.eye(2,4,CvType.CV_32F);
kf.set_measurementMatrix(mm);  // 3.0 only!
// you'll want to set other Mat's like errorCovPost and processNoiseCov, too,
// to change the 'adaption speed'

for(int i = 0; i < samplesArr.length; i++)
{
    meas.put(0, 0, samplesArr[i]);
    Mat corr = kf.correct(meas);
    Mat pre = kf.predict();
    System.out.println(pre.t().dump());
}

 [java] [0, 0, 0, 0]
 [java] [0.5, 0, 0, 0]
 [java] [0.80000001, 0.60000002, 0, 0]
 [java] [1.5384616, 0.84615386, 0, 0]
 [java] [1.8235294, 1.5588235, 0, 0]