Пример #1
0
def render_one_anno(raw_data, directory, anno_id):
    """
    Input:
        raw_data: the huge dictionary of a single game
    """
    print('Running Scripts::Make_One_Annotation:render_one_anno')
    N = len(raw_data['events'])
    anno_id = int(anno_id)
    pnr_annotations = annotation.read_annotation_from_raw(os.path.join(pnr_dir, 'roles/%s' % (arguments['<raw_file>'])), raw_data['gameid'])
    annos = pnr_annotations[anno_id]

    for ind, anno in enumerate(annos):
        e = Event(raw_data['events'][anno_id], anno=anno)
        ## render
        try:
            e.sequence_around_t(anno, int(arguments['<time-frame-radius>']), pnr=True)
            before = copy(e)
            after = copy(e)
            before.moments = before.moments[:int(arguments['<time-frame-radius>'])]
            after.moments = after.moments[int(arguments['<time-frame-radius>']):]
            before.show_static(os.path.join(directory, '%i-pnr-%i-before.pdf' %(anno_id, ind)), anno=anno)
            after.show_static(os.path.join(directory, '%i-pnr-%i-after.pdf' % (anno_id, ind)), anno=anno)
        except EventException as e:
            print ('malformed sequence, skipping')
            continue
def render_one_game(raw_data, directory, skip_these):
    """
    Input:
        raw_data: the huge dictionary of a single game
    """
    print('Running Scripts::Make_One_Game_Topics:render_one_game')
    N = len(raw_data['events'])
    pnr_annotations = annotation.read_annotation_from_raw(
        os.path.join(pnr_dir, 'roles/%s' % (arguments['<raw_file>'])),
        raw_data['gameid'])

    annotations = pd.read_csv('%s/%s/raw-%s.csv' %
                              (pnr_dir, 'extended', arguments['<gameid>']))
    annotations[['over', 'under', 'switch',
                 'trap']] = annotations[['over', 'under', 'switch',
                                         'trap']].fillna(0)
    annotations[['over', 'under', 'switch',
                 'trap']] = annotations[['over', 'under', 'switch',
                                         'trap']].replace('x', 1)

    for i in xrange(N):
        if i in skip_these:
            print('Skipping event <%i>' % i)
            continue
        else:
            if i not in pnr_annotations.keys():
                print "Clip index %i not labelled" % i
                continue
            else:
                annos = pnr_annotations[i]

        for ind, anno in enumerate(annos):
            ## preprocessing
            true_annotation = annotations.loc[
                (annotations.eid == anno['eid']) &
                (annotations.gameclock == anno['gameclock']), :]

            y_true = true_annotation[['over', 'under', 'switch',
                                      'trap']].values
            y_true = np.argmax(y_true, axis=1)

            e = Event(raw_data['events'][i], anno=anno)
            ## render
            try:
                new_dir = '%s/%s' % (directory, e.anno['topic'])
                if not os.path.exists(new_dir):
                    os.makedirs(new_dir)
                e.sequence_around_t(anno,
                                    int(arguments['<time-frame-radius>']),
                                    pnr=True)
                e.show(os.path.join(
                    new_dir, '%i-pnr-%i-%i.mp4' %
                    (i, int(e.anno['gameclock']), int(y_true))),
                       anno=anno)
            except Exception as e:
                print('malformed sequence, skipping')
                continue
Пример #3
0
def render_one_game(raw_data, directory, skip_these):
    print('Running Scripts::Make_One_Game_Vis:render_one_game')
    """
    Input:
        raw_data: the huge dictionary of a single game
    """
    N = len(raw_data['events'])
    if arguments['--annotate']:
        pnr_annotations = annotation.read_annotation(
            os.path.join(
                pnr_dir,
                arguments['<pnr-prefix>'] + '-' + raw_data['gameid'] + '.csv'))
    elif arguments['--from_raw']:
        pnr_annotations = annotation.read_annotation_from_raw(
            os.path.join(pnr_dir, 'roles/%s' % (arguments['<raw_file>'])),
            raw_data['gameid'])
    for i in xrange(N):
        if i in skip_these:
            print('Skipping event <%i>' % i)
            continue
        else:
            if i not in pnr_annotations.keys():
                print "Clip index %i not labelled" % i
                continue
            else:
                annos = pnr_annotations[i]

        for ind, anno in enumerate(annos):
            ## preprocessing
            if arguments['--annotate'] or arguments['--from_raw']:
                e = Event(raw_data['events'][i], anno=anno)
                ## render
                try:
                    e.sequence_around_t(anno,
                                        int(arguments['<time-frame-radius>']),
                                        pnr=True)
                    e.show(os.path.join(directory, '%i-pnr-%i.mp4' % (i, ind)),
                           anno=anno)
                except EventException as e:
                    print('malformed sequence, skipping')
                    continue
            else:
                ## truncate
                if i < N - 1:
                    e.truncate_by_following_event(raw_data['events'][i + 1])
                ## render
                try:
                    print('Creating video for event: %i' % (i))
                    e.show(os.path.join(directory, '%i.mp4' % i))
                except EventException as e:
                    print('malformed sequence, skipping')
                    continue