当前位置: 首页>>代码示例>>Python>>正文


Python KalmanFilter.transition_covariance方法代码示例

本文整理汇总了Python中pykalman.KalmanFilter.transition_covariance方法的典型用法代码示例。如果您正苦于以下问题:Python KalmanFilter.transition_covariance方法的具体用法?Python KalmanFilter.transition_covariance怎么用?Python KalmanFilter.transition_covariance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pykalman.KalmanFilter的用法示例。


在下文中一共展示了KalmanFilter.transition_covariance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: demo

# 需要导入模块: from pykalman import KalmanFilter [as 别名]
# 或者: from pykalman.KalmanFilter import transition_covariance [as 别名]
def demo():
    img = np.zeros((768, 1024, 3), np.uint8)
    trajs = deque(maxlen=200)
    trajs_filterd = deque(maxlen=200)

    def draw(event, x, y, flags, param):
        kf, fm, fo = param
        if event == cv2.EVENT_MOUSEMOVE:
            fm[:], fo[:] = kf.filter_update(fm, fo, np.array([x, y]))
            fx = int(fm[0])
            fy = int(fm[1])
            trajs.append((x, y))
            trajs_filterd.append((fx, fy))

    cv2.namedWindow("image")

    kf = KalmanFilter(n_dim_state=4, n_dim_obs=2)
    kf.transition_matrices = np.array([[1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]])
    kf.observation_matrices = np.array([[1, 0, 0, 0], [0, 1, 0, 0]])
    kf.transition_covariance = 1e-3 * np.eye(4)
    kf.observation_covariance = 10 * np.eye(2)
    kf.initial_state_mean = np.array([0, 0, 0, 0])
    kf.initial_state_covariance = np.eye(4)
    fm = kf.initial_state_mean
    fo = kf.initial_state_covariance

    cv2.setMouseCallback("image", draw, (kf, fm, fo))

    while True:
        img = np.zeros((768, 1024, 3), np.uint8)
        for i in range(len(trajs) - 1):
            cv2.line(img, trajs[i], trajs[i + 1], (0, 255, 0), 1)
            cv2.line(img, trajs_filterd[i], trajs_filterd[i + 1], (0, 0, 255), 1)
        map(lambda pt: cv2.circle(img, pt, 3, (0, 255, 0), 1), trajs)
        map(lambda pt: cv2.circle(img, pt, 3, (0, 0, 255), 1), trajs_filterd)
        cv2.imshow("image", img)
        if cv2.waitKey(5) & 0xFF == ord("q"):
            return
开发者ID:,项目名称:,代码行数:40,代码来源:

示例2: range

# 需要导入模块: from pykalman import KalmanFilter [as 别名]
# 或者: from pykalman.KalmanFilter import transition_covariance [as 别名]
import random


N = 3 * 500
sigma = 0.7

# Function to estimate
W = numpy.zeros(N)
W[0    : 500  ] = 1
W[500  : 1000 ] = 3
W[1000 : 1500 ] = 2

# Generate noisy measures
X = numpy.zeros(N)
for i in range(N):
    X[i] = W[i] + random.gauss(0, sigma)


kf = KalmanFilter(initial_state_mean=X[0], n_dim_obs=1)
kf.transition_covariance = 1e-3
Z = kf.em(X).smooth(X)[0]
#Z = kf.smooth(X)[0]


plt.figure(1)
plt.plot( X, 'r:' )
plt.plot( W, 'b-' )
plt.plot( Z, 'g-' )
plt.show()

开发者ID:fxfabre,项目名称:Algos,代码行数:31,代码来源:Kalman.py


注:本文中的pykalman.KalmanFilter.transition_covariance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。