1

我正在尝试在 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() 函数:

http://www.morethantechnical.com/2011/06/17/simple-kalman-filter-for-tracking-using-opencv-2-2-w-code/comment-page-1/#comment-34618

QtCreator 没有显示错误代码,所以我无法弄清楚这里发生了什么。我检查了其他帖子,他们说问题可能是矩阵的大小不同,但我怀疑因为这个例子适用于其他尝试过它的人......

任何人都可以给我一个关于如何解决这个问题的提示?

非常感谢您提前!!

4

0 回答 0