简体   繁体   English

OpenCV的卡尔曼滤波器缺少矩阵

[英]OpenCV's Kalman Filter lacks Matricies

I have OpenCv 2.4.8 installed and, for the most part, working on Python 2.7 (I'm on Ubuntu). 我已经安装了OpenCv 2.4.8,并且大部分情况下都在Python 2.7上工作(我在Ubuntu上)。

Everything seems to be working fine with OpenCv. 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' AttributeError:“ cv2.KalmanFilter”对象没有属性“ measurementMatrix”

Indeed, dir(kalman) shows that only correct() and predict() are the only functions or variables that aren't built-in. 的确, dir(kalman)表明,只有correct()predict()是唯一未内置的函数或变量。 No transitionMatrix , processNoiseCov or measurementNoiseCov are present. 不存在transitionMatrixprocessNoiseCovmeasurementNoiseCov

Does anyone know what the problem here could be? 有谁知道这里可能是什么问题?

So, what it seems you need to do is get pyKalman rather than using the opencv one. 因此,看来您需要做的是获取pyKalman而不是使用opencv。 From my quick search, all that is available from opencv is what you mention: 从我的快速搜索中,您提到的是opencv提供的所有信息:

'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? 务必阅读以下内容: http : //filterpy.readthedocs.io/en/latest/kalman/KalmanFilter.html https://arxiv.org/ftp/arxiv/papers/1204/1204.0375.pdf 是否有cv2的任何示例。 KalmanFilter实现?

Sorry I couldn't get your answer all sorted out. 抱歉,您的答案无法全部解决。

--EDIT-- - 编辑 -

According to the documentation you may use: 根据文档,您可以使用:

cv2.KalmanFilter.correct(measurement) → retval cv2.KalmanFilter.correct(测量)→检索

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. 我注意到的第一个问题是在定义Kalman过滤器的第一行之后,这样的过滤器未在我的变量浏览器中显示。 The numpy array does show but it makes me wonder about the Kalman. numpy数组确实显示了,但这让我对Kalman感到疑惑。

Further when I use Y=Kalman.correct(X) there is a problem with dimensions, but at least it is one step closer. 此外,当我使用Y = Kalman.correct(X)时,尺寸存在问题,但至少距离了一步。 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!!! 我也发现文档说我可以定义一个CV_32F或CV_64F作为KalmanFilter中的类型,这很奇怪,但是我无法使其正常工作!

source: 资源:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM