0
votes

I've implemented OpenCV's Kalman filter in a previous C++ project and I am now trying to use it in the context of a class.

This is how I usually construct my Kalman filter:

cv::KalmanFilter KF(4,2,0);

I am now trying to have the filter as a member of a class and I'm having trouble initialising it.

I have tried:

1)

class foo
{
public:
...
private:
  cv::KalmanFilter m_filter(4,2,0);
};

And I get the following error:

error: expected identifier before numeric constant cv::KalmanFilter m_filter(4,2,0); ^ foo.hpp:31:39: error: expected ‘,’ or ‘...’ before numeric constant

2)

If I try to remove the initialisation there and do it in the class constructor with:

.hpp

...
private:
  cv::KalmanFilter m_filter;

.cpp

constructor(...)
{
  m_filter(4,2,0);
}

I get:

error: no match for call to ‘(cv::KalmanFilter) (int, int, int)’ m_filter(4,2,0); ^

1
you can simply do constructor(...) : m_filter(4,2,0) {...}Dmitrii Z.
Do you happen to release m_filter anywhere? Say, in foo's destructor.Dmitrii Z.
@DmitriiZ. Your method works, thanks!Nicolas Gaborel
I don't release m_filter, should I?Nicolas Gaborel
No, you should not.Dmitrii Z.

1 Answers

1
votes

After fiddling around with cv::KalmanFilter's constructor, the code finally compiles with the following private declaration:

...
private:
        cv::KalmanFilter m_filter{cv::KalmanFilter(4,2,0)};