def get_cam(camera_name="91"): for cam in m.get_cams(): if camera_name in cam.name: # cam.frame_rate=100 # m.update() # m.update() # m.update() return cam
def motive_camera_vislight_configure(): for cam in motive.get_cams(): # All cameras should have frame rate changed. cam.frame_rate = 30 if 'Prime 13' in cam.name: cam.settings = motive.CameraSettings(video_mode=2, exposure=33000, threshold=200, intensity=0) cam.image_gain = 5 # 8 is the maximum image gain setting cam.set_filter_switch(False) else: cam.settings = motive.CameraSettings(video_mode=0, exposure=cam.exposure, threshold=cam.threshold, intensity=cam.intensity)
def motive_camera_vislight_configure(): import motive for cam in motive.get_cams(): # All cameras should have frame rate changed. cam.frame_rate = 30 if 'Prime 13' in cam.name: cam.set_settings(video_mode=0, exposure=33000, threshold=80, intensity=0) #check if 480 corresponds to these thousands described in motive cam.image_gain = 8 # 8 is the maximum image gain setting cam.set_filter_switch(False) else: cam.set_settings(0, cam.exposure, cam.threshold, cam.intensity)
def motive_camera_vislight_configure(): for cam in motive.get_cams(): # All cameras should have frame rate changed. cam.frame_rate = 30 if 'Prime 13' in cam.name: cam.set_settings( video_mode=0, exposure=33000, threshold=200, intensity=0 ) #check if 480 corresponds to these thousands described in motive cam.image_gain = 8 # 8 is the maximum image gain setting cam.set_filter_switch(False) else: cam.set_settings(0, cam.exposure, cam.threshold, cam.intensity)
help='If this flag is present, the arena will be NOT offset by its mean marker position.') parser.add_argument('-r', action='store', dest='rigid_body_name', default='', help='Name of the Arena rigid body. If only one rigid body is present, unnecessary--that one will be used automatically.') parser.add_argument('-i', action='store', dest='motive_projectfile', default=motive.utils.backup_project_filename, help='Name of the motive project file to load. If not used, will load most recent Project file loaded in MotivePy.') args = parser.parse_args() # Select Rigid Body to track. motive.load_project(args.motive_projectfile) print("Loaded Motive Project: {}".format(args.motive_projectfile)) hardware.motive_camera_vislight_configure() print("Camera Settings changed to Detect Visible light:") print("\t"+"\n\t".join(['{}: FPS={}, Gain={}, Exp.={}, Thresh.={}'.format(cam.name, cam.frame_rate, cam.image_gain, cam.exposure, cam.threshold) for cam in motive.get_cams()])) motive.update() rigid_bodies = motive.get_rigid_bodies() try: if not args.rigid_body_name: assert len(rigid_bodies) == 1, "Only one rigid body should be present for auto-selection. Please use the -r flag to specify a rigid body name to track for the arena." arena_name = args.rigid_body_name if args.rigid_body_name in rigid_bodies else rigid_bodies.keys()[0] except IndexError: raise IndexError("No Rigid Bodies found in Optitrack tracker.") except KeyError: raise KeyError("Rigid Body '{}' not found in list of Optitrack Rigid Bodies.".format(arena_name)) print('Arena Name: {}. N Markers: {}'.format(arena_name, len(rigid_bodies[arena_name].markers))) assert len(rigid_bodies[arena_name].markers) > 5, "At least 6 markers in the arena's rigid body is required"
if __name__ == '__main__': import Tkinter, tkFileDialog from os import path import motive as m root = Tkinter.Tk() root.withdraw() profile_file_u = tkFileDialog.askopenfilename( title='Choose a profile file to load: ', filetypes=[('motive profilefiles', '*.motive')]) profile_file = profile_file_u.encode("ascii") m.load_profile(profile_file) for cam in m.get_cams(): cam.frame_rate = 30 if 'Prime 13' in cam.name: cam.set_settings( videotype=0, exposure=33000, threshold=40, intensity=0 ) #check if 480 corresponds to these thousands described in motive cam.image_gain = 8 # 8 is the maximum image gain setting cam.set_filter_switch(False) else: cam.set_settings(0, cam.exposure, cam.threshold, cam.intensity) directory, extension = path.splitext(profile_file) saved_profile_pathname = ''.join([directory, '_vislight', extension]) m.save_profile(saved_profile_pathname) m.shutdown()
if __name__ == '__main__': import Tkinter, tkFileDialog from os import path import motive as m root = Tkinter.Tk() root.withdraw() project_file_u=tkFileDialog.askopenfilename(title='Choose a project file to load: ', filetypes=[('motive projectfiles', '*.ttp')]) project_file = project_file_u.encode("ascii") m.load_project(project_file) for cam in m.get_cams(): cam.frame_rate = 30 if 'Prime 13' in cam.name: cam.set_settings(videotype=0, exposure=33000, threshold=40, intensity=0) #check if 480 corresponds to these thousands described in motive cam.image_gain = 8 # 8 is the maximum image gain setting cam.set_filter_switch(False) else: cam.set_settings(0, cam.exposure, cam.threshold, cam.intensity) directory, extension = path.splitext(project_file) saved_project_pathname= ''.join([directory, '_vislight', extension]) m.save_project(saved_project_pathname) m.shutdown()
def scan_arena(motive_filename, output_filename, body, nomeancenter, nsides, screen): """Runs Arena Scanning algorithm.""" output_filename = output_filename + '.obj' if not path.splitext(output_filename)[1] else output_filename assert path.splitext(output_filename)[1] == '.obj', "Output arena filename must be a Wavefront (.obj) file" # Load Motive Project File motive_filename = motive_filename.encode() motive.initialize() motive.load_project(motive_filename) # Get old camera settings before changing them, to go back to them before saving later. cam_settings = [cam.settings for cam in motive.get_cams()] frame_rate_old = motive.get_cams()[0].frame_rate hardware.motive_camera_vislight_configure() motive.update() # Get Arena's Rigid Body rigid_bodies = motive.get_rigid_bodies() assert body in rigid_bodies, "RigidBody {} not found in project file. Available body names: {}".format(body, list(rigid_bodies.keys())) # assert len(rigid_bodies[body].markers) > 5, "At least 6 markers in the arena's rigid body is required. Only {} found".format(len(rigid_bodies[body].markers)) for el in range(3): rigid_bodies[body].reset_orientation() rigid_bodies[body].reset_pivot_offset() motive.update() assert np.isclose(np.array(rigid_bodies[body].rotation), 0).all(), "Orientation didn't reset." assert np.isclose(np.array(rigid_bodies[body].location), np.mean(rigid_bodies[body].point_cloud_markers, axis=0)).all(), "Pivot didn't reset." print("Location and Orientation Successfully reset.") # Scan points display = pyglet.window.get_platform().get_default_display() screen = display.get_screens()[screen] window = GridScanWindow(screen=screen, fullscreen=True) pyglet.app.run() points = np.array(window.marker_pos) assert(len(points) > 100), "Only {} points detected. Tracker is not detecting enough points to model. Is the projector turned on?".format(len(points)) assert points.ndim == 2 # Plot preview of data collected fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(*points.T) plt.show() # Get vertex positions and normal directions from the collected data. vertices, normals = pointcloud.meshify_arena(points, n_surfaces=nsides) vertices, face_indices = pointcloud.face_index(vertices) face_indices = pointcloud.fan_triangulate(face_indices) # Reapply old camera settings, then save. for setting, cam in zip(cam_settings, motive.get_cams()): cam.settings = setting cam.image_gain = 1 cam.frame_rate = frame_rate_old if 'Prime 13' in cam.name: cam.set_filter_switch(True) motive.update() # me if not nomeancenter: # import ipdb # ipdb.set_trace() vertmean = np.mean(vertices[face_indices.flatten(), :], axis=0) # vertmean = np.array([np.mean(np.unique(verts)) for verts in vertices.T]) # to avoid counting the same vertices twice. vertices -= vertmean points -= vertmean print('Old Location: {}'.format(rigid_bodies[body].location)) arena = rigid_bodies[body] for attempt in range(300): print('Trying to Set New Rigid Body location, attempt {}...'.format(attempt)) arena.reset_pivot_offset() arena.location = vertmean if np.isclose(arena.location, vertmean, rtol=.001).all(): break else: raise ValueError('Motive failed to properly shift pivot to center of mesh') print('Vertex Mean: {}'.format(vertmean)) print('New Location: {}'.format(arena.location)) # Write wavefront .obj file to app data directory and user-specified directory for importing into Blender. writer = WavefrontWriter.from_indexed_arrays(body, vertices, normals, face_indices) with open(output_filename, 'w') as f: writer.dump(output_filename) # Show resulting plot with points and model in same place. fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(*points[::12, :].T) ax.scatter(*vertices.T, c='r') plt.show() # motive.save_project(motive_filename) motive.save_project(path.splitext(motive_filename)[0]+'_scanned.ttp')