2017-10-06 155 views
0

我嘗試在python中使用開放式cv的卡爾曼濾波器。每次我調用「正確」函數時,它都會崩潰。 我認爲這裏的代碼是不言自明的。OpenCV KalmanFilter Python3將不起作用

是我嗎? 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 
+0

請包括您的輸出,包括您收到的錯誤的完整堆棧跟蹤。 –

+0

對不起,我剛剛編輯了問題並添加了輸出。應該早點完成。 – user198530

回答

0

確定我的傻錯誤... 我混淆測量矩陣和測量... 因此,矩陣的大小不正確