Пример #1
0
def getData(video_path, out_dir=None, overwrite=0):
    ''' 試合動画からカウントと生存状況を取得 '''
    # 動画の名前の取得
    video_name, video_ext = os.path.splitext(os.path.basename(video_path))
    video_dir = os.path.dirname(video_path)
    # 読み込みファイル
    info_path = video_dir + '\\' + video_name + '_info.csv'
    # 出力先
    out_dir = video_dir if not out_dir else out_dir
    status_path = out_dir + '\\' + video_name + '_status.csv'
    count_path = out_dir + '\\' + video_name + '_count.csv'

    if not os.path.exists(info_path):
        iip.printMeter(meter_name, 1, 1)
    if os.path.exists(status_path) and os.path.exists(count_path) \
        and overwrite==0:
        iip.printMeter(meter_name, 1, 1)
    else:
        # 動画の情報を読み込む
        info_dict = csvread.readAsDict(info_path)
        viewpoint = info_dict['viewpoint']

        # 視点に応じて動画処理
        if viewpoint == 'obj':
            status_list, count_list = forObjective(video_path, info_dict)
        elif viewpoint == 'sub':
            status_list, count_list = forSubjective(video_path, info_dict)

        # CSV出力
        with open(status_path, 'w') as file:
            writer = csv.writer(file, lineterminator='\n')
            writer.writerows(status_list)

        with open(count_path, 'w') as file:
            writer = csv.writer(file, lineterminator='\n')
            writer.writerows(count_list)
Пример #2
0
def getScreen(video_path, out_dir=None, overwrite=0):
    ''' 主観視点動画の画面状況を調べる '''
    # 動画の名前の取得
    video_name, video_ext = os.path.splitext(os.path.basename(video_path))
    video_dir = os.path.dirname(video_path)
    # 読み込みファイル
    info_path = video_dir + '\\' + video_name + '_info.csv'
    # 出力先
    out_dir = video_dir if not out_dir else out_dir
    out_path = out_dir + '\\' + video_name + '_screen.csv'

    if not os.path.exists(info_path):
        iip.printMeter(meter_name, 1, 1)
    elif os.path.exists(out_path) and overwrite == 0:
        iip.printMeter(meter_name, 1, 1)
    else:
        # 動画読み込み
        video = cv2.VideoCapture(video_path)
        frame_all = int(video.get(cv2.CAP_PROP_FRAME_COUNT))

        # 動画の情報を読み込む
        info_dict = csvread.readAsDict(info_path)
        frame_start = info_dict['frame_start']
        frame_end = info_dict['frame_end']

        # 出力リスト
        screen_list = [['fcount', 'screen_map', 'maxVal']]

        ### ここから動画処理 #################################################
        fcount = 0
        while video.isOpened():

            # フレーム取得
            ret, frame = video.read()
            # フレーム取得できなかったら終了
            if not ret:
                break

            # フレームカウント
            fcount += 1
            # 処理進捗をコマンドラインに表示
            iip.printMeter(meter_name, fcount, frame_all)

            # 試合中のフレームを対象
            if frame_start <= fcount < frame_end:
                # 画面判別
                jug, val = judgeNice(frame)
                # ナイス表示がなければマップ画面
                screen_map = 0 if jug else 1
                # 出力リストに記録
                screen_list.append([fcount, screen_map, val])

            elif fcount == frame_end:
                break

        video.release
        iip.printMeter(meter_name, frame_all, frame_all)
        ### ここまで動画処理 #################################################

        # CSV出力
        with open(out_path, 'w') as file:
            writer = csv.writer(file, lineterminator='\n')
            writer.writerows(screen_list)

        return screen_list
Пример #3
0
def forObjective(video_path, info_dict):
    ''' 俯瞰視点:試合のデータを取得する '''
    # 動画の情報を読み込む
    frame_all = info_dict['frame_all']
    frame_start = info_dict['frame_start']
    frame_end = info_dict['frame_end']
    rule = info_dict['rule']
    stage_num = info_dict['stage_num']
    team_color_a = info_dict['team_color_alfa']
    team_color_b = info_dict['team_color_bravo']
    team_color = [team_color_a, team_color_b]

    # エリアの数を取得(ルールがエリア以外ならば0)
    zones_num = getZonesNum(rule, stage_num)

    # 記録リスト
    status_list = [['fcount'] + readListTop('lamp')]
    count_list = [['fcount'] + readListTop(rule, zones_num)]

    # 動画読み込み
    video = cv2.VideoCapture(video_path)

    ### ここから動画処理 #####################################################
    fcount = 0
    while video.isOpened():
        # フレーム取得
        ret, frame = video.read()
        # フレーム取得できなかったら終了
        if not ret:
            break

        # フレームカウント
        fcount += 1
        # 処理進捗をコマンドラインに表示
        iip.printMeter(meter_name, fcount, frame_all)

        # 試合中のフレームが対象
        if frame_start <= fcount < frame_end:
            # イカランプから状態を取得
            status_frame = ikaLamp.forFrameObjective(frame, team_color)

            # ルールごとの情報を取得
            if rule == 'zones':
                count_frame = ikaZones.frame(frame, zones_num, team_color)
            elif rule == 'tower':
                count_frame = ikaTower.frame(frame)
            elif rule == 'rain':
                count_frame = ikaRainmaker.frame(frame)
            elif rule == 'clam':
                count_frame = ikaClam.frame(frame)
            else:
                count_frame = []

            # 出力リストに記録
            status_list.append([fcount] + status_frame)
            count_list.append([fcount] + count_frame)

        elif fcount == frame_end:
            break

    video.release
    iip.printMeter(meter_name, frame_all, frame_all)
    ### ここまで動画処理 #####################################################

    return status_list, count_list
Пример #4
0
def forSubjective(video_path, info_dict):
    ''' 主観視点:試合のデータを取得する '''
    # 画面情報ファイル読み込み
    video_name, video_ext = os.path.splitext(os.path.basename(video_path))
    video_dir = os.path.dirname(video_path)
    screen_path = video_dir + '\\' + video_name + '_screen.csv'
    screen_list = csvread.readAsList(screen_path)

    # 動画の情報を読み込む
    frame_all = info_dict['frame_all']
    frame_start = info_dict['frame_start']
    frame_end = info_dict['frame_end']
    rule = info_dict['rule']
    stage_num = info_dict['stage_num']
    team_color_a = info_dict['team_color_alfa']
    team_color_b = info_dict['team_color_bravo']
    user_num = info_dict['user_num']
    team_color = [team_color_a, team_color_b]
    shape_list = [info_dict['shape_' + str(i + 1)] for i in range(8)]

    # エリアの数を取得(ルールがエリア以外ならば0)
    zones_num = getZonesNum(rule, stage_num)

    # 記録リスト
    status_list = [['fcount'] + readListTop('lamp')]
    count_list = [['fcount'] + readListTop(rule, zones_num)]
    # リストの幅
    width_list = len(count_list[0]) - 1

    # 動画読み込み
    video = cv2.VideoCapture(video_path)

    ### ここから動画処理 #####################################################
    fcount = 0
    while video.isOpened():
        # フレーム取得
        ret, frame = video.read()
        # フレーム取得できなかったら終了
        if not ret:
            break

        # フレームカウント
        fcount += 1
        # 処理進捗をコマンドラインに表示
        iip.printMeter(meter_name, fcount, frame_all)

        # 試合中のフレームが対象
        if frame_start <= fcount < frame_end:
            # 画面状況取得
            idx = fcount - frame_start + 1
            screen_map = screen_list[idx][1]

            if screen_map == 0:
                # イカランプから状態を取得
                status_frame = ikaLamp.forFrameSubjective(
                    frame, team_color, shape_list)
                # ルールごとの情報を取得
                count_frame = getCount(frame, rule, zones_num, team_color)

            elif screen_map == 1:
                # マップ画面から状態を取得
                status_frame = ikaLamp.getStatusMap(frame, team_color)
                # プレイヤーの状態は把握できない
                status_frame.insert(user_num - 1, 'nodata')

                # カウント等は取得できない
                count_frame = ['nodata' for i in range(width_list)]

            # 出力リストに記録
            status_list.append([fcount] + status_frame)
            count_list.append([fcount] + count_frame)

        elif fcount == frame_end:
            break

    video.release
    iip.printMeter(meter_name, frame_all, frame_all)
    ### ここまで動画処理 #####################################################

    return status_list, count_list
Пример #5
0
def getinfo(video_path, out_dir=None, overwrite=0):
    ''' 試合動画の情報を取得する '''
    # 動画の名前の取得
    video_name, video_ext = os.path.splitext(os.path.basename(video_path))
    video_dir = os.path.dirname(video_path)
    # 出力先
    out_dir = video_dir if not out_dir else out_dir
    out_path = out_dir + '\\' + video_name + '_info.csv'

    # 取得状況の把握
    if os.path.exists(out_path) and overwrite==0:
        iip.printMeter(meter_name, 1, 1)
        info_list = csvread.readAsList(out_path)
    else:
        # 動画読み込み
        video = cv2.VideoCapture(video_path)
        fps = video.get(cv2.CAP_PROP_FPS)
        frame_all = int(video.get(cv2.CAP_PROP_FRAME_COUNT))

        # 取得する変数たち
        frame_rule  = 0
        rule        = 'nodata'
        stage_num   = 0
        frame_start = 0
        frame_end   = 0
        viewpoint   = 'nodata'
        user_num    = 0

        ### ここから動画処理 #################################################
        fcount = 0
        while video.isOpened():
            # フレーム取得
            ret, frame = video.read()
            # フレーム取得できなかったら終了
            if not ret:
                break

            # フレームカウント
            fcount += 1
            # 処理進捗をコマンドラインに表示
            iip.printMeter(meter_name, fcount, frame_all)

            if frame_rule == 0:
                # ルール表示の判定
                jug_frame = ikaRule.judgeRule(frame)
                if jug_frame:
                    # 「ル」が表示されてから1秒後が判定フレーム
                    # エフェクトによってルール名などが表示されていないため
                    frame_rule = fcount + round(fps*1)

            elif fcount == frame_rule:
                # ルール取得
                rule = ikaRule.getRule(frame)
                # ステージ取得
                stage_num = ikaStage.getStage(frame)

            elif frame_start == 0:
                # 試合開始の判定
                if rule == 'turf':
                    jug_start = ikaStartEnd.judgeStartTurf(frame)
                else:
                    jug_start = ikaStartEnd.judgeStartGachi(frame)

                if jug_start:
                    # 試合開始は1秒前
                    # 試合開始ピッタリは時計表示がなくて認識できない
                    frame_start = fcount - round(fps*1)
                    # チームカラーの取得
                    team_color = ikaLamp.getTeamColor(frame)
                    # 視点の取得
                    # viewpoint, user_num = 'obj', 0
                    viewpoint, user_num = selectViewpoint(frame)
                    # イカランプの形の取得
                    if viewpoint == 'sub':
                        shape_list = ikaLamp.getShape(frame, team_color)
                    else:
                        shape_list = ['nodata' for i in range(8)]

            elif frame_end == 0:
                # 試合終了の判定
                jug_end = ikaStartEnd.judgeEnd(frame)
                if jug_end:
                    frame_end = fcount

            else:
                break

        video.release
        iip.printMeter(meter_name, frame_all, frame_all)
        ### ここまで動画処理 #################################################

        # リスト先頭行
        list_top = ['fps', 'frame_all', 'frame_start', 'frame_end',
                    'viewpoint', 'rule', 'stage_num',
                    'team_color_alfa', 'team_color_bravo', 'user_num']
        list_top += ['shape_' + str(i+1) for i in range(8)]
        # リスト内容 contents
        list_con = [fps, frame_all, frame_start, frame_end,
                    viewpoint, rule, stage_num,
                    team_color[0], team_color[1], user_num]
        list_con += shape_list
        # 出力リスト
        info_list = [list_top, list_con]

        # CSV出力
        with open(out_path, 'w') as file:
            writer = csv.writer(file, lineterminator='\n')
            writer.writerows(info_list)

    return info_list