Free Motion Capture for Everyone πβ¨
TypeScript
reworking gopro/external recordings pipeline
aaroncherianc93170c00147
diff --git a/freemocap/fmc_openpose.py b/freemocap/fmc_openpose.pyindex fc71ab8d..cc387cd3 100644--- a/freemocap/fmc_openpose.py+++ b/freemocap/fmc_openpose.py@@ -28,7 +28,7 @@ def runOpenPose(session, runOpenPose=False):session.syncedVidPath.iterdir()): # Run OpenPose ('Windows Portable Demo') on each video in the raw video folderif (- thisVidPath.suffix == ".mp4"+ thisVidPath.suffix == ".mp4" or thisVidPath.suffix == ".MP4"): # NOTE - build some list of 'synced video names' and check against thatprint("OpenPosing: ", thisVidPath.name)vidPath = session.openPoseDataPath / thisVidPath.stem@@ -119,11 +119,11 @@ def parseOpenPose(session):#numFrames = int(len(list(Path(session.openPose_jsonPathList[0]).glob('*')))) #lolnumFrames = session.numFramesnumMarkers= int(int(len(dataFrameHeader)/3))- numCams = int(session.numCams)+ numCams = int(session.numCams) #rebuilding numCams here instead of using session.numCams in caseopenPoseData_nCams_nFrames_nImgPts_XYC = np.ndarray([numCams,numFrames,numMarkers,3]) #hardcoding for now because I am a bad person- for thisCams_JsonFolderPath in track(session.openPose_jsonPathList, description='Parsing json\'s into a dataframe (per cam)' ):+ for thisCams_JsonFolderPath in track(session.openPose_jsonPathList, description='Parsing json\'s intow a dataframe (per cam)' ):thisCamNum += 1# print('Parsing into a dataframe: ', thisCams_JsonFolderPath.name )jsonPaths = sorted(Path(thisCams_JsonFolderPath).glob('*.json')) #glob is a "generator(?)" for paths to all the jason for THIS camaradiff --git a/freemocap/session.py b/freemocap/session.pyindex 4d6128fb..5eceff83 100644--- a/freemocap/session.py+++ b/freemocap/session.py@@ -4,6 +4,8 @@ from ruamel.yaml import YAMLfrom freemocap import recordingconfigfrom freemocap.webcam import timesync+import cv2+class Session: #self like "recording self"def __init__(self):@@ -151,14 +153,55 @@ class Session: #self like "recording self"self.session_yaml_path = self.sessionPath/'{}_config.yaml'.format(self.sessionID)- if stage == 3:- #this is for the case of GoPro recordings/external recordings - if no config file exists, create one- if self.session_yaml_path.is_file():- self.session_settings = self.load_session()- else:- self.start_session({},{})- else:- self.session_settings = self.load_session()+ # if stage == 3:+ # #this is for the case of GoPro recordings/external recordings - if no config file exists, create one+ # if self.session_yaml_path.is_file():+ # self.session_settings = self.load_session()+ # else:+ # self.start_session({},{})+ # #run a check to make sure all the frame numbers are the same+ # a_sync_vid_path = list(self.syncedVidPath.glob('*.mp4'))+ # frames_per_cam = {}++ # for vid in a_sync_vid_path:+ # temp_cap = cv2.VideoCapture(str(vid))+ # thisCamFrames = temp_cap.get(cv2.CAP_PROP_FRAME_COUNT)+ # frames_per_cam[str(vid)] = thisCamFrames+ # temp_cap.release()+ # frame_check = len(list(set(list(frames_per_cam.values())))) == 1 # using set() to remove duplicates and check for values count+++ # if frame_check:+ # self.numFrames = int(thisCamFrames)+ # self.session_settings['recording_parameters'].update({'numFrames':self.numFrames})+ # self.numCams = len(a_sync_vid_path)+ # else:+ # print('The number of frames in each video are not equal. Frame counts are: ' + frames_per_cam)+ # else:+ # self.session_settings = self.load_session()++ if self.session_yaml_path.is_file():+ self.session_settings = self.load_session() #if a yaml exists, load it in (this is the case for a webcam recording, or an external recording that's been processed already)+ else: #if a session yaml doesn't exist, as is the case of an external recording+ self.start_session({},{})+ #run a check to make sure all the frame numbers are the same+ a_sync_vid_path = list(self.syncedVidPath.glob('*.mp4'))+ frames_per_cam = {}++ for vid in a_sync_vid_path:+ temp_cap = cv2.VideoCapture(str(vid))+ thisCamFrames = temp_cap.get(cv2.CAP_PROP_FRAME_COUNT)+ frames_per_cam[str(vid)] = thisCamFrames+ temp_cap.release()+ frame_check = len(list(set(list(frames_per_cam.values())))) == 1 # using set() to remove duplicates and check for values count+++ if frame_check:+ self.numFrames = int(thisCamFrames)+ self.session_settings['recording_parameters'].update({'numFrames':self.numFrames})+ self.numCams = len(a_sync_vid_path)+ else:+ raise ValueError('The number of frames in each video are not equal. Frame counts per video are are: ' + str(frames_per_cam))