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


Python KalmanFilter.initial_state_mean方法代码示例

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


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

示例1: demo

# 需要导入模块: from pykalman import KalmanFilter [as 别名]
# 或者: from pykalman.KalmanFilter import initial_state_mean [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: len

# 需要导入模块: from pykalman import KalmanFilter [as 别名]
# 或者: from pykalman.KalmanFilter import initial_state_mean [as 别名]
    for cnum, cpos in posDF.groupby("id"):
        if len(cpos) == 1:
            continue
        ft = np.arange(cpos["frame"].values[0], cpos["frame"].values[-1] + 1)
        # obs = np.vstack((cpos['x'].values, cpos['y'].values)).T
        obs = np.zeros((len(ft), 2))
        obs = np.ma.array(obs, mask=np.zeros_like(obs))
        for f in range(len(ft)):
            if len(cpos[cpos["frame"] == ft[f]].x.values) > 0:
                obs[f][0] = cpos[cpos["frame"] == ft[f]].x.values[0] * px_to_m
                obs[f][1] = cpos[cpos["frame"] == ft[f]].y.values[0] * px_to_m
            else:
                obs[f] = np.ma.masked

        kf.initial_state_mean = [cpos["x"].values[0] * px_to_m, cpos["y"].values[0] * px_to_m, 0, 0, 0, 0]
        sse = kf.smooth(obs)[0]

        ani = cpos["animal"].values[0]

        xSmooth = sse[:, 0]
        ySmooth = sse[:, 1]
        xv = sse[:, 2] / 0.1
        yv = sse[:, 3] / 0.1
        xa = sse[:, 4] / 0.01
        ya = sse[:, 5] / 0.01
        headings = np.zeros_like(xSmooth)
        dx = np.zeros_like(xSmooth)
        dy = np.zeros_like(xSmooth)
        for i in range(len(headings)):
            start = max(0, i - 5)
开发者ID:ctorney,项目名称:speciesInteract,代码行数:32,代码来源:processTracks.py

示例3: range

# 需要导入模块: from pykalman import KalmanFilter [as 别名]
# 或者: from pykalman.KalmanFilter import initial_state_mean [as 别名]
        #yobs = np.ma.array(ymes, mask=np.zeros_like(ymes))
        #xobs = np.ma.empty_like(ft)
        #yobs = np.ma.empty_like(ft)
        for f in range(len(ft)):
            if len(cpos[cpos['frame']==ft[f]].x.values)>0:
                obs[f][0]=cpos[cpos['frame']==ft[f]].x.values[0]*px_to_m
                obs[f][1]=cpos[cpos['frame']==ft[f]].y.values[0]*px_to_m
            else:
                obs[f]=np.ma.masked
                #yobs[f]=np.ma.masked
        #if cnum==49:    
        #    break
        #obs = np.vstack((cpos['x'].values*px_to_m, cpos['y'].values*px_to_m)).T
        #obs=np.vstack((xobs,yobs)).T
        #obs = np.vstack((cpos['x'].values, cpos['y'].values)).T
        kf.initial_state_mean=[cpos['x'].values[0]*px_to_m,cpos['y'].values[0]*px_to_m,0,0,0,0]
        #kf.initial_state_mean=[cpos['x'].values[0],cpos['y'].values[0],0,0,0,0]

        sse = kf.smooth(obs)[0]

        
        xSmooth = sse[:,0]
        ySmooth = sse[:,1]
        xv = sse[:,2]/0.1
        yv = sse[:,3]/0.1
        xa = sse[:,4]/0.01
        ya = sse[:,5]/0.01
        dx = np.zeros_like(xSmooth)
        dy = np.zeros_like(xSmooth)
        headings = np.zeros_like(xSmooth)
        # calculate change in position for 5 second intervals
开发者ID:ctorney,项目名称:dolphinUnion,代码行数:33,代码来源:kalmanSmooth.py


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