Free Motion Capture for Everyone πβ¨
TypeScript
unix_timestamp output (unsynced)
aaroncherianb14752324ef6
diff --git a/freemocap/runcams.py b/freemocap/runcams.pyindex 5446d25c..99e2c4f7 100644--- a/freemocap/runcams.py+++ b/freemocap/runcams.py@@ -22,11 +22,16 @@ def RecordCams(session,camInputs,parameterDictionary,rotationInputs):numCamRange = range(numCams) # a range for the number of cameras that we havevidNames = []camIDs = []+ unix_camIDs = []for x in numCamRange: # create names for each of the initial untrimmed videossingleCamID = "Cam{}".format(x + 1)camIDs.append(singleCamID) # creates IDs for each camera based on the number of cameras entered++ unix_camID = singleCamID + '_unix_timestamps'+ unix_camIDs.append(unix_camID)+singleVidName = "raw_cam{}.mp4".format(x + 1)vidNames.append(singleVidName)@@ -36,6 +41,7 @@ def RecordCams(session,camInputs,parameterDictionary,rotationInputs):camRecordings = startcamrecording.CamRecordingThread(session,camIDs[n],+ unix_camIDs[n],camInputs[n],vidNames[n],session.rawVidPath,@@ -52,6 +58,7 @@ def RecordCams(session,camInputs,parameterDictionary,rotationInputs):print("finished recordings")timeStampList = []+ unix_timeStampList = []for (e@@ -61,8 +68,12 @@ def RecordCams(session,camInputs,parameterDictionary,rotationInputs):with open(session.rawVidPath/camIDs[e], "rb") as f:camTimeList = pickle.load(f)timeStampList.append(camTimeList)+ with open(session.rawVidPath/unix_camIDs[e], "rb") as g:+ unix_camTimeList = pickle.load(g)+ unix_timeStampList.append(unix_camTimeList)- timeDictionary = {}+ timeDictionary = {}+ unix_timeDictionary = {}id_and_time = zip(camIDs, timeStampList)@@ -70,7 +81,6 @@ def RecordCams(session,camInputs,parameterDictionary,rotationInputs):timeDictionary[cam] = np.array(data) # create a dictionary that holds the timestamps for each camera-df = pd.DataFrame.from_dict(timeDictionary, orient="index") # create a data frame from this dictionary@@ -79,6 +89,18 @@ def RecordCams(session,camInputs,parameterDictionary,rotationInputs):csvPath = session.rawVidPath / csvNametimeStampData.to_csv(csvPath) # turn dataframe into a CSV+ id_and_unix_time = zip(unix_camIDs,unix_timeStampList)++ for cam_unix, data_unix in id_and_unix_time:+ unix_timeDictionary[cam_unix] = np.array(data_unix)+ df_unix = pd.DataFrame.from_dict(+ unix_timeDictionary, orient="index"+ ) # create a data frame from this dictionary+ unix_timeStampData = df_unix.transpose()+ unix_csvName = session.sessionID + "_unix_timestamps.csv"+ unix_csvPath = session.rawVidPath / unix_csvName+ unix_timeStampData.to_csv(unix_csvPath)+session.numCams = numCamssession.session_settings['recording_parameters'].update({'numCams':session.numCams})session.timeStampData = timeStampDatadiff --git a/freemocap/webcam/startcamrecording.py b/freemocap/webcam/startcamrecording.pyindex cd7746ce..4b90a907 100644--- a/freemocap/webcam/startcamrecording.py+++ b/freemocap/webcam/startcamrecording.py@@ -7,10 +7,11 @@ import platformclass CamRecordingThread(threading.Thread):def __init__(- self, session, camID, camInput, videoName, rawVidPath, beginTime, parameterDictionary+ self, session, camID, unix_camID, camInput, videoName, rawVidPath, beginTime, parameterDictionary):threading.Thread.__init__(self)self.camID = camID+ self.unix_camID = unix_camIDself.camInput = camInputself.videoName = videoNameself.rawVidPath = rawVidPath@@ -23,6 +24,7 @@ class CamRecordingThread(threading.Thread):self.timeStamps = CamRecording(self.session,self.camID,+ self.unix_camID,self.camInput,self.videoName,self.rawVidPath,@@ -36,7 +38,7 @@ class CamRecordingThread(threading.Thread):# the recording function that each threaded camera object runsdef CamRecording(- session, camID, camInput, videoName, rawVidPath, beginTime, parameterDictionary+ session, camID, unix_camID, camInput, videoName, rawVidPath, beginTime, parameterDictionary):"""Runs the recording process for each threaded camera instance. Saves a video to the RawVideos folder.@@ -80,20 +82,25 @@ def CamRecording(width = cam.get(cv2.CAP_PROP_FRAME_WIDTH)height = cam.get(cv2.CAP_PROP_FRAME_HEIGHT)print("width:", width, "height:", height)- saveRawVidPath = str( rawVidPath / videoName) # create a save path for each video to the RawVideos folders+ saveRawVidPath = str(rawVidPath / videoName) # create a save path for each video to the RawVideos foldersout = cv2.VideoWriter(saveRawVidPath, fourcc, framerate, (resWidth, resHeight))timeStamps = [] # holds the timestamps+ timeStamps_unix = []+if cam.isOpened():success, frame = cam.read()else:success = False- while ( success): # while the camera is opened, record the data until the escape button is hit+ while (success): # while the camera is opened, record the data until the escape button is hitif flag: # when the flag is triggered, stop recording and dump the datawith open(session.rawVidPath/camID, "wb") as f:pickle.dump(timeStamps, f)++ with open(session.rawVidPath/unix_camID,"wb") as g:+ pickle.dump(timeStamps_unix,g)breaksuccess, frame = cam.read()@@ -102,15 +109,18 @@ def CamRecording(frame_sized = frameout.write(frame)timeStamps.append(time.time() - beginTime) # add each timestamp to the list+ timeStamps_unix.append(time.time())key = cv2.waitKey(20)if key == 27: # exit on ESCflag = True # set flag to true to shut down all other webcamswith open(session.rawVidPath/camID, "wb") as f:pickle.dump(timeStamps, f) # dump the data+ with open(session.rawVidPath/unix_camID,"wb") as g:+ pickle.dump(timeStamps_unix,g)breakcv2.destroyWindow(camWindowName)- return timeStamps+ return timeStamps,timeStamps_unix# this is how we sync our time frames, based on our recorded timestampsdiff --git a/freemocap_runme_script.py b/freemocap_runme_script.pyindex 104eb169..7dca6e23 100644--- a/freemocap_runme_script.py+++ b/freemocap_runme_script.py@@ -1,3 +1,3 @@import freemocap as fmc-fmc.RunMe()+fmc.RunMe(stage=2)