Skip to content

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

TypeScript

get_synced_unix_timestamps flag added, blender bug fixed

aaroncherian7e8d822e0965
diff --git a/freemocap/fmc_runme.py b/freemocap/fmc_runme.py
index 8e30012f..5fc27094 100644
--- a/freemocap/fmc_runme.py
+++ b/freemocap/fmc_runme.py
@@ -62,6 +62,7 @@ def RunMe(sessionID=None,
startFrame = 0,
useBlender = False,
resetBlenderExe = False,
+ get_synced_unix_timestamps = False,
):
"""
Starts the freemocap pipeline based on either user-input values, or default values. Creates a new session class instance (called sesh)
@@ -83,6 +84,7 @@ def RunMe(sessionID=None,
sesh.userDataPath = userDataPath
sesh.dataFolderName = recordingconfig.dataFolder
sesh.startFrame = startFrame
+ sesh.get_synced_unix_timestamps = get_synced_unix_timestamps
# %% Startup
startup.get_user_preferences(sesh,stage)
@@ -302,11 +304,11 @@ def RunMe(sessionID=None,
#blenderPath = Path('C:\Program Files\Blender Foundation\Blender 2.93')
#os.chdir(blenderExePath)
- path_to_this_py_file = Path(__file__).parent.resolve()
- fmc_blender_script_path = path_to_this_py_file /'fmc_blender.py'
- with console.status('Stuffing data into a Blender scene...'):
- output = subprocess.run([str(blenderPath), "--background", "--python", str(fmc_blender_script_path), "--", str(sesh.dataArrayPath/'mediaPipeSkel_3d_smoothed.npy'), str(sesh.dataArrayPath), sesh.sessionID], capture_output=True, text=True, check=True)
- print(output)
+ path_to_this_py_file = Path(__file__).parent.resolve()
+ fmc_blender_script_path = path_to_this_py_file /'fmc_blender.py'
+ with console.status('Stuffing data into a Blender scene...'):
+ output = subprocess.run([str(blenderPath), "--background", "--python", str(fmc_blender_script_path), "--", str(sesh.dataArrayPath/'mediaPipeSkel_3d_smoothed.npy'), str(sesh.dataArrayPath), sesh.sessionID], capture_output=True, text=True, check=True)
+ print(output)
except:
console.print_exception()
diff --git a/freemocap/runcams.py b/freemocap/runcams.py
index 99e2c4f7..4d25c2d7 100644
--- a/freemocap/runcams.py
+++ b/freemocap/runcams.py
@@ -18,6 +18,7 @@ def RecordCams(session,camInputs,parameterDictionary,rotationInputs):
#%% Setting up recordings
beginTime = time.time()
+ session.beginTime = beginTime
numCams = len(camInputs) # number of cameras
numCamRange = range(numCams) # a range for the number of cameras that we have
vidNames = []
@@ -107,6 +108,7 @@ def RecordCams(session,camInputs,parameterDictionary,rotationInputs):
session.camIDs = camIDs
session.numCamRange = numCamRange
session.vidNames = vidNames
+
def SyncCams(session, timeStampData,numCamRange,vidNames,camIDs):
"""
@@ -116,7 +118,7 @@ def SyncCams(session, timeStampData,numCamRange,vidNames,camIDs):
session.syncedVidPath.mkdir(exist_ok = True)
#start the timesync process
- frameTable,timeTable,frameRate,resultsTable,plots = timesync.TimeSync(session,timeStampData,numCamRange,camIDs)
+ frameTable,timeTable,unix_synced_timeTable,frameRate,resultsTable,plots = timesync.TimeSync(session,timeStampData,numCamRange,camIDs)
#this message shows you your percentages and asks if you would like to continue or not. shuts down the program if no
root = Tk()
@@ -125,6 +127,11 @@ def SyncCams(session, timeStampData,numCamRange,vidNames,camIDs):
) # create a GUI instance called proceed
root.mainloop()
+ if session.get_synced_unix_timestamps == True:
+ unix_synced_timestamps_csvName = 'unix_synced_timestamps.csv'
+ unix_synced_timestamps_csvPath = session.sessionPath/unix_synced_timestamps_csvName
+ unix_synced_timeTable.to_csv(unix_synced_timestamps_csvPath)
+
if proceed.proceed == True:
print()
print('Starting editing')
@@ -132,3 +139,4 @@ def SyncCams(session, timeStampData,numCamRange,vidNames,camIDs):
session.session_settings['recording_parameters'].update({'numFrames':session.numFrames})
#videotrim.createCalibrationVideos(session,60,parameterDictionary)
print('all done')
+
diff --git a/freemocap/webcam/startcamrecording.py b/freemocap/webcam/startcamrecording.py
index 4b90a907..5b9594cf 100644
--- a/freemocap/webcam/startcamrecording.py
+++ b/freemocap/webcam/startcamrecording.py
@@ -87,7 +87,7 @@ def CamRecording(
out = cv2.VideoWriter(saveRawVidPath, fourcc, framerate, (resWidth, resHeight))
timeStamps = [] # holds the timestamps
timeStamps_unix = []
-
+ timeStamps_unix.append(beginTime) #the first timestamp for each camera in the unix CSV will always be the begin time
if cam.isOpened():
success, frame = cam.read()
diff --git a/freemocap/webcam/timesync.py b/freemocap/webcam/timesync.py
index 495e42a4..6ca3cf67 100644
--- a/freemocap/webcam/timesync.py
+++ b/freemocap/webcam/timesync.py
@@ -71,7 +71,8 @@ def TimeSync(session,timeStampData,numCamRange,camNames):
frameList = masterTimeline #start a list of frames, with the first row being our master timeline
timeList = masterTimeline #start a list of timestamps,with the first row being our master timeline
-
+
+ unix_converted_timeList = range(len(masterTimeline)) #keep a record of unix timestamps before they're normalized to fit the master timeline
delNum= []; #stores number of deleted frames/camera
bufNum= []; #stores number of buffered frames/camera
bufPercentList = []; #stores percentage of deleted frames/camera
@@ -85,6 +86,7 @@ def TimeSync(session,timeStampData,numCamRange,camNames):
for y in numCamRange:
thisCam = timeStampData[camNames[y]]
camTimes = []
+ original_camTimes = []
# stored times
camFrames = []
# stored frames
@@ -104,6 +106,14 @@ def TimeSync(session,timeStampData,numCamRange,camNames):
frameList = np.column_stack((frameList,camFrames)) #update our framelist with our new frames
timeList = np.column_stack((timeList,camTimes)) #update our timelist
+ original_camTimes = camTimes - timeDif
+ if session.get_synced_unix_timestamps == True: #this is bad coding please forgive me -
+ unix_converted_original_camTimes = original_camTimes + session.beginTime
+ unix_converted_timeList = np.column_stack((unix_converted_timeList,unix_converted_original_camTimes))
+ else:
+ unix_converted_original_camTimes = original_camTimes
+ unix_converted_timeList = np.column_stack((unix_converted_timeList,unix_converted_original_camTimes))
+
#start counters for the number of buffered and deleted slides
bufCount = 0
@@ -125,9 +135,11 @@ def TimeSync(session,timeStampData,numCamRange,camNames):
if frame1 > frame2:
frameList[i, count] = -1
timeList[i, count] = -1
+ unix_converted_timeList[i,count] = -1
else:
frameList[i + 1, count] = -1
timeList[i + 1, count] = -1
+ unix_converted_timeList[i+1,count] = -1
elif distanceBetweenFrames > 1: # deletion
delCount += 1
else:
@@ -158,6 +170,11 @@ def TimeSync(session,timeStampData,numCamRange,camNames):
frameTable.columns = columnNames
timeTable = pd.DataFrame(timeList)
timeTable.columns = columnNames
+
+ unix_synced_timeTable = pd.DataFrame(unix_converted_timeList)
+ unix_synced_table_columnNames = ['Frame'] + camNames
+ unix_synced_timeTable.columns = unix_synced_table_columnNames
+
totalFrameRate = [round(1 / intvl, 1) for intvl in totalFrameIntvl]
frameRate = 1 / totalAverageIntvl # calculates our framerate
results = {
@@ -197,7 +214,7 @@ def TimeSync(session,timeStampData,numCamRange,camNames):
fpsFrame.plot.hist(
ax=d, bins=6, alpha=0.5, xlim=[0, 40], title="Frames per second distribution"
)
- return frameTable, timeTable, frameRate, resultTable, fig
+ return frameTable, timeTable, unix_synced_timeTable,frameRate, resultTable, fig
# function to trim our videos
@@ -267,10 +284,18 @@ def time_sync_initialize(session):
singleVidName = 'raw_cam{}.mp4'.format(x+1)
vidNames.append(singleVidName)
-
+ if session.get_synced_unix_timestamps == True:
+ unix_timestamp_csvName = session.sessionID + "_unix_timestamps.csv"
+ unixTimeStampDataPath = session.rawVidPath/unix_timestamp_csvName
+ cam_to_search_for_begin_time = camIDs[0] + '_unix_timestamps'
+ unix_timestamp_data = pd.read_csv(unixTimeStampDataPath)
+ unix_timestamp_data = unix_timestamp_data.iloc[:,1:]
+ beginTime = unix_timestamp_data[cam_to_search_for_begin_time][0]
+ session.beginTime = beginTime
#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
+