我正在尝试使用OpenCV实现卡尔曼滤波器,所以我遵循以下跟踪旋转点的示例(OpenCV 2.4.3):
http://fossies.org/unix/misc/OpenCV-2.4.3.tar.gz:a/OpenCV-2.4.3/samples/cpp/kalman.cpp
我正在使用OpenCV 2.4.2和QtCreator 4.7.4。所有编译都很好,但是当我在这段代码的末尾执行程序崩溃时:
int main(int, char**)
{
help();
Mat img(500, 500, CV_8UC3);
KalmanFilter KF(2, 1, 0);
Mat state(2, 1, CV_32F); /* (phi, delta_phi) */
Mat processNoise(2, 1, CV_32F);
Mat measurement = Mat::zeros(1, 1, CV_32F);
char code = (char)-1;
for(;;)
{
randn( state, Scalar::all(0), Scalar::all(0.1) );
KF.transitionMatrix = *(Mat_<float>(2, 2) << 1, 1, 0, 1);
setIdentity(KF.measurementMatrix);
setIdentity(KF.processNoiseCov, Scalar::all(1e-5));
setIdentity(KF.measurementNoiseCov, Scalar::all(1e-1));
setIdentity(KF.errorCovPost, Scalar::all(1));
randn(KF.statePost, Scalar::all(0), Scalar::all(0.1));
for(;;)
{
Point2f center(img.cols*0.5f, img.rows*0.5f);
float R = img.cols/3.f;
double stateAngle = state.at<float>(0);
Point statePt = calcPoint(center, R, stateAngle);
Mat prediction = KF.predict(); //it crashes here
...
我也试过这个教程(OpenCV 2.2),它也在同一点崩溃:.predict()函数:
QtCreator没有显示错误代码,所以我无法弄清楚这里发生了什么。我已经检查了其他帖子,他们说问题可能是矩阵的大小不同,但我怀疑这个例子适用于其他试过它的人......
任何人都可以给我一个如何解决这个问题的提示?
非常感谢你!!