def __init__(self, keys='interactive', size=(640, 480), show=True, **kwargs): super().__init__(keys=keys, size=size, show=show, **kwargs) self.unfreeze() self._viewbox = self.central_widget.add_view(camera='turntable') self._baseAxis = visuals.XYZAxis(parent=self._viewbox.scene, width=5) self._gridLines = visuals.GridLines() self._viewbox.add(self._gridLines) self._cubeAxis = visuals.XYZAxis(parent=self._viewbox.scene, width=5) Plot3D = scene.visuals.create_visual_node(LinePlotVisual) self._plot = Plot3D(([0], [0], [0]), width=3.0, color='y', edge_color='w', symbol='x', face_color=(0.2, 0.2, 1, 0.8), parent=self._viewbox.scene) self._xPos = np.array([0], dtype=np.float32) self._yPos = np.array([0], dtype=np.float32) self._zPos = np.array([0], dtype=np.float32) self._cube = visuals.Cube(parent=self._viewbox.scene, color=(0.5, 0.5, 1, 0.5), edge_color=(0.6, 0.2, 0.8, 1)) self._transform = MatrixTransform() self._cube.transform = self._transform self._cubeAxis.transform = self._transform self.freeze()
def resetTwo(self): """ Reset. """ # last key press (it should have a mutex, but visualization is not # safety critical, so let's do things wrong) self.action = "no" # no, next, back, quit are the possibilities # new canvas prepared for visualizing data self.canvas = SceneCanvas(keys='interactive', show=True) # interface (n next, b back, q quit, very simple) self.canvas.events.key_press.connect(self.key_press) self.canvas.events.draw.connect(self.draw) # grid self.grid = self.canvas.central_widget.add_grid() # laserscan part self.scan_view = vispy.scene.widgets.ViewBox(border_color='white', parent=self.canvas.scene) self.grid.add_widget(self.scan_view, 0, 0) self.scan_vis = visuals.Markers() self.scan_view.camera = 'turntable' self.scan_view.add(self.scan_vis) visuals.XYZAxis(parent=self.scan_view.scene) #if self.instances: print("Using instances in visualizer") self.inst_view = vispy.scene.widgets.ViewBox(border_color='white', parent=self.canvas.scene) self.grid.add_widget(self.inst_view, 0, 1) self.inst_vis = visuals.Markers() self.inst_view.camera = 'turntable' self.inst_view.add(self.inst_vis) visuals.XYZAxis(parent=self.inst_view.scene)
def reset(self, sem_color_dict=None): """ Reset. """ # new canvas prepared for visualizing data self.map_color(sem_color_dict=sem_color_dict) self.canvas = SceneCanvas(keys='interactive', show=True) # grid self.grid = self.canvas.central_widget.add_grid() # laserscan part self.scan_view = vispy.scene.widgets.ViewBox(border_color='white', parent=self.canvas.scene) self.grid.add_widget(self.scan_view, 0, 0) self.scan_view.camera = 'turntable' self.scan_vis = visuals.Markers() self.scan_view.add(self.scan_vis) if self.viz_joint: self.joint_vis = visuals.Arrow(connect='segments', arrow_size=18, color='blue', width=10, arrow_type='angle_60') self.arrow_length = 10 self.scan_view.add(self.joint_vis) if self.viz_box: vertices, faces, outline = create_box(width=1, height=1, depth=1, width_segments=1, height_segments=1, depth_segments=1) vertices['color'][:, 3] = 0.2 # breakpoint() self.box = visuals.Box(vertex_colors=vertices['color'], edge_color='b') self.box.transform = STTransform(translate=[-2.5, 0, 0]) self.theta = 0 self.phi = 0 self.scan_view.add(self.box) visuals.XYZAxis(parent=self.scan_view.scene) # add nocs if self.viz_label: print("Using nocs in visualizer") self.nocs_view = vispy.scene.widgets.ViewBox( border_color='white', parent=self.canvas.scene) self.grid.add_widget(self.nocs_view, 0, 1) self.label_vis = visuals.Markers() self.nocs_view.camera = 'turntable' self.nocs_view.add(self.label_vis) visuals.XYZAxis(parent=self.nocs_view.scene) self.nocs_view.camera.link(self.scan_view.camera)
def simple_viewer(reconstruction, data_path, has_color=1, show_camera=1): pos, color = get_points(reconstruction, has_color) # # Make a canvas and add simple view # canvas = vispy.scene.SceneCanvas(keys='interactive', show=True) view = canvas.central_widget.add_view() # create scatter object and fill in the data scatter = visuals.Markers() scatter.set_data(pos, edge_color=None, face_color=color, size=5) view.add(scatter) if (show_camera): attach_cameras_to_view(reconstruction, view, data_path) view.camera = 'arcball' # or try 'turntable' # add a colored 3D axis for orientation visuals.XYZAxis(parent=view.scene) canvas.app.run()
def reset(self): """ Reset. """ # last key press (it should have a mutex, but visualization is not # safety critical, so let's do things wrong) self.action = "no" # no, next, back, quit are the possibilities # new canvas prepared for visualizing data self.canvas = SceneCanvas(keys='interactive', show=True, size=self.canvas_size) # interface (n next, b back, q quit, very simple) self.canvas.events.key_press.connect(self.key_press) self.canvas.events.draw.connect(self.draw) # laserscan part self.scan_view = vispy.scene.widgets.ViewBox(border_color='white', parent=self.canvas.scene) self.scan_view.camera = vispy.scene.TurntableCamera(elevation=30, azimuth=-90, distance=30, translate_speed=30, up='+z') # grid self.grid = self.canvas.central_widget.add_grid() self.grid.add_widget(self.scan_view) self.scan_vis = visuals.Markers(parent=self.scan_view.scene) self.scan_vis.antialias = 0 # self.scan_view.add(self.scan_vis) visuals.XYZAxis(parent=self.scan_view.scene) self.line = visuals.Line(width=1, method='gl', parent=self.scan_view.scene) self.text = visuals.Text(color='red', font_size=600, bold=True, parent=self.scan_view.scene) self.gt_line = visuals.Line(width=1000, parent=self.scan_view.scene) # self.sem_view.camera.link(self.scan_view.camera) if self.show_img: # img canvas size # new canvas for img self.img_canvas = SceneCanvas(keys='interactive', show=True, size=(1242, 375)) # grid self.img_grid = self.img_canvas.central_widget.add_grid() # interface (n next, b back, q quit, very simple) self.img_canvas.events.key_press.connect(self.key_press) self.img_canvas.events.draw.connect(self.draw) # add a view for the depth self.img_view = vispy.scene.widgets.ViewBox( border_color='white', parent=self.img_canvas.scene) self.img_grid.add_widget(self.img_view, 0, 0) self.img_vis = visuals.Image(cmap='viridis') self.img_view.add(self.img_vis)
def __init__(self, planes, leyeball, reyeball, pipe): ''' NOTE: the R200 camera uses a right-handed coordinate system! This means that relative to the image projection, x-values increase to the right and y-values increase as they go to the bottom ''' self.leyeball = leyeball self.reyeball = reyeball self.le_vtx = None self.re_vtx = None self.canvas = vispy.scene.SceneCanvas(keys='interactive', show=True) self.view = self.canvas.central_widget.add_view() self.view.camera = 'turntable' for p in planes: mesh = self.__define_plane(p) self.view.add(mesh) self.__define_eyeballs() axis = visuals.XYZAxis(parent=self.view.scene) self.__build_gaze_rays() self.pipe = pipe self.quit = False update_t = Thread(target=self.update, args=()) update_t.start() self.run() update_t.join()
def showInVispy(self, path): # Make a canvas and add simple view canvas = vispy.scene.SceneCanvas(keys='interactive', show=True) view = canvas.central_widget.add_view() # 读取点云 with open(path, "r") as f: lines = f.readlines() lines = lines[13:] points = np.ones((len(lines), 3)) colors = [] for i in range(len(lines)): points[i, :3] = list( map(float, lines[i].strip("\n").split(" ")[:3])) colors.append( tuple( list(map(float, lines[i].strip("\n").split(" ")[-3:])))) colors = np.array(colors) / 255 # create scatter object and fill in the data scatter = visuals.Markers() scatter.set_data(points[:, :3], edge_color=None, face_color=colors, size=4) view.add(scatter) view.camera = 'turntable' # or try 'arcball' # add a colored 3D axis for orientation axis = visuals.XYZAxis(parent=view.scene) if sys.flags.interactive != 1: vispy.app.run()
def plot_3d_point_clouds(pc1, pc2): """ Function plots 3d points from two pointclouds Input: pc1: Nx3 numpy array of first pointcloud pc2: Nx3 numpy array of second pointcloud """ canvas = vispy.scene.SceneCanvas(keys='interactive', show=True) view = canvas.central_widget.add_view() scatter1 = visuals.Markers() scatter1.set_data(pc1, edge_color=(1, 1, 1, .5), face_color=(1, 1, 1, .5), size=3) scatter2 = visuals.Markers() scatter2.set_data(pc2, edge_color=(1, 1, 1, .5), face_color=(1, 0, 0, .5), size=5) view.add(scatter1) view.add(scatter2) view.camera = 'turntable' # or try 'arcball' # add a colored 3D axis for orientation axis = visuals.XYZAxis(parent=view.scene) vispy.app.run()
def draw_3D(*datas, labels=None): canvas = vispy.scene.SceneCanvas(keys='interactive', show=True, bgcolor="white") view = canvas.central_widget.add_view() pos, colors = [], [] D = len(datas) cm = matplotlib.cm.rainbow(np.linspace(0, 1, D)) for i, data in enumerate(datas): pos.extend(data.T) color = cm[i] colors.extend([color] * len(data.T)) colors = np.array(colors) pos = np.array(pos) # create scatter object and fill in the data scatter = visuals.Markers() scatter.set_data(pos, edge_color=None, face_color=colors, size=5) view.add(scatter) view.camera = 'turntable' # or try 'arcball' # add a colored 3D axis for orientation axis = visuals.XYZAxis(parent=view.scene) view.add(axis) if labels is not None: # legend for i, label in enumerate(labels): leg = visuals.Text(label, color=cm[i], pos=(0, 10 * i)) canvas.scene.add(leg) return canvas
def plot_structure_contours(point_cloud, title=''): """ PLot contours from Dicom Structure point cloud (x,y,z) property. :param point_cloud: array of x,y,z contour points :param symbol: """ # # Make a canvas and add simple view # canvas = vispy.scene.SceneCanvas(title=title, keys='interactive', show=True, bgcolor='white') view = canvas.central_widget.add_view() # create scatter object and fill in the data scatter = visuals.Markers() scatter.set_data(point_cloud, symbol='+', face_color=(1, 1, 1, .5), size=1) view.add(scatter) view.camera = 'arcball' # or try 'arcball' # view.camera = 'turntable' # add a colored 3D axis for orientation visuals.XYZAxis(parent=view.scene) vispy.app.run()
def __init__(self, width=800, height=800, show_axis=True): self.canvas = SceneCanvas(size=(width, height), position=(0,0), keys='interactive', title=self.__class__.__name__) self.view = self.canvas.central_widget.add_view() self.view.camera = 'turntable' if show_axis: self.axis = visuals.XYZAxis(parent=self.view.scene) self.canvas.show()
def draw_cloud(self, data, centroid, basis): self.draw_axis(centroid, basis) self.scatter.set_data(data, edge_color=None, face_color=(1, 1, 1, .5), size=5) self.view.add(self.scatter) self.view.camera = 'turntable' axis = visuals.XYZAxis(parent=self.view.scene)
def ScatterPlot3D(data, labels=None, x_feat=0, y_feat=1, z_feat=2, label_feat=-1, title="Scatterplot"): """" Creates a 3D scatterplot of data with unique colors for each label :param @data: matrix of row vectors containing data feature and optionally labels @labels: optional vector of labels for the samples in @data @x_feat: which feature in @data to use for the x-axis @y_feat: which feature in @data to use for the y-axis @z_feat: which feature in @data to use for the z-axis @label_feat: which column in @data to use as labels (ignored if @labels is provided) @title: plot window title :returns None """ # Extract data and labels if no label vector is supplied if labels is None: labels = data[:, label_feat] data = np.delete(data, label_feat, axis=1) # Create a canvas and add view canvas = vispy.scene.SceneCanvas(title=title, keys='interactive', show=True) view = canvas.central_widget.add_view() # Separate data into point clouds based on label unique_labels = np.unique(labels) cm = Colormap(['r', 'g', 'b']) for y in unique_labels: cloud = data[np.where(labels.ravel() == y), :] cloud = np.squeeze(cloud, axis=0) # Define Colors y = y / len(unique_labels) color = cm[y] # Create scatter object and fill in the data scatter = visuals.Markers() scatter.set_data(cloud[:, [x_feat, y_feat, z_feat]], edge_color=None, face_color=color, size=5) view.add(scatter) # Define camara rotation view.camera = 'turntable' # or try 'arcball' # Add a colored 3D axis for orientation axis = visuals.XYZAxis(parent=view.scene)
def __init__(self, width=600, height=600): self._canvas = SceneCanvas(size=(width, height), position=(0, 0), keys='interactive', title="ALife book " + self.__class__.__name__) self._view = self._canvas.central_widget.add_view() #self._view.camera = 'arcball' self._view.camera = 'turntable' self._axis = visuals.XYZAxis(parent=self._view.scene) self._arrows = None self._markers = None self._canvas.show()
def visualize_results(pcl,label = None): canvas = vispy.scene.SceneCanvas(keys='interactive', show=True) view = canvas.central_widget.add_view() scatter = visuals.Markers() # pcl = convert_pcl(pcl,label) if (label.any() != None): scatter.set_data(pcl[:,:3],edge_color = color_labels(label), size = 2) else: scatter.set_data(pcl[:,:3], size = 7) # scatter.set_data(, edge_color=None, face_color=(1, 1, 1, .5), size=5) view.add(scatter) view.camera = 'turntable' axis = visuals.XYZAxis(parent=view.scene) vispy.app.run()
def plot_3d_point_cloud_vispy(points, colors, size=5): canvas = vispy.scene.SceneCanvas(keys='interactive', show=True, bgcolor='w') view = canvas.central_widget.add_view() scatter = visuals.Markers() scatter.set_data(points / (np.max(points) - np.min(points)), edge_color=colors, size=1) # view.camera = 'turntable' view.camera = 'arcball' view.add(scatter) visuals.XYZAxis(parent=view.scene) vispy.app.run()
def draw(): canvas = scene.SceneCanvas(keys='interactive', show=True) view = canvas.central_widget.add_view() # add a colored 3D axis for orientation axis = visuals.XYZAxis(parent=view.scene) self.graphic_robots = [] self.graphic_trajectories = [] for _ in self.quads: self.graphic_robots.append(GraphicQuad(view)) # Trtajectory Plot3D = scene.visuals.create_visual_node(visualsplot.LinePlotVisual) pos = np.c_[[0], [0], [0]] gtraj = Plot3D(pos, width=2.0, color=(1, 0, 0, .9), face_color=(0., 0., 0, 0.), parent=view.scene) self.graphic_trajectories.append(gtraj) # Initial drawing for robots for i, q in enumerate(self.quads): self.graphic_robots[i].draw(q) cam = scene.TurntableCamera(elevation=30, azimuth=45) cam.set_range((-3, 3), (-3, 3), (-3, 3)) view.camera = cam view.camera = 'arcball' # or try 'turntable' def update(ev): # Draw robots for i, q in enumerate(self.quads): self.graphic_robots[i].draw(q) # Draw trajectories for traj, gtraj in zip(self.trajectories, self.graphic_trajectories): x, y, z = traj pos = np.c_[x, y, z] gtraj.set_data(pos, marker_size=0) timer = app.Timer(interval=1 / refresh_rate, connect=update, start=True) vispy.app.run()
def plot(self): with open("./episode_1.pkl", "rb") as f: self.data = pickle.load(f) canvas = vispy.scene.SceneCanvas(keys="interactive", show=True, bgcolor="white") view = canvas.central_widget.add_view() self.idx = 0 colors = cm.get_cmap("tab10")(np.linspace(0.0, 1.0, 10)) self.color_id = colors[self.data["particle_ids"][0, self.idx, :, 1]] self.data["flex_states"][:, :, :, [0, 1, 2]] = self.data[ "flex_states"][:, :, :, [0, 2, 1]] pos = self.data["flex_states"][0, self.idx, :, :3] self.scatter = visuals.Markers() self.scatter.set_data(pos, edge_color=None, face_color=self.color_id, size=5) floor = visuals.Plane(width=5, height=5) wall = visuals.Plane(width=5, height=1, direction="+x", width_segments=4, height_segments=10) wall._mesh.color = "green" view.add(wall) wall.transform = transforms.STTransform(translate=(-2.5, 0.0, 0.5)) view.add(self.scatter) view.add(floor) view.camera = "turntable" # or try 'arcball' # add a colored 3D axis for orientation axis = visuals.XYZAxis(parent=view.scene) self.reverse = False timer = app.Timer(interval="1.1") timer.connect(self.update) timer.start(0.04) vispy.app.run()
def __init__(self, data_getter_func, live=False): """ Initializes Display :param live: Whether data is live; determines whether data is updated for each draw frame. """ # Make canvas and add view self.pos = None self.canvas = PointMapCanvas(keys='interactive', show=True) self._data_getter = data_getter_func self.view = self.canvas.central_widget.add_view() self.scatter = visuals.Markers() # not an error self.update_data() self.view.add(self.scatter) self.view.camera = 'turntable' self.axis = visuals.XYZAxis(parent=self.view.scene) # not an error if live: self.canvas.draw_func = self.update_data
def reset(self): """ Reset. """ # last key press (it should have a mutex, but visualization is not # safety critical, so let's do things wrong) self.action = "no" # no, next, back, quit are the possibilities # new canvas prepared for visualizing data self.canvas = SceneCanvas(keys='interactive', show=True) # interface (n next, b back, q quit, very simple) self.canvas.events.key_press.connect(self.key_press) self.canvas.events.draw.connect(self.draw) # grid self.grid = self.canvas.central_widget.add_grid() # laserscan part self.scan_view = vispy.scene.widgets.ViewBox( border_color='white', parent=self.canvas.scene) self.grid.add_widget(self.scan_view, 0, 0) self.scan_vis = visuals.Markers() self.scan_view.camera = 'turntable' self.scan_view.add(self.scan_vis) visuals.XYZAxis(parent=self.scan_view.scene) # img canvas size self.multiplier = 1 self.canvas_W = 1024 self.canvas_H = 64 # new canvas for img self.img_canvas = SceneCanvas(keys='interactive', show=True, size=(self.canvas_W, self.canvas_H * self.multiplier)) # grid self.img_grid = self.img_canvas.central_widget.add_grid() # interface (n next, b back, q quit, very simple) self.img_canvas.events.key_press.connect(self.key_press) self.img_canvas.events.draw.connect(self.draw) # add a view for the depth self.img_view = vispy.scene.widgets.ViewBox( border_color='white', parent=self.img_canvas.scene) self.img_grid.add_widget(self.img_view, 0, 0) self.img_vis = visuals.Image(cmap='viridis') self.img_view.add(self.img_vis)
def vispy_plot_contours(pos, title=''): canvas = vispy.scene.SceneCanvas(title=title, keys='interactive', show=True, dpi=100) view = canvas.central_widget.add_view() # scatter = visuals.Line(method='gl') # scatter.set_data(pos, width=3) scatter = visuals.Isosurface() scatter.set_data(pos) view.add(scatter) # # view.camera = 'arcball' # or try 'arcball' view.camera = 'turntable' # add a colored 3D axis for orientation axis = visuals.XYZAxis(parent=view.scene) axis.set_data(pos.mean(axis=0)) vispy.app.run()
def visualize_las(self, flag_label=False): # create a rendering window and renderer canvas = vispy.scene.SceneCanvas(keys='interactive', show=True) view = canvas.central_widget.add_view() # data (Point cloud) position = self.las[:, 0:3] intensity = self.las[:, 3] nPoints = position.shape[0] colors = np.ones((nPoints, 4)) # Only show intensity colors[:, 3] = colors[:, 3] * intensity # create scatter object and fill in the data scatter = visuals.Markers() scatter.set_data(position, edge_color=None, face_color=colors, size=1) view.add(scatter) # data (Label) if flag_label: label = self.label for iterId in range(len(label)): scatter = visuals.Markers() labelOne = label[iterId] position = np.vstack(labelOne.position) if position.shape[0] > 1: scatter.set_data(position, edge_color=None, face_color=COLOR_CODE[labelOne.label], size=3) view.add(scatter) # setting visualizer view.camera = 'turntable' axis = visuals.XYZAxis(parent=view.scene) import sys if sys.flags.interactive != 1: vispy.app.run() return 1
def setup_pcl_viewer(X, color=(1, 1, 1, .5), run=False): # setup a point cloud viewer using vispy and return a drawing function # make a canvas and add simple view canvas = vispy.scene.SceneCanvas(keys='interactive', show=True) view = canvas.central_widget.add_view() # create scatter object and fill in the data # init_pc = np.random.normal(size=(100, 3), scale=0.2) init_pc = X scatter = visuals.Markers() draw_fn = partial(scatter.set_data, edge_color=None, face_color=color, size=5) draw_fn(init_pc) view.add(scatter) # set camera view.camera = 'turntable' # ['turntable','arcball'] # add a colored 3D axis for orientation axis = visuals.XYZAxis(parent=view.scene) return draw_fn
def plot_surf_vispy(vertx, idx, surface_property, color_scheme, text=False): canvas = scene.SceneCanvas(keys='interactive', show=True, bgcolor='white') view = canvas.central_widget.add_view() cm = plt.get_cmap('gist_rainbow') p = len(vertx) cmap = np.asarray([cm(1. * i / p) for i in range(p)]) # p = scene.visuals.Markers(pos=vertx, size=1, face_color='b') # Same color for all vertices p = scene.visuals.Markers( pos=vertx, size=10, face_color=cmap) # Color the vertices according to their numbering view.add(p) c = surface_color_scale( surface_property, idx, 'bwr_r') # Colormap according to crystalexplorer visualization # c = np.tile([1, 1, 1], (len(idx), 1)) # Colormap for same color applied to all faces mesh = scene.visuals.Mesh(vertices=vertx, faces=idx, face_colors=c) view.add(mesh) # t1 = scene.visuals.Text(str(1), pos=vertx[0], color='black') # t1.font_size = 12 # view.add(t1) # # t1 = scene.visuals.Text(str(10+1), pos=vertx[10], color='black') # t1.font_size = 12 # view.add(t1) if text is True: for k, v in enumerate(vertx): t1 = scene.visuals.Text(str(k + 1), pos=v, color='black') t1.font_size = 16 view.add(t1) view.camera = 'turntable' axis = visuals.XYZAxis(parent=view.scene) import sys canvas.show() if sys.flags.interactive == 0: app.run() return canvas
def __init__(self): self.canvas = SceneCanvas(keys='interactive', show=True) self.grid = self.canvas.central_widget.add_grid() self.view = vispy.scene.widgets.ViewBox(border_color='white', parent=self.canvas.scene) self.grid.add_widget(self.view, 0, 0) # Point Cloud Visualizer self.sem_vis = visuals.Markers() self.view.camera = vispy.scene.cameras.TurntableCamera(up='z', azimuth=90) self.view.add(self.sem_vis) visuals.XYZAxis(parent=self.view.scene) # Object Detection Visualizer self.obj_vis = visuals.Line() self.view.add(self.obj_vis) self.connect = np.asarray([[0, 1], [0, 3], [0, 4], [2, 1], [2, 3], [2, 6], [5, 1], [5, 4], [5, 6], [7, 3], [7, 4], [7, 6]]) self.data = load_data( 'data/data.p') # Change to data.p for your final submission
def __init__(self, reconstruction, data_path, has_color=1, show_camera=1): self.data_path = data_path self.has_color = has_color self.show_camera = show_camera pos, color = get_points(reconstruction, has_color) # create scatter object and fill in the data self.scatter = visuals.Markers() self.scatter.set_data(pos, edge_color=None, face_color=color, size=5) # self.canvas = vispy.scene.SceneCanvas(keys='interactive', show=True) # self.view = self.canvas.central_widget.add_view() vispy.scene.SceneCanvas.__init__(self, keys='interactive', show=True) self.unfreeze() self.view = self.central_widget.add_view() self.view.add(self.scatter) # size for plotting cameras self.length = 1 self.font_size = 12 if (show_camera): self.camera_nodes, self.text_nodes = \ attach_cameras_to_view(reconstruction, self.view, self.data_path, length=self.length, font_size=self.font_size) self.view.camera = 'arcball' # or try 'turntable' # add a colored 3D axis for orientation self.axis = visuals.XYZAxis(parent=self.view.scene) self.visible = True # self.canvas.app.run() self.app.run()
# generate data def solver(t): pos = np.array([[0.5 + t / 10000, 0.5, 0], [0, 0, 0.5], [0, 0.5, 0], [0.5, 0, 0]]) return pos # These are the data that need to be updated each frame --^ scatter = visuals.Markers() view.add(scatter) #view.camera = scene.TurntableCamera(up='z') # just makes the axes axis = visuals.XYZAxis(parent=view.scene) t = 0.0 def update(ev): global scatter global t t += 1.0 scatter.set_data(solver(t), edge_color=None, face_color=(1, 1, 1, .5), size=10) timer = app.Timer()
def main(vid): # Video capture cap = cv2.VideoCapture(vid) print("fps is ", cap.get(cv2.CAP_PROP_FPS)) # Make a canvas and add simple view canvas = vispy.scene.SceneCanvas(keys='interactive', show=True) view = canvas.central_widget.add_view() # create scatter object scatter = visuals.Markers() # generate data or figure out how to prevent crash without data ^^ pos = np.random.normal(size=(100000, 3), scale=0.2) scatter.set_data(pos, edge_color=None, face_color=(1, 1, 1, .5), size=5) view.add(scatter) #configure view view.camera = 'turntable' # or try 'arcball' axis = visuals.XYZAxis(parent=view.scene) #load model sess = tf.Session() model = RunModel(config, sess=sess) # verts_anim = [] i = 0 while True: # Capture frame-by-frame # print(cap.read()) ret, frame = cap.read() if frame is None: break processed, proc_param, img = preprocess_image(frame) # Add batch dimension: 1 x D x D x 3 input_img = np.expand_dims(processed, 0) # Theta is the 85D vector holding [camera, pose, shape] # where camera is 3D [s, tx, ty] # pose is 72D vector holding the rotation of 24 joints of SMPL in axis angle format # shape is 10D shape coefficients of SMPL start = datetime.datetime.now() joints, verts, cams, joints3d, theta = model.predict( input_img, get_theta=True) # verts_anim.append(verts.tolist()) cam_for_render, vert_shifted, joints_orig = vis_util.get_original( proc_param, verts, cams[0], joints[0], img_size=img.shape[:2]) rend_img_overlay = renderer( vert_shifted, cam=cam_for_render, img=img, do_alpha=True) cv2.imshow('processed', rend_img_overlay) end = datetime.datetime.now() delta = end -start print("took:" , delta) # Display Camera frame cv2.imshow('frame',frame) # cv2.imshow('processed',processed) if cv2.waitKey(1) & 0xFF == ord('q'): break # Display Plot # pos = np.random.normal(size=(100000, 3), scale=0.2) # scatter.set_data(verts[0], edge_color=None, face_color=(1, 1, 1, .5), size=5) i = i + 1 print(i) if i % 30 == 0: print("new second!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") # to_json(verts_anim, "verts_anim.txt") # When everything done, release the capture cap.release() cv2.destroyAllWindows()
def pcd_vispy(scans=None, img=None, boxes=None, name=None, index=0, vis_size=(800, 600), save_img=False, visible=True, no_gt=False, multi_vis=False, point_size=0.02): if multi_vis: canvas = vispy.scene.SceneCanvas(title=name, keys='interactive', size=vis_size, show=True) else: canvas = vispy.scene.SceneCanvas(title=name, keys='interactive', size=vis_size, show=visible) grid = canvas.central_widget.add_grid() vb = grid.add_view(row=0, col=0, row_span=2) vb_img = grid.add_view(row=1, col=0) vb.camera = 'turntable' vb.camera.elevation = 90 # 21.0 vb.camera.center = (6.5, -0.5, 9.0) vb.camera.azimuth = -90 # -75.5 vb.camera.scale_factor = 63 # 32.7 if scans is not None: if not isinstance(scans, list): pos = scans[:, :3] scatter = visuals.Markers() scatter.set_gl_state('translucent', depth_test=False) scatter.set_data(pos, edge_width=0, face_color=(1, 1, 1, 1), size=point_size, scaling=True) vb.add(scatter) else: pos = scans[0][:, :3] scatter = visuals.Markers() scatter.set_gl_state('translucent', depth_test=False) scatter.set_data(pos, edge_width=0, face_color=(1, 1, 1, 1), size=point_size, scaling=True) vb.add(scatter) pos = scans[1][:, :3] scatter = visuals.Markers() scatter.set_gl_state('translucent', depth_test=False) scatter.set_data(pos, edge_width=0, face_color=(0, 1, 1, 1), size=point_size, scaling=True) vb.add(scatter) axis = visuals.XYZAxis() vb.add(axis) if img is None: img = np.zeros(shape=[1, 1, 3], dtype=np.float32) image = visuals.Image(data=img, method='auto') vb_img.camera = 'turntable' vb_img.camera.elevation = -90.0 vb_img.camera.center = (2100, -380, -500) vb_img.camera.azimuth = 0.0 vb_img.camera.scale_factor = 1500 vb_img.add(image) if boxes is not None: gt_indice = np.where(boxes["cls_rpn"] == 4)[0] gt_cnt = len(gt_indice) boxes_cnt = boxes["center"].shape[0] i = 0 for k in range(boxes_cnt): radio = max(boxes["score"][k] - 0.5, 0.005) * 2.0 color = (0, radio, 0, 1) # Green if boxes["cls_rpn"][k] == 4: # gt boxes i = i + 1 vsp_box = visuals.Box(depth=boxes["size"][k][0], width=boxes["size"][k][1], height=boxes["size"][k][2], color=(0.3, 0.4, 0.0, 0.06), edge_color='pink') mesh_box = vsp_box.mesh.mesh_data mesh_border_box = vsp_box.border.mesh_data vertices = mesh_box.get_vertices() center = np.array([ boxes["center"][k][0], boxes["center"][k][1], boxes["center"][k][2] ], dtype=np.float32) vertices_roa_trans = box_rot_trans(vertices, -boxes["yaw"][k][0], center) # mesh_border_box.set_vertices(vertices_roa_trans) mesh_box.set_vertices(vertices_roa_trans) vb.add(vsp_box) if True: text = visuals.Text(text='det: ({}/{})'.format(i, gt_cnt), color='white', face='OpenSans', font_size=12, pos=[ boxes["center"][k][0], boxes["center"][k][1], boxes["center"][k][2] ], anchor_x='left', anchor_y='top', font_manager=None) vb.add(text) elif (boxes["cls_rpn"][k] + boxes["cls_cube"][k] ) == 0: # True negative cls rpn divided by cube vb.add( line_box(boxes["center"][k], boxes["size"][k], -boxes["yaw"][k], color=color)) elif (boxes["cls_rpn"][k] + boxes["cls_cube"][k] ) == 1: # False negative cls rpn divided by cube vb.add( line_box(boxes["center"][k], boxes["size"][k], -boxes["yaw"][k], color="red")) elif (boxes["cls_rpn"][k] + boxes["cls_cube"][k] ) == 2: # False positive cls rpn divided by cube vb.add( line_box(boxes["center"][k], boxes["size"][k], -boxes["yaw"][k], color="blue")) elif (boxes["cls_rpn"][k] + boxes["cls_cube"][k] ) == 3: # True positive cls rpn divided by cube vb.add( line_box(boxes["center"][k], boxes["size"][k], -boxes["yaw"][k], color="yellow")) text = visuals.Text( text=str(k), color=color, face='OpenSans', font_size=12, pos=[ boxes["center"][k][0] - boxes["size"][k][0] / 2, boxes["center"][k][1] - boxes["size"][k][1] / 2, boxes["center"][k][2] - boxes["size"][k][2] / 2 ], anchor_x='left', anchor_y='top', font_manager=None) vb.add(text) if save_img: folder = path_add(cfg.TEST_RESULT, cfg.RANDOM_STR) if not os.path.exists(folder): os.makedirs(folder) fileName = path_add(folder, str(index).zfill(6) + '.png') res = canvas.render(bgcolor='black')[:, :, 0:3] vispy_file.write_png(fileName, res) @canvas.connect def on_key_press(ev): if ev.key.name in '+=': a = vb.camera.get_state() print(a) if visible: pass vispy.app.run() return canvas
mask_scatter = visuals.Markers() pred_scatter = visuals.Markers() real_scatter.set_data(data[:, :3], edge_color=None, face_color=real_colors, size=5) mask_scatter.set_data(data[:, :3], edge_color=None, face_color=mask_colors, size=5) pred_scatter.set_data(data[:, :3], edge_color=None, face_color=pred_colors, size=5) vb1.add(real_scatter) vb2.add(mask_scatter) vb3.add(pred_scatter) vb1.camera = 'turntable' vb2.camera = 'turntable' vb3.camera = 'turntable' vb1.camera.link(vb2.camera) vb1.camera.link(vb3.camera) vb1.camera.set_range() # add a colored 3D axis for orientation real_axis = visuals.XYZAxis(parent=vb1.scene) mask_axis = visuals.XYZAxis(parent=vb2.scene) pred_axis = visuals.XYZAxis(parent=vb3.scene) if __name__ == '__main__': import sys if sys.flags.interactive != 1: vispy.app.run()