Bahramdun Adil
Bahramdun Adil

Reputation: 6079

Is there any example of Kalman Filter with OpenCV in Java?

I am using OpenCV 3.0 beta, I want to use Kalman Filter, but I cannot find any example of the Kalman Filter implementation in Java OpenCV. I have tried the example code in C++ and Python, but I cannot completely translate this code to Java.

Upvotes: 0

Views: 2453

Answers (2)

kiranpradeep
kiranpradeep

Reputation: 11201

The thing you might miss when porting OpenCV C++/Python Kalman filter sample to Java is how to set transition/control or measurement matrices. Unfortunately Opencv java doc(1) for Kalman filter doesn't mention those methods. Hope this code sample(2) from github helps. You might need OpenCV 3.0 though.

KalmanFilter kalman = new KalmanFilter(4, 2, 0, CvType.CV_32F);
Mat transitionMatrix = new Mat(4, 4, CvType.CV_32F, new Scalar(0));
float[] tM = { 1, 0, 1, 0, 
        0, 1, 0, 1,
        0, 0, 1, 0,
        0, 0, 0, 1 } ;
transitionMatrix.put(0,0,tM);
kalman.set_transitionMatrix(transitionMatrix);

Upvotes: 3

ixjlyons
ixjlyons

Reputation: 1

I recommend taking a look at the Efficient Java Matrix Library (ejml). They provide several Kalman filter implementations in the examples (see the KalmanFilterSimple class for a concrete example).

Upvotes: 0

Related Questions