前言
对于一个.csv文件保存的行人轨迹,需要重新还原原始动态视频,从而直观的观察,路人之间的交互状态。
其中.csv
帧 | 10 | 20 |
---|---|---|
id | 1 | 3 |
y | 2 | 3 |
x | 3 | 3 |
import numpy as np
import matplotlib.pyplot as plt
import time
plt.ion() #开启interactive mode 成功的关键函数
plt.figure(1)
t = 0
class KM(object):
def __init__(self, fram, id, x, y):
self.life = 1
self.fram = fram
self.id = id
self.x = x
self.y = y
self.tra = np.array([[fram, x, y]])
self.ismatched = False
def uptra(self, fram, x, y):
temp = np.array([fram, x, y])
self.x = x
self.y = y
self.tra = np.append(self.tra,temp)
def uplife(self):
if self.ismatched ==True:
self.life+=1
else:
self.life-=1
if self.life > 3:
self.life = 3
elif self.life <= -1:
self.life = -1;
data = np.genfromtxt('../data/eth/hotel/true_pos_.csv', delimiter=',')
max = np.unique(data[0,:]).size
cur_fram = 10
obs_id = []
obs = []
for i in range(max):
a = data[:, data[0, :] == cur_fram]
a = a.transpose(1,0)
for j in a:
if j[1] in obs_id:
n = np.where(obs_id == j[1])
n = n[0][0]
obs[n].uptra(j[0], j[3], j[2])
obs[n].ismatched = True
else:
obs_id.append(j[1])
c = KM(j[0],j[1], j[3], j[2])
obs.append(c)
for obs_ in obs:
obs_.uplife()
obs_.ismatched = False
if obs_.life == -1:
obs_id.remove(obs_.id)
obs.remove(obs_)
cur_fram += 10
for obs_ in obs:
s = obs_.tra
if len(s) > 3:
s = s.reshape(len(s)//3, 3)
plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.plot(s[-1][1], s[-1][2], '.')
plt.pause(1)
if t // 10 == 1:
t = 0
plt.clf()
else:
t += 1
TODO:
- 对于同一个行人轨迹的颜色相同
- 引入帧之间连续性