示例#1
0
def add_routine(originalFilePath, routineFullPath):
    if not os.path.exists(routineFullPath):
        print("File not found:", routineFullPath)
        return

    # Open database
    db = getDb()

    routineRelPath = routineFullPath.replace(consts.videosRootPath, '')
    originalRelPath = originalFilePath.replace(consts.videosRootPath, '')
    competition = routineFullPath.split(os.sep)[-3]

    # Use OpenCV to get video meta data
    cap = helper_funcs.open_video(routineFullPath)
    height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
    width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
    fps = cap.get(cv2.CAP_PROP_FPS)
    frame_count = cap.get(cv2.CAP_PROP_FRAME_COUNT)

    try:
        routine = Routine(routineRelPath, originalRelPath, competition, height,
                          width, fps, frame_count)
        db.add(routine)
        db.commit()
        print("Routine addded:", routineFullPath)

        output_images.generate_thumbnail(routine)

    except sqlite3.IntegrityError:
        print("Routine already in db:", routineFullPath)
示例#2
0
def generate_many_thumbnails():
    db = getDb()

    routines = db.query(Routine).filter(or_(Routine.use == 1, Routine.use == None)).all()

    for routine in routines:
        generate_thumbnail(routine)
示例#3
0
def add_to_database(original, routine_path):
    # Open database
    db = getDb()

    # Check that the folder to use exists
    routine_path = os.path.abspath(routine_path)
    if not os.path.exists(routine_path):
        print('No such directory ' + routine_path)
        exit()

    print("Adding files to database")
    files = [
        f for f in os.listdir(routine_path)
        if os.path.isfile(os.path.join(routine_path, f)) and '.mp4' in f
    ]
    for f in files:
        # Do path stuff
        absVideoPath = os.path.join(routine_path,
                                    f)  # make the absolute path to the file
        pathFromVideoRoot = absVideoPath.replace(
            os.path.abspath(helpers.consts.videosRootPath) + os.sep,
            "")  # Make the path relative to the videos root folder
        competition = pathFromVideoRoot.split(os.sep)[0]

        # Use OpenCV to get video meta data
        cap = cv2.VideoCapture(absVideoPath)
        height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
        width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
        fps = cap.get(cv2.CAP_PROP_FPS)
        frame_count = cap.get(cv2.CAP_PROP_FRAME_COUNT)

        try:
            Routine(pathFromVideoRoot, competition, height, width, fps,
                    frame_count)
        except sqlite3.IntegrityError:
            print("Routine already in db:", pathFromVideoRoot)
            continue
        print("Routine addded:", pathFromVideoRoot)

    db.commit()
    db.close()
示例#4
0
import os

import cv2
import numpy as np

from helpers import consts
from helpers import helper_funcs
from helpers.db_declarative import getDb, Routine

db = getDb()

# Add frame count to database table
routines = db.query(Routine).all()
for routine in routines:
    pathToVideo = os.path.join(consts.videosRootPath, routine.path)
    cap = cv2.VideoCapture(pathToVideo)
    routine.frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
db.commit()
exit()

routines = db.query(Routine).filter(Routine.use == 1).all()
# routines = db.query(Routine).filter(Routine.id == 35).all()
# if False:
# Delete frames coming from some other routine... :/
for routine in routines:
    cap = helper_funcs.open_video(routine.path)
    frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))

    if routine.frames[-1].frame_num > frame_count:
        for frame in routine.frames:
            if frame.frame_num > frame_count:
示例#5
0
def main():
    db = getDb()

    # routines = db.query(Routine).filter(Routine.use == 1).all()
    # bounces_count = 0
    # for routine in routines:
    #     bounces_count += len(routine.bounces)
    # print("Average num bounces per routine is {}".format(bounces_count/len(routines)))
    # exit()
    # plot_tariff_confusion_matrix(db)
    # plot_skill_bar_charts(db)
    #
    # bounce = db.query(Bounce).filter(Bounce.id == 1520).one()
    # bounce = db.query(Bounce).filter(Bounce.id == 1551).one()
    # bounce = db.query(Bounce).filter(Bounce.id == 1870).one()  # me gopro tuck jump
    # plot_angles_1x6_save_image(bounce)
    # skill_into_filmstrip(bounce)
    # plot_angles_6x2_filtering_effect(bounce)
    # play_frames_of_2_bounces(db, bounce, bounce)

    # exit()

    # judge_skill(db)

    # Tariff
    # for i in range(1, 7):
    #     db.execute("DELETE FROM tariff_matches")
    #     db.commit()
    #     set_reference_skills(db, i)
    #     tariff_bounces_test_set(db)
    # tariff_epochs(db)

    # open_epoch_save_data()
    # print_list_of_skills(db)

    # Convert names to performers
    routines = db.query(Routine).filter(Routine.performer_id != None).all()
    for routine in routines:
        perf = routine.performer
        if perf.sex is not None and perf.sex != routine.sex:
            print('Mismatch')
        perf.sex = routine.sex
    db.commit()
    exit()

    # Tariff Routines
    # routines = db.query(Routine).filter(Routine.use == 1, Routine.has_pose == 1).all()
    # tariff_many_routines(db, routines)
    # tariff_bounces_test_set(db)

    # Thesis
    # routine = db.query(Routine).filter(Routine.id == 1).one()
    # routine = db.query(Routine).filter(Routine.id == 129).one()  # high res #1
    routine = db.query(Routine).filter(Routine.id == 127).one()  # first gopro
    # plot_twist(routine)
    # plot_3d(routine)
    # routine = db.query(Routine).filter(Routine.id == 82).one()  # colm
    # routine = db.query(Routine).filter(Routine.id == 89).one()  # cian
    # detect_trampoline(db, routine)
    track_gymnast(db, routine)
    # save_cropped_frames(db, routine, routine.frames)
    # play_monocap_imgs(routine)
    # play_frames(db, routine)
    # calculate_bounces(routine)
    # play_frames(db, routine)
    # import_pose_unfiltered(db, routine)

    exit()

    # Execute
    routines = db.query(Routine).filter(
        Routine.use == 1, Routine.id >= 89).order_by(Routine.level).all()
    for i, routine in enumerate(routines):
        print(routine)

        # for i, routine in enumerate(routines):
        #     print()
        #     print(routine.id, routine.path)
        #     print("Note:", routine.note)
        #     # print("Level:", consts.levels[routine.level])
        #     # trampolineObj = {'top': routine.trampoline_top, 'center': routine.trampoline_center, 'width': routine.trampoline_width, }
        #     # print("Trampoline:", trampolineObj)
        #     print("Tracked:", routine.isTracked(db))
        #     # print("Bounces:", prettyPrintRoutine(routine.bounces))
        #     # print("Bounces:", len(routine.bounces))
        #     # print("Frames Saved:", routine.hasFramesSaved())
        #     print("Pose Imported:", routine.isPoseImported(db))
        #     print("Use:", routine.use)
        #
        #     helper_funcs.print_pose_status(routine.getPoseDirPaths())
        #
        #     print()

        # import_output.import_monocap_preds_2d(db, routine)
        # if routine.isPoseImported(db):
        #     # Play the MATLAB images back as a video
        #     # visualise.compare_pose_tracking_techniques(routine)
        #     pass
        # else:
        #     continue

        # If this routine is selected, automatically prompt to locate trampoline.
        # if not routine.trampoline_top or not routine.trampoline_center or not routine.trampoline_width:
        #     # Detect Trampoline
        #     trampoline.detect_trampoline(db, routine)
        #
        # if not routine.isTracked():
        #     print("Auto tracking frames")
        #     # Track gymnast and save
        #     track.track_and_save(db, routine)
        #     # Find bounces and save
        #     segment_bounces.segment_bounces_and_save(db, routine)
        #     # Plot
        #     visualise.plot_data(routine)

        # if not routine.hasFramesSaved('_blur_dark_0.6'):
        #     import_pose.save_cropped_frames(db, routine, routine.frames, '_blur_dark_0.6')
        # else:
        # image_processing.visualise.compare_pose_tracking_techniques(routine)

        # if True:
        #     continue
        # else:
        #     # Options as [Title, function name, [function args]]
        #     options = [
        #         ["Detect Trampoline", trampoline.detect_trampoline, [db, routine]],
        #         ["Track and Save", track.track_and_save, [db, routine]],
        #         ["Track without Save", track.track_gymnast, [routine]],
        #         ["Segment Bounces", segment_bounces.segment_bounces_and_save, [db, routine]],
        #         ["Save Cropped Frames", import_output.save_cropped_frames, [db, routine]],
        #         ["Plot", visualise.plot_data, [routine]],
        #         ["Import Pose", import_output.import_pose_hg_smooth, [db, routine, routine.frames]],
        #         ["Play Video", visualise.play_frames, [db, routine]],
        #         # ["Plot Routine Angles", visualise.plot_frame_angles, [db, routine]],
        #         ["Exit", None, [None]],
        #     ]
        #     print("This routine has already been tracked.")
        #     while True:
        #         print("What would you like to do?")
        #         choiceIndex = helper_funcs.selectListOption([op[0] for op in options])
        #         if choiceIndex == len(options) - 1:  # Last option is to Exit
        #             break
        #         else:
        #             # Load function name and covert iterable to positional args.    http://stackoverflow.com/questions/3941517/converting-list-to-args-in-python
        #             options[choiceIndex][1](*options[choiceIndex][2])

        print("Finished routine {} of {}".format(i + 1, len(routines)))

    db.close()
    print("Done")