import sys from MultiLaneGenerator import MultiLane import numpy as np def saveInterp(folder, interp, num_left, num_right, name='multilane_points'): num_lanes = num_left + num_right out = {} out['num_lanes'] = np.array(num_lanes) out['num_left'] = np.array(num_left) out['num_right'] = np.array(num_right) for i in xrange(num_lanes): out['lane' + str(i)] = interp[:, :, i] f = folder + '/' + name print 'Saved', f np.savez(f, **out) if __name__ == '__main__': left = int(sys.argv[2]) right = int(sys.argv[3]) ml = MultiLane(sys.argv[1], left, right, sys.argv[4]) ml.extendLanes() # ml.offsetInterpolated() if len(sys.argv) == 6: saveInterp(sys.argv[5], ml.interp, left, right) else: saveInterp(sys.argv[5], ml.interp, left, right, sys.argv[6])
def __init__(self): self.start = 0 self.step = 5 self.end = self.step * 500 self.count = 0 self.ren = vtk.vtkRenderer() args = parse_args(sys.argv[1], sys.argv[2]) # Transforms self.imu_transforms = get_transforms(args) self.trans_wrt_imu = self.imu_transforms[self.start:self.end:self.step, 0:3, 3] self.params = args['params'] self.lidar_params = self.params['lidar'] ml = MultiLane(sys.argv[3], sys.argv[4], 2, 2) ml.extendLanes() saveInterp(ml.interp, ml.rightLanes + ml.leftLanes) ml.filterLaneMarkings() print 'Adding filtered points' pts = ml.lanes.copy() raw_cloud = VtkPointCloud(pts[:, :3], pts[:, 4]) raw_actor = raw_cloud.get_vtk_cloud(zMin=0, zMax=100) self.ren.AddActor(raw_actor) try: npz = np.load('cluster.npz') print 'Loading clusters from file' ml.lanes = npz['data'] ml.times = npz['t'] except IOError: print 'Clustering points' ml.clusterLanes() ml.saveLanes('cluster.npz') ml.sampleLanes() print 'Adding clustered points' clusters = ml.lanes.copy() cluster_cloud = VtkPointCloud(clusters[:, :3], clusters[:, -2]) cluster_actor = cluster_cloud.get_vtk_cloud(zMin=0, zMax=4) cluster_actor.GetProperty().SetPointSize(10) self.ren.AddActor(cluster_actor) print 'Interpolating lanes' ml.interpolateLanes() interp_lanes = ml.interp_lanes.copy() interp_lanes_cloud = VtkPointCloud(interp_lanes[:, :3], interp_lanes[:, 3]) interp_lanes_actor = interp_lanes_cloud.get_vtk_cloud(zMin=0, zMax=4) self.ren.AddActor(interp_lanes_actor) # ml.fixMissingPoints() # saveClusters(ml.lanes, ml.times, -1, 5) print 'Adding car' self.car = load_ply('../mapping/viz/gtr.ply') self.ren.AddActor(self.car) self.car.GetProperty().LightingOff() print 'Rendering' self.ren.ResetCamera() self.win = vtk.vtkRenderWindow() self.ren.SetBackground(0, 0, 0) self.win.AddRenderer(self.ren) self.win.SetSize(800, 400) self.iren = vtk.vtkRenderWindowInteractor() self.iren.SetRenderWindow(self.win) mouseInteractor = vtk.vtkInteractorStyleTrackballCamera() self.iren.SetInteractorStyle(mouseInteractor) self.iren.Initialize() # Whether to write video self.record = False # Set up time self.iren.AddObserver('TimerEvent', self.update) self.timer = self.iren.CreateRepeatingTimer(100) # Add keypress event self.iren.AddObserver('KeyPressEvent', self.keyhandler) self.mode = 'ahead' self.iren.Start()
def __init__(self): self.start = 0 self.step = 5 self.end = self.step * 500 self.count = 0 self.ren = vtk.vtkRenderer() args = parse_args(sys.argv[1], sys.argv[2]) # Transforms self.imu_transforms = get_transforms(args) self.trans_wrt_imu = self.imu_transforms[ self.start:self.end:self.step, 0:3, 3] self.params = args['params'] self.lidar_params = self.params['lidar'] ml = MultiLane(sys.argv[3], sys.argv[4], 2, 2) ml.extendLanes() saveInterp(ml.interp, ml.rightLanes + ml.leftLanes) ml.filterLaneMarkings() print 'Adding filtered points' pts = ml.lanes.copy() raw_cloud = VtkPointCloud(pts[:, :3], pts[:, 4]) raw_actor = raw_cloud.get_vtk_cloud(zMin=0, zMax=100) self.ren.AddActor(raw_actor) try: npz = np.load('cluster.npz') print 'Loading clusters from file' ml.lanes = npz['data'] ml.times = npz['t'] except IOError: print 'Clustering points' ml.clusterLanes() ml.saveLanes('cluster.npz') ml.sampleLanes() print 'Adding clustered points' clusters = ml.lanes.copy() cluster_cloud = VtkPointCloud(clusters[:, :3], clusters[:, -2]) cluster_actor = cluster_cloud.get_vtk_cloud(zMin=0, zMax=4) cluster_actor.GetProperty().SetPointSize(10) self.ren.AddActor(cluster_actor) print 'Interpolating lanes' ml.interpolateLanes() interp_lanes = ml.interp_lanes.copy() interp_lanes_cloud = VtkPointCloud(interp_lanes[:, :3], interp_lanes[:, 3]) interp_lanes_actor = interp_lanes_cloud.get_vtk_cloud(zMin=0, zMax=4) self.ren.AddActor(interp_lanes_actor) # ml.fixMissingPoints() # saveClusters(ml.lanes, ml.times, -1, 5) print 'Adding car' self.car = load_ply('../mapping/viz/gtr.ply') self.ren.AddActor(self.car) self.car.GetProperty().LightingOff() print 'Rendering' self.ren.ResetCamera() self.win = vtk.vtkRenderWindow() self.ren.SetBackground(0, 0, 0) self.win.AddRenderer(self.ren) self.win.SetSize(800, 400) self.iren = vtk.vtkRenderWindowInteractor() self.iren .SetRenderWindow(self.win) mouseInteractor = vtk.vtkInteractorStyleTrackballCamera() self.iren.SetInteractorStyle(mouseInteractor) self.iren.Initialize() # Whether to write video self.record = False # Set up time self.iren.AddObserver('TimerEvent', self.update) self.timer = self.iren.CreateRepeatingTimer(100) # Add keypress event self.iren.AddObserver('KeyPressEvent', self.keyhandler) self.mode = 'ahead' self.iren.Start()
# -*- coding: utf-8 -*- #Usage: OffsetLanes.py interpolated_lanes.pickle num_left num_right lidar.npz output_folder/ import sys from MultiLaneGenerator import MultiLane import numpy as np def saveInterp(folder, interp, num_left, num_right, name='multilane_points'): num_lanes = num_left + num_right out = {} out['num_lanes'] = np.array(num_lanes) out['num_left'] = np.array(num_left) out['num_right'] = np.array(num_right) for i in xrange(num_lanes): out['lane' + str(i)] = interp[:,:,i] f = folder + '/' + name print 'Saved', f np.savez(f, **out) if __name__ == '__main__': left = int(sys.argv[2]) right = int(sys.argv[3]) ml = MultiLane(sys.argv[1], left, right, sys.argv[4]) ml.extendLanes() # ml.offsetInterpolated() if len(sys.argv) == 6: saveInterp(sys.argv[5], ml.interp, left, right) else: saveInterp(sys.argv[5], ml.interp, left, right, sys.argv[6])