Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

basic docstring commit

Aaron Cherian7882183c2833
diff --git a/freemocap/__init__.py b/freemocap/__init__.py
index cbdd4674..c8b040e8 100644
--- a/freemocap/__init__.py
+++ b/freemocap/__init__.py
@@ -6,9 +6,15 @@ del get_versions
from freemocap import fmc_runme, fmc_demo
def RunMe(sessionID=None,stage=1,useOpenPose=True, openPoseDummyRun = False, useMediaPipe=False,useDLC=False,dlcConfigPath=None,debug=False,setDataPath=False,userDataPath = None, recordVid=False):
+ """
+ Passes user-set values from the freemocap_runme_script to the fmc_runme.Run function (and allows the user to run the pipeline with just an fmc.RunMe command)
+ """
fmc_runme.Run(sessionID,stage,useOpenPose,openPoseDummyRun, useMediaPipe,useDLC,dlcConfigPath,debug,setDataPath,userDataPath,recordVid)
def RunDemo():
+ """
+ Will (eventually) download sample data from Figshare, and run the animation for it
+ """
sample_data_location = fmc_demo.DemoSetup() #run a bunch of GUIs, get the location of the directory where the data folder with the sample data is
fmc_runme.Run(sessionID = 'sesh_21-07-18_170130',stage = 6,useOpenPose = True,useDLC = True, userDataPath = sample_data_location)
diff --git a/freemocap/calibrate.py b/freemocap/calibrate.py
index 5e5ba186..599a6ccf 100644
--- a/freemocap/calibrate.py
+++ b/freemocap/calibrate.py
@@ -12,7 +12,11 @@ from rich.progress import track
def CalibrateCaptureVolume(session,board):
-
+ """
+ Check if a previous calibration yaml exists, and if not, create a set of shortened calibration videos and run Anipose functions
+ to create a calibration yaml. Takes the 2D charuco board points and reconstructs them into 3D points that are saved out
+ into the DataArrays folder
+ """
session.calVidPath.mkdir(exist_ok = True)
session.dataArrayPath.mkdir(exist_ok = True)
@@ -177,6 +181,10 @@ def CalibrateCaptureVolume(session,board):
def createCalibrationVideos(session, calVideoFrameLength):
+ """
+ Based on the desired length of the calibration videos (for the anipose functions), create new videos trimmed
+ to that specific length
+ """
vidList = os.listdir(session.syncedVidPath)
framelist = list(range(calVideoFrameLength))
codec = "DIVX"
diff --git a/freemocap/fmc_mediapipe.py b/freemocap/fmc_mediapipe.py
index bb8098bc..0d231127 100644
--- a/freemocap/fmc_mediapipe.py
+++ b/freemocap/fmc_mediapipe.py
@@ -14,6 +14,9 @@ mp_holistic = mp.solutions.holistic
def runMediaPipe(session, dummyRun=False):
+ """
+ Run MediaPipe on synced videos, and save body tracking data to be parsed
+ """
session.mediaPipeDataPath.mkdir(exist_ok = True)
@@ -154,6 +157,9 @@ def runMediaPipe(session, dummyRun=False):
def parseMediaPipe(session):
+ """
+ Parse through saved MediaPipe data, and save out a numpy array of 2D points
+ """
numCams = len(session.mediaPipeData) # Get number of cameras
numFrames = len(session.mediaPipeData[0]) # Get number of frames
# numBodyPoints = len(np.max(session.mediaPipeData[0][:].pose_landmarks.landmark[:]))#Get number of body points
@@ -298,6 +304,7 @@ def parseMediaPipe(session):
)
return mediaPipeData_nCams_nFrames_nImgPts_XYC
+
# #def parseMediaPipe2(session):
# #numCams = len(session.mediaPipeData) #Get number of cameras
diff --git a/freemocap/fmc_openpose.py b/freemocap/fmc_openpose.py
index e3ca8a2d..8a0b64ec 100644
--- a/freemocap/fmc_openpose.py
+++ b/freemocap/fmc_openpose.py
@@ -11,7 +11,9 @@ from pathlib import Path
def runOpenPose(session, dummyRun=False):
-
+ """
+ Run OpenPose on synced videos, and save bdoy tracking data to be parsed
+ """
if not dummyRun:
os.chdir(session.openPoseExePath)
@@ -79,84 +81,87 @@ def runOpenPose(session, dummyRun=False):
# @jit(nopython=True)
def parseOpenPose(session):
- thisCamNum = -1
+ """
+ Parse through saved OpenPose data and create a 2D numpy array of tracked body points
+ """
+ thisCamNum = -1
- ## %%
- #build header for dataframe - NOTE - #openpose data comes in a line ordered 'pixel x location (px)', 'pixel y (py)', 'confidence (conf)' for each keypoint
+ ## %%
+ #build header for dataframe - NOTE - #openpose data comes in a line ordered 'pixel x location (px)', 'pixel y (py)', 'confidence (conf)' for each keypoint
+
+ dataFrameHeader = []
+ bodyCols = 75
+ handCols = 63 #per hand
+ faceCols = 210 #das alotta face!
+ headerLength = bodyCols + 2*handCols + faceCols#should be 411 for whatever version of openpose i was using on 11 Jan 2021
+ numImgPoints = headerLength
+
+ for bb in range(0,int(bodyCols/3)): #loop through the number of body markers (i.e. #bodyCols/3)
+ dataFrameHeader.append('body_' + str(bb).zfill(3) + '_pixx')
+ dataFrameHeader.append('body_' + str(bb).zfill(3) + '_pixy')
+ dataFrameHeader.append('body_' + str(bb).zfill(3) + '_conf')
+
+ for hr in range(0,int(handCols/3)): #loop through the number of handR markers (i.e. #handCols/3)
+ dataFrameHeader.append('handR_' + str(hr).zfill(3) + '_pixx')
+ dataFrameHeader.append('handR_' + str(hr).zfill(3) + '_pixy')
+ dataFrameHeader.append('handR_' + str(hr).zfill(3) + '_conf')
+
+ for hl in range(0,int(handCols/3)): #loop through the number of handL markers (i.e. #handCols/3)
+ dataFrameHeader.append('handL_' + str(hl).zfill(3) + '_pixx')
+ dataFrameHeader.append('handL_' + str(hl).zfill(3) + '_pixy')
+ dataFrameHeader.append('handL_' + str(hl).zfill(3) + '_conf')
+
+ for ff in range(0,int(faceCols/3)): #loop through the number of Face markers (i.e. #faceCols/3)
+ dataFrameHeader.append('face_' + str(ff).zfill(3) + '_pixx')
+ dataFrameHeader.append('face_' + str(ff).zfill(3) + '_pixy')
+ dataFrameHeader.append('face_' + str(ff).zfill(3) + '_conf')
+
+ assert len(dataFrameHeader) == headerLength, ['Header is the wrong length! Should be ' + str(headerLength) + ' but it is ' + str(len(dataFrameHeader)) + ' Check version of OpenPose?']
+
+ ## %%
+ ## load in data from json files
+ #numFrames = int(len(list(Path(session.openPose_jsonPathList[0]).glob('*')))) #lol
+ numFrames = session.numFrames
+ numMarkers= int(int(len(dataFrameHeader)/3))
+ numCams = int(session.numCams)
+
+ openPoseData_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)' ):
+ 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 camara
- dataFrameHeader = []
- bodyCols = 75
- handCols = 63 #per hand
- faceCols = 210 #das alotta face!
- headerLength = bodyCols + 2*handCols + faceCols#should be 411 for whatever version of openpose i was using on 11 Jan 2021
- numImgPoints = headerLength
-
- for bb in range(0,int(bodyCols/3)): #loop through the number of body markers (i.e. #bodyCols/3)
- dataFrameHeader.append('body_' + str(bb).zfill(3) + '_pixx')
- dataFrameHeader.append('body_' + str(bb).zfill(3) + '_pixy')
- dataFrameHeader.append('body_' + str(bb).zfill(3) + '_conf')
-
- for hr in range(0,int(handCols/3)): #loop through the number of handR markers (i.e. #handCols/3)
- dataFrameHeader.append('handR_' + str(hr).zfill(3) + '_pixx')
- dataFrameHeader.append('handR_' + str(hr).zfill(3) + '_pixy')
- dataFrameHeader.append('handR_' + str(hr).zfill(3) + '_conf')
-
- for hl in range(0,int(handCols/3)): #loop through the number of handL markers (i.e. #handCols/3)
- dataFrameHeader.append('handL_' + str(hl).zfill(3) + '_pixx')
- dataFrameHeader.append('handL_' + str(hl).zfill(3) + '_pixy')
- dataFrameHeader.append('handL_' + str(hl).zfill(3) + '_conf')
-
- for ff in range(0,int(faceCols/3)): #loop through the number of Face markers (i.e. #faceCols/3)
- dataFrameHeader.append('face_' + str(ff).zfill(3) + '_pixx')
- dataFrameHeader.append('face_' + str(ff).zfill(3) + '_pixy')
- dataFrameHeader.append('face_' + str(ff).zfill(3) + '_conf')
-
- assert len(dataFrameHeader) == headerLength, ['Header is the wrong length! Should be ' + str(headerLength) + ' but it is ' + str(len(dataFrameHeader)) + ' Check version of OpenPose?']
-
- ## %%
- ## load in data from json files
- #numFrames = int(len(list(Path(session.openPose_jsonPathList[0]).glob('*')))) #lol
- numFrames = session.numFrames
- numMarkers= int(int(len(dataFrameHeader)/3))
- numCams = int(session.numCams)
-
- openPoseData_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)' ):
- 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 camara
+ for thisJsonPath in jsonPaths: #loop throug all the json files and save their 'people' data to a dictionary (which will then be formatted into a pandas dataframe). NOTE - will be empty array if no hoomans visible in frame
+ # print('loading: ', thisJsonPath.name)
+ frameNum = int(thisJsonPath.stem.split('_')[-2]) #frame number we're on
+ thisJsonData = json.loads(thisJsonPath.read_bytes())
+ thisJsonData = thisJsonData['people'] # #FEATURE_REQUEST - at some point, we should check the openpose version (save it with the data somehow, verify everything is the same version, use different markernamlists for different versions, etc)
+
+ if thisJsonData: #if this json has data
+ bodyData = np.array(thisJsonData[0]['pose_keypoints_2d'])
+ handRData = np.array(thisJsonData[0]['hand_right_keypoints_2d'])
+ handLData = np.array(thisJsonData[0]['hand_left_keypoints_2d'])
+ faceData = np.array(thisJsonData[0]['face_keypoints_2d'])
+ thisFrameRow = np.hstack((bodyData,handRData, handLData, faceData)) #horizontally concatenate these arrays
+ else: #if this json is empty, just stuff it fulla NaNs
+ thisFrameRow = np.empty([headerLength])
+ thisFrameRow.fill(np.nan)
+
+
+ assert thisFrameRow.size == headerLength, ['Header is the wrong length! Should be ' + str(headerLength) + ' but it is ' + str(thisFrameRow.size) + ' Check version of OpenPose?']
- for thisJsonPath in jsonPaths: #loop throug all the json files and save their 'people' data to a dictionary (which will then be formatted into a pandas dataframe). NOTE - will be empty array if no hoomans visible in frame
- # print('loading: ', thisJsonPath.name)
- frameNum = int(thisJsonPath.stem.split('_')[-2]) #frame number we're on
- thisJsonData = json.loads(thisJsonPath.read_bytes())
- thisJsonData = thisJsonData['people'] # #FEATURE_REQUEST - at some point, we should check the openpose version (save it with the data somehow, verify everything is the same version, use different markernamlists for different versions, etc)
-
- if thisJsonData: #if this json has data
- bodyData = np.array(thisJsonData[0]['pose_keypoints_2d'])
- handRData = np.array(thisJsonData[0]['hand_right_keypoints_2d'])
- handLData = np.array(thisJsonData[0]['hand_left_keypoints_2d'])
- faceData = np.array(thisJsonData[0]['face_keypoints_2d'])
- thisFrameRow = np.hstack((bodyData,handRData, handLData, faceData)) #horizontally concatenate these arrays
- else: #if this json is empty, just stuff it fulla NaNs
- thisFrameRow = np.empty([headerLength])
- thisFrameRow.fill(np.nan)
-
-
- assert thisFrameRow.size == headerLength, ['Header is the wrong length! Should be ' + str(headerLength) + ' but it is ' + str(thisFrameRow.size) + ' Check version of OpenPose?']
-
- if frameNum < openPoseData_nCams_nFrames_nImgPts_XYC.shape[1]: #NOTE: THIS SHOULDN"T BE NECESSARY. CURRENT Vid Trim Methods can (apparently) produce vids with off-by-one numbers of frames
- openPoseData_nCams_nFrames_nImgPts_XYC[thisCamNum, frameNum, :, :] = np.reshape(thisFrameRow, [137,3]) #hard coding the number of OpenPose Image Points b/c I'm a bad person
-
+ if frameNum < openPoseData_nCams_nFrames_nImgPts_XYC.shape[1]: #NOTE: THIS SHOULDN"T BE NECESSARY. CURRENT Vid Trim Methods can (apparently) produce vids with off-by-one numbers of frames
+ openPoseData_nCams_nFrames_nImgPts_XYC[thisCamNum, frameNum, :, :] = np.reshape(thisFrameRow, [137,3]) #hard coding the number of OpenPose Image Points b/c I'm a bad person
+
- # session.dataFrameHeader = dataFrameHeader
- # session.numImgPoints = numImgPoints
- #session.numFrames = frameNum #NOTE - Need to find a safer way to get this number
+ # session.dataFrameHeader = dataFrameHeader
+ # session.numImgPoints = numImgPoints
+ #session.numFrames = frameNum #NOTE - Need to find a safer way to get this number
- path_to_openpose_2d = session.dataArrayPath/'openPoseData_2d.npy'
- np.save(path_to_openpose_2d, openPoseData_nCams_nFrames_nImgPts_XYC)
+ path_to_openpose_2d = session.dataArrayPath/'openPoseData_2d.npy'
+ np.save(path_to_openpose_2d, openPoseData_nCams_nFrames_nImgPts_XYC)
- return openPoseData_nCams_nFrames_nImgPts_XYC
+ return openPoseData_nCams_nFrames_nImgPts_XYC
diff --git a/freemocap/fmc_runme.py b/freemocap/fmc_runme.py
index 8579814a..4e3513b0 100644
--- a/freemocap/fmc_runme.py
+++ b/freemocap/fmc_runme.py
@@ -36,6 +36,11 @@ def Run(sessionID=None,
setDataPath = False,
userDataPath = None,
recordVid = True,):
+ """
+ Starts the freemocap pipeline based on either user-input values, or default values. Creates a new session class instance (called sesh)
+ based on the specified inputs. Checks for previous user preferences and choices if they exist, or will prompt the user for new choices
+ if they don't. Runs the initialization for the system and runs each stage of the pipeline.
+ """
sesh = session.Session()
sesh.sessionID = sessionID
diff --git a/freemocap/reconstruct3D.py b/freemocap/reconstruct3D.py
index deeb552d..13e8232e 100644
--- a/freemocap/reconstruct3D.py
+++ b/freemocap/reconstruct3D.py
@@ -5,6 +5,9 @@ import numpy as np
# @jit(nopython=True)
def reconstruct3D(session, data_nCams_nFrames_nImgPts_XYC, confidenceThreshold=0.3):
+ """
+ Take a specifically formatted data array, and based on the camera calibration yaml, reconstruct a 3D image
+ """
if (
session.cgroup is None
diff --git a/freemocap/runcams.py b/freemocap/runcams.py
index dcb2feb7..5446d25c 100644
--- a/freemocap/runcams.py
+++ b/freemocap/runcams.py
@@ -9,6 +9,10 @@ from tkinter import Tk
def RecordCams(session,camInputs,parameterDictionary,rotationInputs):
+ """
+ Determines the number of cameras, assigns them IDs, and then starts a threaded cam recording process. Accesses the pickle file of timestamps
+ saved during recording, makes a dataframe from it and saves it to a CSV file. Updates the session class at the end with numCam variable
+ """
#Create RawVideos folder
session.rawVidPath.mkdir(exist_ok = True)
@@ -83,6 +87,10 @@ def RecordCams(session,camInputs,parameterDictionary,rotationInputs):
session.vidNames = vidNames
def SyncCams(session, timeStampData,numCamRange,vidNames,camIDs):
+ """
+ Runs the time-syncing process. Accesses saved timestamps, runs the time-syncing GUI, and on user-permission, proceeds to create
+ synced videos
+ """
session.syncedVidPath.mkdir(exist_ok = True)
#start the timesync process
diff --git a/freemocap/session.py b/freemocap/session.py
index f9b50a38..32728337 100644
--- a/freemocap/session.py
+++ b/freemocap/session.py
@@ -32,7 +32,10 @@ class Session: #self like "recording self"
self.openPose_imgPathList = None
def start_session(self,paramDict,rotDict):
- #start a session, create all the file paths necessary, and create a session dictionary to save settings
+ """
+ When starting a session from stage 1, create all the file paths necessary, and create a session dictionary to save settings.
+ Calls the create_session_paths and create_session_dictionary function
+ """
dataFolderPath = self.basePath/self.dataFolderName
dataFolderPath.mkdir(exist_ok= True)
@@ -49,9 +52,10 @@ class Session: #self like "recording self"
def create_session_paths(self):
- #creates Path objects to each folder created in a recording self and adds them all to the pathList variable
- #folders for these paths are created at the start of each stage where they are needed
-
+ """
+ Creates Path objects to each folder created in a recording self and adds them all to the pathList variable
+ folders for these paths are created at the start of each stage where they are needed
+ """
pathList = []
self.rawVidPath = self.sessionPath/'RawVideos'
@@ -81,7 +85,10 @@ class Session: #self like "recording self"
return pathList
def create_session_dictionary(self):
- #creates a dictionary of settings that should be saved into a YAML throughout each self
+ """
+ Creates a dictionary of settings that should be saved into a YAML through each session
+ """
+
recording_parameters = {'numCams': self.numCams, 'numFrames': self.numFrames, 'numTrackedPoints': self.numTrackedPoints}
@@ -99,7 +106,9 @@ class Session: #self like "recording self"
def create_session_txt(self,paramDict,rotDict):
- #create a text file listing recording parameters
+ """
+ Create a text file listing recording parameters
+ """
parameter_text = self.sessionPath/'sessionSettings.txt'
text = open(parameter_text, 'w')
text.write("Session ID = %s\n" %(self.sessionID))
@@ -108,10 +117,10 @@ class Session: #self like "recording self"
text.close()
def save_session(self):
- #save the self settings you want to keep from self to self into a yaml
- #because some items are not yaml-able, a copy of the sessionDictionary is made and adjusted to be fully yaml-able
- #Adjustments Made:
- #pathLib objects are all converted to strings
+ """
+ Save the settings needed to rerun the session at a later point into a dictionary, and then save it into a YAML
+ """
+
session_dictionary_to_save = self.session_settings
for key,value in session_dictionary_to_save['session_paths'].items():
@@ -127,6 +136,10 @@ class Session: #self like "recording self"
def initialize(self,stage):
+ """
+ When starting a session from Stage 3 onwards, modify the current session class instance with all necessary
+ attributes needed to run the rest of the pipeline
+ """
#load all session settings back into the session class for this run-through of the code
#recordPath = self.basePath/'Data' #create a Data folder in the filepath if none exists yet
@@ -150,6 +163,10 @@ class Session: #self like "recording self"
def load_session(self):
+ """
+ Called by the self.initialize function - reads the session yaml and loads the number of cameras and frames, and then
+ creates all necessary session paths
+ """
#session_yaml_path = self.sessionPath/'{}_config.yaml'.format(self.sessionID)
session_yaml = YAML(typ='safe', pure=True)
diff --git a/freemocap/webcam/camsetup.py b/freemocap/webcam/camsetup.py
index cc0e4d2c..591a00da 100644
--- a/freemocap/webcam/camsetup.py
+++ b/freemocap/webcam/camsetup.py
@@ -4,6 +4,9 @@ import imutils
class VideoSetup(threading.Thread):
+ """
+ Class to run and thread webcams for preview purposes
+ """
def __init__(self, camID, parameterDictionary, rotNum):
self.camID = camID
self.parameterDictionary = parameterDictionary
@@ -59,6 +62,9 @@ class VideoSetup(threading.Thread):
def RunSetup(cam_inputs, rotation_input, paramDict):
+ """
+ Start video setup by threading instances of the VideoSetup class
+ """
if not cam_inputs:
raise ValueError("Camera input list (cam_inputs) is empty")
diff --git a/freemocap/webcam/checkcams.py b/freemocap/webcam/checkcams.py
index dda1348c..6491a2fa 100644
--- a/freemocap/webcam/checkcams.py
+++ b/freemocap/webcam/checkcams.py
@@ -3,6 +3,9 @@ import cv2
def TestDevice(source):
+ """
+ Checks to see if there is a camera available at the input
+ """
cap = cv2.VideoCapture(source, cv2.CAP_DSHOW)
# if cap is None or not cap.isOpened():
# print('Warning: unable to open video source: ', source)
@@ -20,6 +23,9 @@ def TestDevice(source):
def CreateAvailableCamList():
+ """
+ Loops through the first 20 ports (this number is overkill, really) and creates a list of ports that have a camera available on them
+ """
openCamList = []
for x in tqdm(range(20)): # range 20 right now to be safe
openCamera = TestDevice(x)
diff --git a/freemocap/webcam/startcamrecording.py b/freemocap/webcam/startcamrecording.py
index a0cdec1e..a60a6fd5 100644
--- a/freemocap/webcam/startcamrecording.py
+++ b/freemocap/webcam/startcamrecording.py
@@ -37,6 +37,12 @@ class CamRecordingThread(threading.Thread):
def CamRecording(
session, camID, camInput, videoName, rawVidPath, beginTime, parameterDictionary
):
+ """
+ Runs the recording process for each threaded camera instance. Saves a video to the RawVideos folder.
+ Saves a timestamp for each frame into a pickle file. Checks for whether the global variable 'flag'
+ has been set to True to end the recording (the first camera to end sets the flag to True, which
+ means the rest of the cameras will quit in short order)
+ """
# the flag is triggered when the user shuts down one webcam to shut down the rest.
# normally I'd try to avoid global variables, but in this case it's
# necessary, since each webcam runs as it's own object.
diff --git a/freemocap/webcam/timesync.py b/freemocap/webcam/timesync.py
index 8f508af0..cca2b439 100644
--- a/freemocap/webcam/timesync.py
+++ b/freemocap/webcam/timesync.py
@@ -7,10 +7,20 @@ import tkinter as tk
from tkinter import Tk, Label, Button, Frame
def TimeSync(session,timeStampData,numCamRange,camNames):
-
+ """
+ First creates a master timeline from the average frame length interval across all cameras. Then proceeds to compare timepoints in master timeline
+ to timestamps in each camera and find the closest matching timestamp in a camera to a point on the master timeline and create a list of
+ frame numbers.
+
+ Then loop through the list of frame numbers from each camera. Update counts for missing frames and duplicated frames. Create a table with these counts
+ and plots of statistics related to the recording
+ """
def CloseNeighb(camera,point):
- closestPoint = (np.abs(camera - point)).argmin()
- return closestPoint
+ """
+ Find the timestamp in the camera timestamp list that most closely matches the input pointin the master timeline
+ """
+ closestPoint = (np.abs(camera - point)).argmin()
+ return closestPoint
# this section auto-finds the start and end points for our master timeline to the nearest second
masterTimelineBegin = np.ceil(max(timeStampData.iloc[0]))
@@ -96,8 +106,8 @@ def TimeSync(session,timeStampData,numCamRange,camNames):
#start counters for the number of buffered and deleted slides
- bufCount = 0;
- delCount = 0;
+ bufCount = 0
+ delCount = 0
thisCamNumFrames = len(camFrames)
postSyncTotalNumFrames.append(thisCamNumFrames)
@@ -194,6 +204,9 @@ def TimeSync(session,timeStampData,numCamRange,camNames):
class proceedGUI:
+ """
+ GUI that displays all statistics from recording, and then asks for user input on whether to proceed with the rest of the pipeline
+ """
def __init__(self, master, results, figure):
self.master = master
self.results = results
diff --git a/freemocap/webcam/videotrim.py b/freemocap/webcam/videotrim.py
index 9b5a82dc..3b4f42e8 100644
--- a/freemocap/webcam/videotrim.py
+++ b/freemocap/webcam/videotrim.py
@@ -6,6 +6,10 @@ import os
def VideoTrim(session, vidList, ft, parameterDictionary, rotationState, numCamRange):
+ """
+ From the list of saved frames from the time-syncing function, create synced videos by pulling those specific
+ frames from the original raw videos into new videos, replacing any duplicate frames with a black 'buffer' slide
+ """
camList = list(
ft.columns[1 : len(vidList) + 1]
) # grab the camera identifiers from the data frame
@@ -75,6 +79,7 @@ def VideoTrim(session, vidList, ft, parameterDictionary, rotationState, numCamRa
def createCalibrationVideos(session,calVideoFrameLength,parameterDictionary):
+
vidList = os.listdir(session.syncedVidPath)
framelist = list(range(calVideoFrameLength))
codec = parameterDictionary.get("codec")
diff --git a/freemocap/webcamGUI.py b/freemocap/webcamGUI.py
index 84b8703c..1a461071 100644
--- a/freemocap/webcamGUI.py
+++ b/freemocap/webcamGUI.py
@@ -10,6 +10,16 @@ from freemocap import recordingconfig, fmc_anipose
def initialize(session, stage, board):
+ """
+ Runs the initialization needed to either a) start a new recording from scratch (Stage 1), or b) continue a sesssion from stage 2 (time-syncing).
+
+ If running from stage 1: create a new sessionID and attempt to load previous recording parameters (camera settings/rotations/save locations),
+ and use default values if previous parameters are not found. Ask user to select preferences using a series of GUIs, runs the Setup option if
+ chosen by the user, and ultimately sets a bool that dictates whether we should proceed to start the actual Stage 1 recording. Also saves parameters
+ into the session class, which gets saved into the user_preferences yaml
+
+ If running from stage 2: loads the timestamps and reads them into a dataframe, and sets up all the parameters necesary to run the pipeline
+ """
print("Starting initialization for stage {}".format(stage))
# if stage == 1:
@@ -150,129 +160,129 @@ def initialize(session, stage, board):
session.vidNames = vidNames
session.numCams = numCams
- if stage == 3:
+# if stage == 3:
- session.sessionPath = (
- filepath / "Data" / session.sessionID
- ) # create a session path based on the sessionID
+# 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
- )
+# # 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:
+# 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.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.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
+# for count, thisVidPath in enumerate(
+# session.syncedVidPath.glob("*.mp4"), start=1
+# ):
+# session.numCams = count
- if stage == 6:
+# if stage == 6:
- session.sessionPath = filepath / "Data" / session.sessionID
+# 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.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.useOpenPose:
+# session.openPose_imgPathList = session.config_settings[
+# "openPose_imgPathList"
+# ]
- if session.useMediaPipe:
- session.mediaPipe_imgPathList = session.config_settings[
- "mediaPipe_imgPathList"
- ]
+# if session.useMediaPipe:
+# session.mediaPipe_imgPathList = session.config_settings[
+# "mediaPipe_imgPathList"
+# ]
- # if stage == 5:
+# # if stage == 5:
- # session.sessionPath = filepath/'Data'/session.sessionID
+# # 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.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
+# # 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)
+# # session.mediaPipe_jsonPathList = session.config_settings['mediaPipe_jsonPathList']
+# # session.numCams = len(session.mediaPipe_jsonPathList)
- # if stage == 6:
+# # if stage == 6:
- # session.sessionPath = filepath/'Data'/session.sessionID
+# # 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.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')
+# # session.mediaPipeData_nCams_nFrames_nImgPts_XY = np.load(session.dataArrayPath/'mediaPipeData_nCams_nFrames_nImgPts_XY.npy')
- if stage == 7:
+# if stage == 7:
- session.sessionPath = filepath / "Data" / session.sessionID
+# 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.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)
+# 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:
+# if stage == 8:
- session.sessionPath = filepath / "Data" / session.sessionID
+# 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.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_runme_script (DESKTOP-5BEPF2F's conflicted copy 2021-07-20).py b/freemocap_runme_script (DESKTOP-5BEPF2F's conflicted copy 2021-07-20).py
deleted file mode 100644
index 48cdd35c..00000000
--- a/freemocap_runme_script (DESKTOP-5BEPF2F's conflicted copy 2021-07-20).py
+++ /dev/null
@@ -1,10 +0,0 @@
-import freemocap as fmc
-from pathlib import Path
-import socket
-
-dlcConfigPath = Path(r"C:\Users\jonma\Dropbox\DLC_Models\PinkGreenRedJugglingBalls-JSM-2021-05-31\config.yaml")
-
-if socket.gethostname() == 'DESKTOP-DCG6K4F':
- fmc.RunMe( sessionID='sesh_21-07-19_231345', stage=7, openPoseDummyRun=True, useDLC = True, dlcConfigPath=dlcConfigPath, recordVid = False)
-else:
- fmc.RunMe( stage = 7, useDLC = True, dlcConfigPath=dlcConfigPath, recordVid = False)