Appuru
Appuru

Reputation: 417

KalmanFilter Tracking in openCV - Program received signal SIGSEGV

I wanted to test the KalmanFilter for tracking purposes and found several tutorials which all look pretty similar overall (as it is mostly initializing openCVs KalmanFilter and setting up parameters).

I went after this implementation: https://github.com/screename/Kalman-Filter-Tracker/blob/master/KalmanFilterTracker.ccp

I'm having trouble testing it now though because whenever I start the program it crashes. There's no build-errors but when I start the debugging it shows a short message of "Program received signal SIGSEGV - segmentation fault.

The Call Stack shows that there's problems with mat.hpp in the line 574:

int i = i0/cols, j = i0 - i*cols;

and also at line 1043:

template<typename _Tp> inline _Tp& Mat_<_Tp>::operator ()(int i0)
{
     return this->at<_Tp>(i0);
}

Within the KalmanFilter class these lines seem to be troubling:

measurement(0) = x;
measurement(1) = y;

with

Mat_<float> measurement;

and initializing it with

measurement(2, 1);
measurement.setTo(Scalar(0));

Any idea on what might be causing the problems here and/or how to fix it? I tried a few things before but haven't found the cause so far. I appreciate any help.

Upvotes: 0

Views: 229

Answers (1)

berak
berak

Reputation: 39796

i bet you wanted:

Mat_<float> measurement(2, 1);  // alloc 2 rows, 1 col
measurement.setTo(Scalar(0));

not:

Mat_<float> measurement; // an *empty* Mat.
measurement(2, 1);       // invalid access on an *empty* Mat (would be out of bounds, too)

Upvotes: 2

Related Questions