gpt4 book ai didi

python - 适用于Python3的OpenCV卡尔曼滤波器

转载 作者:行者123 更新时间:2023-12-02 16:23:46 37 4
gpt4 key购买 nike

我正在尝试使用Kalman Tracker跟踪对象的速度和位置。
为此,我有2个检测器返回边界框,但没有传感器返回速度,因此我使用状态转换矩阵间接跟踪了它。
因此,动态参数的数量将为8(4个坐标,每个坐标都有一个速度)
该测量总共有8个坐标(因为有2个检测器)。目前,由于我正在测试Kalman滤波器类,因此我正在构造测量。
每个边界框的格式-[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
请要求任何进一步的说明

最佳答案

您必须为 numpy.array errorCovPoststatePost设置适当的类型:errorCovPost = 1. * np.array([0.])statePost = 1. * np.array([0.])

errorCovPost = 1. * np.array([0.], np.float32)
statePost = 1. * np.array([0.], np.float32)

关于python - 适用于Python3的OpenCV卡尔曼滤波器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62715160/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com