私はOpenCVを使用して、Webカメラで見たボールの動きを予測していました。ただし、cvKalmanPredict状態でエラーが発生し続けるため、コードを次の数行に簡略化して、フィルターのみをテストしてみます。
CvKalman* kalman = cvCreateKalman(6,3,1);
kalman->temp2 = cvCreateMat(1, 1, CV_32FC1);
float alpha = 0.1, beta = 0.2;
float kalmA[] = {1.0+t0/t1, 0, 0, -t0/t1, 0, 0,
0, 1.0+t0/t1, 0, 0, -t0/t1, 0,
0, 0, 1.0+t0/t1, 0, 0, -t0/t1,
1, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0};
float kalmB[] = {0, 0, 1, 0, 0, 0};
float kalmH[] = {1, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0};
float kalmQ[] = {alpha, 0, 0, 0, 0, 0,
0, alpha, 0, 0, 0, 0,
0, 0, beta, 0, 0, 0,
0, 0, 0, alpha, 0, 0,
0, 0, 0, 0, alpha, 0,
0, 0, 0, 0, 0, beta};
float kalmR[] = {alpha, 0, 0,
0, alpha, 0,
0, 0, beta};
float kalmS[] = {0,0,0, 0, 0, 0};
float kalmP[] = {480, 0, 0, 0, 0, 0,
0, 480, 0, 0, 0, 0,
0, 0, 480, 0, 0, 0,
0, 0, 0, 480, 0, 0,
0, 0, 0, 0, 480, 0,
0, 0, 0, 0, 0, 480};
memcpy( kalman->transition_matrix->data.fl, kalmA, sizeof(kalmA) );
memcpy( kalman->control_matrix->data.fl, kalmB, sizeof(kalmB) );
memcpy( kalman->measurement_matrix->data.fl, kalmH, sizeof(kalmH) );
memcpy( kalman->process_noise_cov->data.fl, kalmQ, sizeof(kalmQ) );
memcpy( kalman->measurement_noise_cov->data.fl, kalmR, sizeof(kalmR) );
// initialize state and covariance
memcpy( kalman->state_post->data.fl, kalmS, sizeof(kalmS) );
cvSetIdentity( kalman->error_cov_post, cvRealScalar(3));
// update the control
float t0 = 0.3;
cvSetReal2D( kalman->temp2, 0, 0, -490 * t0 * t0 );
const CvMat* kalmanPred = cvKalmanPredict(kalman, kalman->temp2);
CvMat* kalmMeas = cvCreateMat(3,1,CV_32FC1);
cvSetReal2D(kalmMeas, 0, 0, 3);
cvSetReal2D(kalmMeas, 1, 0, 2);
cvSetReal2D(kalmMeas, 2, 0, 5.5);
cvKalmanCorrect(kalman, kalmMeas);
cvReleaseMat(&kalmMeas);
// release memory
ただし、cvKalmanPredictを呼び出すと、同じエラーが発生します。
OpenCV Error: Assertion failed ((D.rows == ((flags & CV_GEMM_A_T) == 0 ? A.rows : A.cols)) && (D.cols == ((flags & CV_GEMM_B_T) == 0 ? B.cols : B.rows)) && D.type() == A.type() in unknown function. file C:\Users\opencv\modules\core\src\matmul.cpp. line 2930
コンパイルにはMSVisualC++10でcmakeを使用しています。