Ejemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--content",
                        help="1: Point To Target" + " 2: Change Detection" +
                        " 3: Odd One Out" + " 4: Visual Search" +
                        " 5: Multiple Object Tracking" +
                        " 6: Random Dot Motion Descrimination",
                        type=int,
                        default=1)
    args = parser.parse_args()

    content_type = args.content

    if content_type == CONTENT_POINT_TO_TARGET:
        content = PointToTargetContent()
    elif content_type == CONTENT_CHANGE_DETECTION:
        content = ChangeDetectionContent()
    elif content_type == CONTENT_ODD_ONE_OUT:
        content = OddOneOutContent()
    elif content_type == CONTENT_VISUAL_SEARCH:
        content = VisualSearchContent()
    elif content_type == CONTENT_MULTIPLE_OBJECT_TRACKING:
        content = MultipleObjectTrackingContent()
    else:
        content = RandomDotMotionDiscriminationContent()

    FPS = 60
    display_size = (128 * 4 + 16, 500)
    inspector = Inspector(content, display_size)

    clock = pygame.time.Clock()
    running = True

    frame_count = 0

    if RECORDING:
        writer = MovieWriter("out.mov", inspector.display_size, FPS)

    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

        inspector.update()
        clock.tick(FPS)

        if RECORDING:
            d = inspector.get_frame()
            writer.add_frame(d)

            frame_count += 1

            if frame_count > 1000:
                running = False

    if RECORDING:
        writer.close()
Ejemplo n.º 2
0
class Runner(object):
    def __init__(self):
        self.content_id = 0
        self.difficulty = -1
        self.inspector = Inspector(contents[self.content_id](-1), display_size)
        self.lock = Lock()

    def init(self):
        self.set_content(0)
        self.set_difficulty(-1)
        return self.info()

    def info(self):
        return flask.jsonify({
            'content_range': len(contents),
            'content': self.content_id,
            'difficulty_range': contents[self.content_id].difficulty_range,
            'difficulty': self.difficulty,
        })

    def step(self):
        with self.lock:
            self.inspector.update()
            image = self.inspector.get_frame()
        data = cv2.imencode('.png', image)[1].tobytes()
        encoded = base64.encodestring(data)
        return make_response(encoded)

    def set_content(self, content_id):
        with self.lock:
            self.content_id = content_id
            content = contents[self.content_id](self.difficulty)
            self.inspector = Inspector(content, display_size)
            ret = {
                'difficulty_range': contents[content_id].difficulty_range,
                'difficulty': -1,
            }
            return flask.jsonify(ret)

    def set_difficulty(self, difficulty):
        with self.lock:
            self.difficulty = difficulty
            content = contents[self.content_id](self.difficulty)
            self.inspector = Inspector(content, display_size)
        return 'New Content Created', HTTPStatus.OK
Ejemplo n.º 3
0
class Runner(object):
    def __init__(self):
        self.content_id = 0
        self.inspector = Inspector(contents[self.content_id], display_size)
        self.lock = Lock()

    def step(self):
        with self.lock:
            self.inspector.update()
            image = self.inspector.get_frame()
        data = cv2.imencode('.png', image)[1].tobytes()
        encoded = base64.encodestring(data)
        return make_response(encoded)

    def swap(self, content_id):
        with self.lock:
            self.inspector = Inspector(contents[content_id], display_size)
        return 'Switched Content', HTTPStatus.OK
Ejemplo n.º 4
0
class Runner(object):
    def __init__(self):
        from inspector import Inspector
        from oculoenv import PointToTargetContent, ChangeDetectionContent, OddOneOutContent, VisualSearchContent, MultipleObjectTrackingContent, RandomDotMotionDiscriminationContent
        self.contents = [
            PointToTargetContent,
            ChangeDetectionContent,
            OddOneOutContent,
            VisualSearchContent,
            MultipleObjectTrackingContent,
            RandomDotMotionDiscriminationContent,
        ]
        self.content_id = args.content
        self.difficulty = -1
        self.inspector = Inspector(
            self.contents[args.content](-1), display_size,
            model_name=args.model_name,
            use_ppo_models=args.use_ppo_models
        )
        self.lock = Lock()

    def init(self):
        #self.set_content(0)
        #self.set_difficulty(-1)
        return self.info()

    def info(self):
        return json.dumps({
            'content_range': len(self.contents),
            'content': self.content_id,
            'difficulty_range': self.contents[self.content_id].difficulty_range,
            'difficulty': self.difficulty,
        })

    def step(self):
        #with self.lock:
        self.inspector.update()
        image = self.inspector.get_frame()
        data = cv2.imencode('.png', image)[1].tobytes()
        encoded = base64.encodestring(data)
        return encoded

    def set_content(self, content_id):
        #with self.lock:
        print('content')
        self.content_id = content_id
        content = self.contents[self.content_id](self.difficulty)
        self.inspector = Inspector(content, display_size)
        ret = {
            'difficulty_range': self.contents[content_id].difficulty_range,
            'difficulty': -1,
        }
        return flask.jsonify(ret)

    def set_difficulty(self, difficulty):
    #    with self.lock:
        print('difficulty')
        self.difficulty = difficulty
        content = self.contents[self.content_id](self.difficulty)
        self.inspector = Inspector(content, display_size)
        return 'New Content Created', HTTPStatus.OK