2

我的项目有 5 条不同的轨迹。首先我从文件中读取它们,然后通过解析文件将它们保存到列表中。之后,我将这些值数字化。我想分别对齐 x 和 y 坐标,并将 x 和 y 坐标一起绘制在网格上。

这是我到目前为止所做的。我在 python 中使用 dtw 包,但它需要两个列表并将路径作为数组提供。如何将其转换为 5 个不同列表的对齐轨迹?

x_dict = {}
y_dict = {}
for x in ["1", "2", "3", "4", "5"]:
    file = open("data-" + x + ".txt", encoding="latin-1")
    data = file.read()
    pos_list = re.findall(r'position:(.*?)orientation:', data, re.DOTALL)
    or_list = re.findall(r'orientation:(.*?)scale:', data, re.DOTALL)

    for i in range(len(pos_list)):
        pos_list[i] = pos_list[i].replace('\n','')

    regexx = re.compile(r'x: (.*?) y:')
    regexy = re.compile(r'y: (.*?) z:')

    posx_list = [m.group(1) for l in pos_list for m in [regexx.search(l)] if m]
    posx_list = list(map(float, posx_list))

    posy_list = [m.group(1) for l in pos_list for m in [regexy.search(l)] if m]
    posy_list = list(map(float, posy_list))

    bins = numpy.linspace(-1, 1, 100)
    digitized_x = numpy.digitize(posx_list, bins)
    digitized_y = numpy.digitize(posy_list, bins)

    x_dict[x] = digitized_x
    y_dict[x] = digitized_y

dist, cost, acc, path = dtw(y_dict["5"], y_dict["4"], dist= euclidean)

plt.imshow(acc.T, origin='lower', cmap=cm.gray, interpolation='nearest')
plt.plot(path[0], path[1], 'w')
plt.xlim((-0.5, acc.shape[0]-0.5))
plt.ylim((-0.5, acc.shape[1]-0.5))
4

0 回答 0