Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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 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)
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)