0

I have OpenCv 2.4.8 installed and, for the most part, working on Python 2.7 (I'm on Ubuntu).

Everything seems to be working fine with OpenCv. However, the following code

import numpy as np
kalman = cv2.KalmanFilter(4,2)
kalman.measurementMatrix = np.array([[1,0,0,0],[0,1,0,0]],np.float32)

gives me this error:

AttributeError: 'cv2.KalmanFilter' object has no attribute 'measurementMatrix'

Indeed, dir(kalman) shows that only correct() and predict() are the only functions or variables that aren't built-in. No transitionMatrix, processNoiseCov or measurementNoiseCov are present.

Does anyone know what the problem here could be?

Argon
  • 111
  • 6

1 Answers1

0

So, what it seems you need to do is get pyKalman rather than using the opencv one. From my quick search, all that is available from opencv is what you mention:

'KERNEL_SYMMETRICAL', 'KMEANS_PP_CENTERS', 'KMEANS_RANDOM_CENTERS', 'KMEANS_USE_INITIAL_LABELS', 'KNearest', 'KalmanFilter', 'KeyPoint', 'LEV_MARQ_CALC_J', 'LEV_MARQ_CHECK_ERR', 'LEV_MARQ_DONE', 'LEV_MARQ_STARTED', 'LMEDS', 'LUT', 'Laplacian', 'MAGIC_MASK',

You could also just implement your own defintion.

Please do read these: http://filterpy.readthedocs.io/en/latest/kalman/KalmanFilter.html https://arxiv.org/ftp/arxiv/papers/1204/1204.0375.pdf Is there any example of cv2.KalmanFilter implementation?

Sorry I couldn't get your answer all sorted out.

--EDIT--

According to the documentation you may use:

cv2.KalmanFilter.correct(measurement) → retval

import numpy as np
import cv2
import cv2.cv as cv

kalman = cv2.KalmanFilter(4,2)
X = np.array([[1,0,0,0],[0,1,0,0]],np.float32)
Y=kalman.correct(X)

The first problem I notice is that after the first line where the Kalman filter is defined, the filter as such is not shown in my variable explorer. The numpy array does show but it makes me wonder about the Kalman.

Further when I use Y=Kalman.correct(X) there is a problem with dimensions, but at least it is one step closer. I also find it odd that the documentation says I can define a CV_32F or CV_64F, as type in the KalmanFilter, but I just can't get it to work!!!

source:

http://docs.opencv.org/2.4/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=kalman%20python#cv.CreateKalman

Community
  • 1
  • 1
Joseph
  • 71
  • 4
  • The variables I mention are in the documentation. Moreover, I can find them on the OpenCV I installed on my Python 3. – Argon Jun 07 '16 at 09:00
  • Alright, so I have digged a bit more into it! - see my edit – Joseph Jun 07 '16 at 09:49
  • I don't understand. I don't want to install more packages, especially if they can be made to be superfluous. I would prefer to solve why I don't have the variables I should. – Argon Jun 07 '16 at 09:51
  • I know it is annoying. When I implemented the HoughsCircles method I found out a lot of problems and deprecated methods... – Joseph Jun 07 '16 at 10:03