Kaushik Acharya
Kaushik Acharya

Reputation: 1590

Kalman Filter : some doubts

I have several questions:

  1. In the example given in openCV document:

    /* generate measurement */ cvMatMulAdd( kalman->measurement_matrix, state, measurement, measurement );

Is this correct? In the tutorial: An Introduction to the Kalman Filter by Welch and Bishop in Equation 1.2 it says measurement = H*state + measurement noise

Doesn't seems both are same.

  1. I was trying to implement bouncing ball tracking for a single ball. I tried the following: (Please point out if I am doing it incorrectly.)

For the measurement I am measuring two things: a) x b) y of the centroid of the ball.

I am just mentioning lines which are different from the example given in opencv documentation.

CvKalman* kalman = cvCreateKalman( 5, 2, 0 );
const float A[] = { 1, 0, 1, 0, 0,
        0, 1, 0, 1, 0,
        0, 0, 1, 0, 0,
        0, 0, 0, 1, 1,
        0, 0, 0, 0, 1};

CvMat* state = cvCreateMat( 5, 1, CV_32FC1 );
CvMat* measurement = cvCreateMat( 2, 1, CV_32FC1 );

//initialize the state of kalman filter
            state->data.fl[0] = mean_c;
            state->data.fl[1] = mean_r;
            state->data.fl[2] = mean_c - prev_mean_c;
            state->data.fl[3] = mean_r - prev_mean_r;
            state->data.fl[4] = 9.81;

after initialization, this is what gives crash

cvMatMulAdd( kalman->transition_matrix, state, kalman->process_noise_cov, state );

Upvotes: 4

Views: 1682

Answers (1)

Andrey Sboev
Andrey Sboev

Reputation: 7672

  1. In this line they just use variable measurement to store noise. See previous line:

    cvRandArr( &rng, measurement, CV_RAND_NORMAL, cvRealScalar(0),cvRealScalar(sqrt(kalman->measurement_noise_cov->data.fl[0])) );

  2. You should change dimension of H matrix as well. It must be 5 by 2 to make it possible to calculate H*state + measurement noise. You get an error probably in line

    memcpy( cvkalman->measurement_matrix->data.fl, H, sizeof(H));

because in initial example cvkalman->measurement_matrix and H are allocated as 4 by 4 matrices and you decreased dimension of cvkalman->measurement_matrix only to 5 by 2 (4*4 is more than 5*2)

Upvotes: 4

Related Questions