Ask Your Question
2

How to control a KalmanFilter using the Java interface ?

asked 2013-07-30 18:08:38 -0600

George Profenza gravatar image

I'm trying to port the code in this KalmanFilter tutorial to Java.

I have no clue how to write this in Java:

KF.statePre.at<float>(0) = mouse_info.x;
KF.statePre.at<float>(1) = mouse_info.y;
KF.statePre.at<float>(2) = 0;
KF.statePre.at<float>(3) = 0;
KF.transitionMatrix = *(Mat_<float>(4, 4) << 1,0,0,0,   0,1,0,0,  0,0,1,0,  0,0,0,1);

I couldn't find any fields or any setters for statePre or transitionMatrix.

The javadocs state:

The class implements a standard Kalman filter http://en.wikipedia.org/wiki/Kalman_filter, [Welch95]. However, you can modify transitionMatrix, controlMatrix, and measurementMatrix to get an extended Kalman filter functionality. See the OpenCV sample kalman.cpp.

but I'm guessing this is valid for c++, not java.

Is there a way to control the KalmanFilter in Java ? If so, how ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-07-31 02:05:30 -0600

berak gravatar image

"but I'm guessing this is valid for c++, not java."

unfortunately, yes.


the problem here is, that there are no public setters, and the wrapper mechanism ignores public member vars. ( same problem applies to python, too )

a simple :

CV_WRAP void setTransitionMatrix( const Mat & trans ) {
    transitionMatrix = trans;
}

in the Kalman class would solve the problem ( the CV_WRAP tag would make the wrappers bind it )


on the other hand, i doubt, that setting KF.statePre makes any sense, that'll be overwritten in the predict method anyway. and the eye-matrix you're using for the transition is the default value already.

edit flag offensive delete link more

Comments

hmmm, I might need to go the CV_WRAP option. Where would I make that change ? Would that be in Mat.java in the java wrapper ? Also, I've tried commenting out as much as possible to get the sample to bare minimum (code here) but it still looks like I need to access setIdentity(KF.measurementMatrix); and other KF properties. Thanks for the suggestions(+1), looking forward to see your suggestion

George Profenza gravatar imageGeorge Profenza ( 2013-07-31 17:49:24 -0600 )edit

no, not in the java wrapper, in the c++ source for the kalman filter , unfortunately ( modules/video/include/opencv2/video/tracking.hpp) and recompile that module and the java wrappers

if you need to set other matrices, like the measurement, or the measurementNoiseCov mat, the same receipt applies there (add a setter function).

berak gravatar imageberak ( 2013-08-01 02:43:04 -0600 )edit

Question Tools

Stats

Asked: 2013-07-30 18:08:38 -0600

Seen: 1,102 times

Last updated: Jul 31 '13