Free Motion Capture for Everyone πβ¨
TypeScript
Parameter yaml creation
Aaron Cherian4c84e1b9502f
diff --git a/freemocap/__init__.py b/freemocap/__init__.pyindex ea35df3b..70773613 100644--- a/freemocap/__init__.py+++ b/freemocap/__init__.py@@ -8,7 +8,6 @@ del get_versionsfrom freemocap import (createvideo,- initialization,recordingconfig,runcams,calibrate,@@ -195,7 +194,7 @@ def RunMe():# reupdate the config_settings with mediapipe and openpose image paths- sesh.config_settings = recordingconfig.load_config_yaml(sesh.yamlPath)+ #sesh.config_settings = recordingconfig.load_config_yaml(sesh.yamlPath)# %% Stage Sixdiff --git a/freemocap/initialization.py b/freemocap/initialization.pydeleted file mode 100644index 5db9a02c..00000000--- a/freemocap/initialization.py+++ /dev/null@@ -1,255 +0,0 @@-from pathlib import Path-from ruamel.yaml import YAML-import datetime-import sys-import pandas as pd-import numpy as np--from freemocap.webcam import recordGUI, camsetup-from freemocap import recordingconfig, fmc_anipose---def initialize(session, stage, board):-- print("Starting initialization for stage {}".format(stage))- # if stage == 1:- filepath = Path.cwd()-- session.board = board-- # %% Stage One Initialization- if stage == 1:-- # create session ID- sessionID_in = datetime.datetime.now().strftime("sesh_%y-%m-%d_%H%M%S")- session.sessionID = sessionID_in-- # load the parameters YAML and extract the saved parameters if possible, and the default otherwise- parameter_path = filepath / "parameters.yaml"- parameters_yaml = YAML()- parameters = parameters_yaml.load(parameter_path)-- try:- rotation_entry = parameters["saved"]["rotations"]- parameter_entry = parameters["saved"]["parameters"]- except:- print("Using Default Config")- rotation_entry = parameters["default"]["rotations"]- parameter_entry = parameters["default"]["parameters"]-- proceedToRecording = False # create this boolean, set it to false, and if the user wants to record- # later in the pipeline, it will be set to true-- # run the GUI to get the tasks, the cams chosen, the camera settings, and the session ID- task, cam_inputs, rotDict, paramDict, session.sessionID = recordGUI.RunGUI(- sessionID_in, rotation_entry, parameter_entry- )-- # update the saved parameters in the YAML- parameters["saved"]["rotations"] = rotDict- parameters["saved"]["parameters"] = paramDict- parameters_yaml.dump(parameters, parameter_path)-- # create a list from the rotation dictionary to be used in running webcams- rotation_input = list(rotDict.values())-- if task == "setup":- # run setup processes, and then check if th user wants to proceed to recording- camsetup.RunSetup(cam_inputs, rotation_input, paramDict)- proceedToRecording, session.sessionID = recordGUI.RunProceedtoRecordGUI(- sessionID_in- )-- elif task == "record":- proceedToRecording = True-- if proceedToRecording:- # create these session properties to be used later in the pipeline- session.cam_inputs = cam_inputs- session.parameterDictionary = paramDict- session.rotationInputs = rotation_input-- # create a config yaml and text file for this session- config_yaml_path = recordingconfig.createSession(session, filepath)- recordingconfig.createSessionTxt(session, paramDict, rotDict)-- print("Proceeding to Stage One")-- else:-- sys.exit("Recording Cancelled")- # %% Stage Two Initalization- if stage == 2:- session.sessionPath = (- filepath / "Data" / session.sessionID- ) # create a session path based on the sessionID-- # load the config yaml for this session, and add all the paths to the session file- session.yamlPath = session.sessionPath / "{}_config.yaml".format(- session.sessionID- )- session.config_settings = recordingconfig.load_config_yaml(- session.yamlPath- ) # config settings = paths and camera parameter inputs- recordingconfig.load_session_paths(- session, session.config_settings- ) # add paths to session class-- # from the config settings add the camera input parameters to parameter dictionary- session.parameterDictionary = session.config_settings["CamInputs"][- "ParameterDict"- ]- session.rotationInputs = session.config_settings["CamInputs"]["RotationInputs"]-- # initialize the path to the timestamp csv- csvName = session.sessionID + ".csv"- csvPath = session.sessionPath / csvName-- # read CSV data, turn it into a data frame- timeStampData = pd.read_csv(csvPath)- timeStampData = timeStampData.iloc[:, 1:]-- # get the camIDs and number of cameras (numCamRange) from the dataframe- camIDs = list(timeStampData.columns)- numCams = len(camIDs)- numCamRange = range(len(camIDs))-- # create names for each of the raw videos- vidNames = []- for x in numCamRange:- singleVidName = "raw_cam{}.mp4".format(x + 1)- vidNames.append(singleVidName)-- # initialize all the session variables we'll need to run the rest of the pipeline- session.timeStampData = timeStampData- session.camIDs = camIDs- session.numCamRange = numCamRange- session.vidNames = vidNames- session.numCams = numCams-- if stage == 3:-- session.sessionPath = (- filepath / "Data" / session.sessionID- ) # create a session path based on the sessionID-- # load the config yaml for this session, and add all the paths to the session file- session.yamlPath = session.sessionPath / "{}_config.yaml".format(- session.sessionID- )-- if (- session.yamlPath.is_file()- ): # if the config yaml exists (from a webcam recording)- session.config_settings = recordingconfig.load_config_yaml(- session.yamlPath- ) # config settings = paths and camera parameter inputs- recordingconfig.load_session_paths(- session, session.config_settings- ) # add paths to session class- else: # if it doesn't exist (because of a GoPro/external camera recording)- recordingconfig.createSession(session, filepath)-- if stage == 4:-- session.sessionPath = filepath / "Data" / session.sessionID-- session.yamlPath = session.sessionPath / "{}_config.yaml".format(- session.sessionID- ) # path to the configuration yaml- session.config_settings = recordingconfig.load_config_yaml(- session.yamlPath- ) # config settings = paths and camera parameter inputs- recordingconfig.load_session_paths(- session, session.config_settings- ) # add paths to session class-- for count, thisVidPath in enumerate(- session.syncedVidPath.glob("*.mp4"), start=1- ):- session.numCams = count-- if stage == 6:-- session.sessionPath = filepath / "Data" / session.sessionID-- session.yamlPath = session.sessionPath / "{}_config.yaml".format(- session.sessionID- ) # path to the configuration yaml- session.config_settings = recordingconfig.load_config_yaml(- session.yamlPath- ) # config settings = paths and camera parameter inputs- recordingconfig.load_session_paths(- session, session.config_settings- ) # add paths to session class-- if session.useOpenPose:- session.openPose_imgPathList = session.config_settings[- "openPose_imgPathList"- ]-- if session.useMediaPipe:- session.mediaPipe_imgPathList = session.config_settings[- "mediaPipe_imgPathList"- ]-- # if stage == 5:-- # session.sessionPath = filepath/'Data'/session.sessionID-- # session.yamlPath = session.sessionPath/'{}_config.yaml'.format(session.sessionID) #path to the configuration yaml- # session.config_settings = recordingconfig.load_config_yaml(session.yamlPath) #config settings = paths and camera parameter inputs- # recordingconfig.load_session_paths(session,session.config_settings) #add paths to session class-- # for count,thisVidPath in enumerate(session.syncedVidPath.glob('*.mp4'),start=1):- # session.numCams = count-- # session.mediaPipe_jsonPathList = session.config_settings['mediaPipe_jsonPathList']- # session.numCams = len(session.mediaPipe_jsonPathList)-- # if stage == 6:-- # session.sessionPath = filepath/'Data'/session.sessionID-- # session.yamlPath = session.sessionPath/'{}_config.yaml'.format(session.sessionID) #path to the configuration yaml- # session.config_settings = recordingconfig.load_config_yaml(session.yamlPath) #config settings = paths and camera parameter inputs- # recordingconfig.load_session_paths(session,session.config_settings) #add paths to session class-- # session.mediaPipeData_nCams_nFrames_nImgPts_XY = np.load(session.dataArrayPath/'mediaPipeData_nCams_nFrames_nImgPts_XY.npy')-- if stage == 7:-- session.sessionPath = filepath / "Data" / session.sessionID-- session.yamlPath = session.sessionPath / "{}_config.yaml".format(- session.sessionID- ) # path to the configuration yaml- session.config_settings = recordingconfig.load_config_yaml(- session.yamlPath- ) # config settings = paths and camera parameter inputs- recordingconfig.load_session_paths(- session, session.config_settings- ) # add paths to session class-- session.mediaPipe_imgPathList = session.config_settings["mediaPipe_imgPathList"]- session.openPose_imgPathList = session.config_settings["openPose_imgPathList"]-- # session.openPose_imgPathList = session.config_settings['openPose_imgPathList']- # session.numCams = len(session.openPose_imgPathList)-- if stage == 8:-- session.sessionPath = filepath / "Data" / session.sessionID-- session.yamlPath = session.sessionPath / "{}_config.yaml".format(- session.sessionID- ) # path to the configuration yaml- session.config_settings = recordingconfig.load_config_yaml(- session.yamlPath- ) # config settings = paths and camera parameter inputs- recordingconfig.load_session_paths(- session, session.config_settings- ) # add paths to session class---# %%diff --git a/freemocap/recordingconfig.py b/freemocap/recordingconfig.pyindex 30cb5bd0..2a7bf710 100644--- a/freemocap/recordingconfig.py+++ b/freemocap/recordingconfig.py@@ -6,78 +6,13 @@ Created on Thu Mar 11 11:54:12 2021"""-def createSession(session, filepath, existing_data=False):- # create file paths for the session, raw and synced videos-- pathList = []-- recordPath = filepath / "Data"- recordPath.mkdir(exist_ok=True)-- session.sessionPath = recordPath / session.sessionID- # if existing_data:- # session.sessionPath.mkdir(exist_ok = True)- # else:- session.sessionPath.mkdir(exist_ok=True)- pathList.append(session.sessionPath)-- session.rawVidPath = session.sessionPath / "RawVideos"- session.rawVidPath.mkdir(exist_ok=True)- pathList.append(session.rawVidPath)-- session.syncedVidPath = session.sessionPath / "SyncedVideos"- session.syncedVidPath.mkdir(exist_ok=True)- pathList.append(session.syncedVidPath)-- session.calVidPath = session.sessionPath / "CalVideos"- session.calVidPath.mkdir(exist_ok=True)- pathList.append(session.calVidPath)-- session.openPoseDataPath = session.sessionPath / "OpenPoseData"- session.openPoseDataPath.mkdir(exist_ok=True)- pathList.append(session.openPoseDataPath)-- session.mediaPipeDataPath = session.sessionPath / "MediaPipeData"- session.mediaPipeDataPath.mkdir(exist_ok=True)- pathList.append(session.mediaPipeDataPath)-- session.dlcDataPath = session.sessionPath / "DLCdata"- session.dlcDataPath.mkdir(exist_ok=True, parents=True)- pathList.append(session.dlcDataPath)-- session.imOutPath = session.sessionPath / "imOut"- session.imOutPath.mkdir(exist_ok=True)- pathList.append(session.imOutPath)-- session.dataArrayPath = session.sessionPath / "Data Arrays"- session.dataArrayPath.mkdir(exist_ok=True)- pathList.append(session.dataArrayPath)-- # create a list of paths that is passed to the recording script- # pathList = [session.sessionPath,session.rawVidPath,session.syncedVidPath,session.openPoseDataPath,session.dlcDataPath,session.imOutPath, session.dataArrayPath]-- config_settings, config_yaml = create_config_yaml()- session.config_settings = config_settings-- yaml_name = session.sessionPath / "{}_config.yaml".format(session.sessionID)- session.yamlPath = yaml_name- # print(yaml_name)- write_config_yaml(session, config_settings, config_yaml, pathList, yaml_name)-- return yaml_name---def createSessionTxt(session, paramDict, rotDict):- # create a text file listing recording parameters- parameter_text = session.sessionPath / "sessionSettings.txt"- text = open(parameter_text, "w")- text.write("Session ID = %s\n" % (session.sessionID))- text.write("%s = %s\n" % ("Parameters", paramDict))- text.write("%s = %s\n" % ("Rotations", rotDict))- text.close()folder_setup = ['RawVideos','SyncedVideos','CalVideos','DataArrays','DLCData','OpenPoseData','MediaPipeData','imOut']+default_parameters = {'rotations':{},'parameters':{'exposure':-5,'resWidth':640,'resHeight':480,'framerate':25,'codec':'DIVX'}}+saved_parameters = default_parameters+parameters_for_yaml = {'default':default_parameters,'saved':{}}+diff --git a/freemocap/webcamGUI.py b/freemocap/webcamGUI.pyindex 97188d0c..a91bae7e 100644--- a/freemocap/webcamGUI.py+++ b/freemocap/webcamGUI.py@@ -28,7 +28,13 @@ def initialize(session, stage, board):here = Path(__file__).parentparameter_path = here/'parameters.yaml'parameters_yaml = YAML()- parameters = parameters_yaml.load(parameter_path)+ if parameter_path.exists():+ parameters = parameters_yaml.load(parameter_path)+ else:+ parameters = recordingconfig.parameters_for_yaml+ with open(parameter_path,'w') as outfile:+ parameters_yaml.dump(parameters, outfile)+try:rotation_entry = parameters["saved"]["rotations"]