我正在尝试使用卡尔曼跟踪器跟踪物体的速度和位置。
为此,我有两个探测器返回边界框,但没有传感器返回速度,因此我使用状态转移矩阵间接跟踪它。
因此,动态参数的数量将为8(4个坐标,每个坐标都有一个速度)
测量总共有8个坐标(因为有2个探测器)。目前我正在制作测量,因为我正在测试卡尔曼滤波器类。
每个边界框的格式为-[x1、y1、x2、y2],即左上角、右下角(LTRB)
这是我正在使用的代码
import numpy as np
import cv2
from scipy.linalg import block_diag
dt = 1.
dynamicParams = 8
measurementParams = 8
transitionMatrix = 1. * np.array([[1., dt, 0, 0, 0, 0, 0, 0],
[0, 1., 0, 0, 0, 0, 0, 0],
[0, 0, 1., dt, 0, 0, 0, 0],
[0, 0, 0, 1., 0, 0, 0, 0],
[0, 0, 0, 0, 1., dt, 0, 0],
[0, 0, 0, 0, 0, 1., 0, 0],
[0, 0, 0, 0, 0, 0, 1., dt],
[0, 0, 0, 0, 0, 0, 0, 1.]], dtype = np.float32)
measurementMatrix = 1. * np.array([[1., 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1., 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1., 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1., 0],
[1., 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1., 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1., 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1., 0]], dtype = np.float32
)
L = 10.0
# All velocity and positions vectors are completely independant of each other
P = 1. * np.diag(L * np.ones(8))
# prev_cov is just a temp variable to update self.P, P is the state covariance
prev_cov = P
# Initialize the covariance of the process noise
Q_comp_mat = 1. * np.array([[dt ** 4 / 4., dt ** 3 / 2.],
[dt ** 3 / 2., dt ** 2]] , dtype = np.float32)
Q = 1. * block_diag(Q_comp_mat, Q_comp_mat,
Q_comp_mat, Q_comp_mat)
R_scaler = 1.0
R_diag_array = 1. * R_scaler * np.array([L, L, L, L, L, L, L, L] , dtype = np.float32)
R = 1. * np.diag(R_diag_array)
processNoiseCov = 1. * Q
measurementNoiseCov = 1. * R
errorCovPost = 1. * np.array([0.])
statePost = 1. * np.array([0.])
tracker = cv2.KalmanFilter(dynamicParams, measurementParams)
tracker.transitionMatrix = 1. * transitionMatrix
tracker.measurementMatrix = 1. * measurementMatrix
tracker.processNoiseCov = 1. * processNoiseCov
tracker.measurementNoiseCov = 1. * measurementNoiseCov
tracker.errorCovPost = errorCovPost
tracker.statePost = statePost
measurement = tracker.measurementNoiseCov * np.random.randn(1, 1)
#measurement = np.array([[1,1,1,1] , [2,2,2,2]])
#pdb.set_trace()
prediction = tracker.predict()
dummy = tracker.correct(measurement)
最后一行的第二行抛出一个错误:cv2.error: OpenCV(4.1.0) ../modules/core/src/matmul.dispatch.cpp:337: error: (-215:Assertion failed) type == B.type() in function 'gemm'
我无法使用PyCharm的调试器对此进行调试,因为该函数没有代码
OpenCV版本:4.1.0
Python版本:3.7.4
请要求进一步澄清
您必须为^{} 的
errorCovPost
和statePost
设置正确的类型:errorCovPost = 1. * np.array([0.])
statePost = 1. * np.array([0.])
相关问题 更多 >
编程相关推荐