OpenCV KalmanFilter Python3不起作用

时间:2017-10-06 14:25:43

标签: python opencv kalman-filter

我尝试在python中使用open cv的卡尔曼滤波器。每当我打电话给'#34;正确"它就会崩溃。功能。 我认为这里的代码是不言自明的。

是我吗? OpenCV? python绑定(即它是否可以在C ++中工作)?

欢迎任何帮助。 虚拟代码和输出低于或on github

#!/usr/bin/env python3
import numpy as np
import cv2, numpy as np
kalman = cv2.KalmanFilter(3,3,3,cv2.CV_64F)     #Declare 3 dynamical         parameter 3 state parameter 3 control parameter
kalman.transitionMatrix=1.0*np.eye(3)           #Transition set to identity only the control and the noise are changing the state
#Dummy measurement matrix,  3 measurement each times !
kalman.measurementMatrix=np.matrix([[1.0,2.2,3.10],
                [1.1,2.2,3.30],
                [1.2,2.4,3.70],
                [1.3,2.430,3.50],
                [1.5,2.50,3.340],
                [1.5,2.60,3.70],
                [1.7,2.0,3.30],
                [1.9,2.30,3.20],
                [1.0,2.40,3.50],
                [1.3,2.60,3.60],
                [1.4,2.20,3.20],
                [1.6,2.0,3.20]])

kalman.measurementNoiseCov=1.1*np.eye(3)
kalman.processNoiseCov=1.2*np.eye(3)
kalman.controlMatrix=1.0*np.eye(3)

uk=np.matrix([[0.0],
    [1.2],
    [1.4]])

print("Now checking")
print("Measurement Matrix")
print(kalman.measurementMatrix)
print("Transition Matrix")
print(kalman.transitionMatrix)
print("MeasurementNoiseCov")
print(kalman.measurementNoiseCov)
print("ProcessNoiseCov")
print(kalman.processNoiseCov)
print("ControlMatrix")
print(kalman.controlMatrix)

print("Now attempted to make use of the underdocumented kalman filter in opencv with python ;)")
predicted=kalman.predict(uk)
print("Predicted:")
print(predicted)
print("Will (try to) correct by feeding directly the predicted to correction")
print("So here OpenCV is telling me that KF can not correct its own prediction even though the KF here has same number of dynamical,state and control parameters ?\n...")
estimated=kalman.correct(predicted)

输出(只是崩溃的行)

OpenCV Error: Assertion failed (C.type() == type && (((flags&GEMM_3_T) == 0 && C.rows == d_size.height && C.cols == d_size.width) || ((flags&GEMM_3_T) != 0 && C.rows == d_size.width && C.cols == d_size.height))) in gemm, file /io/opencv/modules/core/src/matmul.cpp, line 1588
Traceback (most recent call last):
  File "./opencvhorror.py", line 46, in <module>
estimated=kalman.correct(predicted)
cv2.error: /io/opencv/modules/core/src/matmul.cpp:1588: error: (-215) C.type() == type && (((flags&GEMM_3_T) == 0 && C.rows == d_size.height && C.cols == d_size.width) || ((flags&GEMM_3_T) != 0 && C.rows == d_size.width && C.cols == d_size.height)) in function gemm

1 个答案:

答案 0 :(得分:0)

好的,我的傻错...... 我混淆了测量矩阵和测量.... 因此,矩阵的大小不正确