def update_generator(): last_time= time.time() rig_data = ', '.join(['{0}: {1}'.format(body.name, body.color_name) for body in rigs.values()]) while True: m.update() # Update Title with new FPS try: fps = round(1. / (time.time() - last_time)) last_time = time.time() w.setWindowTitle('MotivePy Viewer. Rigid Bodies = {{{rigid_bodies}}}. Update Rate: {fps} fps'.format(rigid_bodies = rig_data, fps=fps)) except ZeroDivisionError: pass # Plot markers = m.get_unident_markers() if markers: unident_markers.setData(pos=np.array(m.get_unident_markers())) for rig, scat in zip(rigs.values(), w.items[1:-1]): scat.setData(pos=np.array(rig.point_cloud_markers)) # Return Nothing yield
def random_scan(window, scene, n_points=300): circle = scene.root.children[0] screenPos, pointPos = [], [] collect_fmt, missed_fmt, missed_cnt = ", Points Collected: ", ", Points Missed: ", 0 pbar = pb.ProgressBar(widgets=[pb.Bar(), pb.ETA(), collect_fmt +'0', missed_fmt+'0'], maxval=n_points) pbar.start() while len(pointPos) < n_points and 'escape' not in event.getKeys(): # Update position of circle, and draw. circle.visible = True homogenous_pos = np.random.random(2) - .5 circle.x, circle.y = homogenous_pos * [1.8, 1] slow_draw(window, scene) motive.update() # Try to isolate a single point. for _ in timers.countdown_timer(.2, stop_iteration=True): motive.flush_camera_queues() motive.update() markers = motive.get_unident_markers() if markers and markers[0][1] > 0.: screenPos.append(circle.position[:2]) # Update Progress Bar pointPos.append(markers[0]) pbar.widgets[2] = collect_fmt + str(len(pointPos)) pbar.update(len(pointPos)) break else: # Update Progress bar missed_cnt += 1 pbar.widgets[3] = missed_fmt + str(missed_cnt) pbar.update(len(pointPos)) # Hide circle, and wait again for a new update. circle.visible = False slow_draw(window, scene) motive.update() motive.flush_camera_queues() while len(motive.get_unident_markers()) > 0: motive.update() motive.flush_camera_queues() return np.array(screenPos), np.array(pointPos)
def detect_projection_point(self, dt): """Use Motive to detect the projected mesh in 3D space""" motive.flush_camera_queues() for el in range(2): motive.update() markers = motive.get_unident_markers() markers = [marker for marker in markers if 0.08 < marker[1] < 0.50] click.echo("{} markers detected.".format(len(markers))) self.marker_pos.extend(markers)
def detect_projection_point(self, dt): """Use Motive to detect the projected mesh in 3D space""" motive.flush_camera_queues() for el in range(2): motive.update() markers = motive.get_unident_markers() markers = [marker for marker in markers if marker[1] < 0.50 and marker[1] > 0.08] if len(markers) == 1: click.echo(markers) self.screen_pos.append([self.mesh.x, self.mesh.y]) self.marker_pos.append(markers[0])
def ray_scan(window): circle = window.active_scene.meshes[0] circle.visible = True # Do some non-random points to so human can change height range. pointPos, screenPos = [], [] for pos in [(0, 0), (-.5, 0), (.5, 0)]: circle.x, circle.y = pos window.draw() window.flip() for _ in timers.countdown_timer(5, stop_iteration=True): motive.update() markers = motive.get_unident_markers() old_time = motive.frame_time_stamp() if motive.frame_time_stamp() > old_time + .3 and len(markers) == 1: if markers[0][1] > 0.1: screenPos.append(circle.position[:2]) pointPos.append(markers[0]) old_time = motive.frame_time_stamp() return screenPos, pointPos
def scan(pointwidth=.06): """Project a series of points onto the arena, collect their 3d position, and save them and the associated rigid body data into a pickled file.""" # Initialize Calibration Point Grid. wavefront_reader = rc.WavefrontReader(rc.resources.obj_primitives) mesh = wavefront_reader.get_mesh('Grid', scale=1.5, drawstyle='point', point_size=12, position=(0,0,-1)) # mesh.material.diffuse.rgb = 1, 1, 1 scene = rc.Scene([mesh], bgColor=(0,0,0)) scene.camera.ortho_mode = True window = visual.Window(screen=1, fullscr=True) # Main Loop old_frame, clock, points = motive.frame_time_stamp(), utils.timers.countdown_timer(3.), [] for theta in np.linspace(0, 2*np.pi, 40)[:-1]: # Update Screen scene.camera.position = (pointwidth * np.sin(theta)), (pointwidth * np.cos(theta)), -1 scene.draw() window.flip() # Collect New Tracker Data old_frame = motive.frame_time_stamp() while motive.frame_time_stamp() == old_frame: motive.flush_camera_queues() motive.update() # Collect 3D points from Tracker markers = motive.get_unident_markers() if markers: points.extend(markers) # Housekeeping window.close() # Data quality checks and return. return np.array(points)