iter=10, thresh=1e-05, minit='matrix', missing='warn') assert (len(trajectories) == len(labels)) for trajLab in zip(trajectories, labels): trajLab[0].setClusterIdx(trajLab[1]) # Testing the module if __name__ == "__main__": list_trajs = [[(0.0, 0.0), (1.0, 1.0), (2.0, 2.0), (3.0, 3.0)], [(0.5, 0.5), (1.5, 1.5), (2.5, 2.5), (3.5, 3.5)], [(12.0, -5.0), (10.0, -2.5), (8.0, 0.0), (6.0, 2.5)], [(14.0, -7.0), (12.0, -4.5), (10.0, -2.0), (8.0, 0.5)]] trajs = [] for trj in list_trajs: temp = Trajectory(-1) for pt in trj: temp.addPoint(pt) trajs.append(temp) #print(trj, temp) clust = Clustering() res = clust.clusterAgglomerartive(trajs, 2) print(res)
for i in range(20): color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) colors.append(color) file = open('trajectories_filtered.txt', 'r') trajs = [] for i, line in enumerate(file): traj = Trajectory(i) pts = line.split(',')[:-1] for pt in pts: xy = pt.split(' ') x = float(xy[0]) y = float(xy[1]) xy = (x, y) traj.addPoint(xy) trajs.append(traj) print("[INFO] Read in %d trajectories." % len(trajs)) clust = Clustering() # res = clust.clusterAgglomerartive(trajs, 5) res = clust.clusterSpectral(trajs) print("printing image") for traj in trajs: for pt in traj.getPoints(): cv2.circle(mask, (int(pt[0]), int(pt[1])), 1, colors[traj.getClusterIdx() - 1], -1) count = [0] * res