Skip to content

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

TypeScript

Adding demo stuff

Aaron Cherian3b368ba3f73a
diff --git a/freemocap/__init__.py b/freemocap/__init__.py
index 1327aaae..e548ba77 100644
--- a/freemocap/__init__.py
+++ b/freemocap/__init__.py
@@ -3,7 +3,11 @@ from ._version import get_versions
__version__ = get_versions()["version"]
del get_versions
-from freemocap import fmc_runme
+from freemocap import fmc_runme, fmc_demo
-def RunMe(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,dlcConfigPath=None,debug=False,setDataPath=False):
- fmc_runme.Run(sessionID,stage,useOpenPose,useMediaPipe,useDLC,dlcConfigPath,debug,setDataPath)
\ No newline at end of file
+def RunMe(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,dlcConfigPath=None,debug=False,setDataPath=False,userDataPath = None):
+ fmc_runme.Run(sessionID,stage,useOpenPose,useMediaPipe,useDLC,dlcConfigPath,debug,setDataPath,userDataPath)
+
+def RunDemo():
+ 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)
\ No newline at end of file
diff --git a/freemocap/fmc_demo.py b/freemocap/fmc_demo.py
new file mode 100644
index 00000000..24054921
--- /dev/null
+++ b/freemocap/fmc_demo.py
@@ -0,0 +1,132 @@
+from freemocap import fmc_runme,recordingconfig
+
+import zipfile
+from pathlib import Path
+import tkinter as tk
+from tkinter import Tk, Label, Button, Frame, Listbox, Entry, filedialog
+
+def DemoSetup():
+
+
+ download_data = runDataDownloadGUI() #ask for user input on downloading
+
+ if download_data: #if they want to download
+ #code to download stuff from online will go here
+
+
+ #run the GUI to get the directory locations of the zipped folder, and where to extract it to
+ locationPath, destinationPath = runDemoGUI()
+ zipPath = Path(locationPath)/'sesh_21-07-18_170130.zip' #append the name of the zipped sample file to the path to find it
+ extractToPath = Path(destinationPath)/recordingconfig.dataFolder #append the name of the data folder to the destination path
+ extractToPath.mkdir(exist_ok=True) #make the data folder if it doesn't current exist
+
+ with zipfile.ZipFile(zipPath,'r') as zip_ref:
+ zip_ref.extractall(extractToPath) #extract stuff to the data folder
+ else:
+ root = tk.Tk() #brinng up a window to select the data folder directory
+ root.withdraw()
+ destinationPath = filedialog.askdirectory( title='Select the directory where the Freemocap_data folder with the sample data is located',
+ initialdir= Path.cwd())
+
+
+ return destinationPath #take the path to the directory where the data folder is located
+
+class DemoGUI(): #GUI to pick the location and the destination directories for the sample data
+ def __init__(self, master):
+ self.master = master
+
+ dataText = "Select the directory where your sample data is located"
+ dataLable = Label(master, text=dataText)
+ dataLable.pack(side="top")
+
+ self.locationPathVar = tk.StringVar()
+ savedLocationLabel = Label(master,textvariable=self.locationPathVar)
+ savedLocationLabel.pack()
+
+ dataButton = Button(master,text = 'Select the current sample data location',command = self.openLocationDialog)
+ dataButton.pack()
+
+ sampleDestinationText = "If a {} folder already exists, choose the directory where it is located. \n Otherwise, choose a directory to create a {} folder".format(recordingconfig.dataFolder,recordingconfig.dataFolder)
+ sampleDestinationLabel = Label(master, text=sampleDestinationText)
+ sampleDestinationLabel.pack()
+
+ self.destinationPathVar = tk.StringVar()
+ savedDestinationLabel = Label(master,textvariable=self.destinationPathVar)
+ savedDestinationLabel.pack()
+
+ sampleDestinationButton = Button(master,text = 'Select the sample data destination',command = self.openDestinationDialog)
+ sampleDestinationButton.pack()
+
+ submitButton = Button(master,text = 'Submit',command = self.submit)
+ submitButton.pack()
+
+ def openLocationDialog(self):
+
+ self.locationPath = filedialog.askdirectory(
+ title='Select the directory where the sample data zip file is located',
+ initialdir= Path.cwd())
+
+ self.locationPathVar.set(self.locationPath)
+ f = 2
+
+ def openDestinationDialog(self):
+
+ self.destinationPath = filedialog.askdirectory(
+ title='Select the directory where the freemocap data is located or should be created',
+ initialdir= Path.cwd())
+ f = 2
+
+ self.destinationPathVar.set(self.destinationPath)
+
+ def submit(self):
+ self.master.destroy()
+
+
+ def getLocationPath(self):
+ return self.locationPath
+
+ def getDestinationPath(self):
+ return self.destinationPath
+
+class dataDownloadGUI(): #GUI to ask whether users want to download data
+ def __init__(self, master):
+ self.master = master
+
+ dataText = "Would you like to download sample data?"
+ dataLable = Label(master, text=dataText)
+ dataLable.pack(side="top")
+
+ yesButton = Button(master,text = 'Yes',command = self.yes)
+ yesButton.pack()
+
+ noButton = Button(master,text = 'No',command = self.no)
+ noButton.pack()
+
+ def yes(self):
+ self.download_sample_data = True
+ self.master.destroy()
+
+
+ def no(self):
+ self.download_sample_data = False
+ self.master.destroy()
+
+
+def runDemoGUI():
+ root = tk.Tk()
+ pathchoices = DemoGUI(root)
+ root.mainloop()
+
+ locationPath = pathchoices.locationPath
+ destinationPath = pathchoices.destinationPath
+
+ return locationPath,destinationPath
+
+def runDataDownloadGUI():
+ root = tk.Tk()
+ download_options = dataDownloadGUI(root)
+ root.mainloop()
+
+ return download_options.download_sample_data
+
+
diff --git a/freemocap/fmc_runme.py b/freemocap/fmc_runme.py
index ffb437c6..e8614883 100644
--- a/freemocap/fmc_runme.py
+++ b/freemocap/fmc_runme.py
@@ -23,7 +23,7 @@ import numpy as np
from ruamel.yaml import YAML
-def Run(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,dlcConfigPath=None,debug=False,setDataPath=False):
+def Run(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,dlcConfigPath=None,debug=False,setDataPath=False,userDataPath = None):
sesh = session.Session()
sesh.sessionID = sessionID
@@ -32,10 +32,10 @@ def Run(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,d
sesh.useDLC= useDLC
sesh.debug = debug
sesh.setDataPath = setDataPath
+ sesh.userDataPath = userDataPath
+ sesh.dataFolderName = recordingconfig.dataFolder
- sesh.dataFolderName = 'FreeMocap_Data'
-
- if sesh.useDLC:
+ if sesh.useDLC and stage < 5:
import deeplabcut as dlc
# sesh.dlcConfigPath = dlcConfigPath
@@ -54,7 +54,7 @@ def Run(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,d
sesh.preferences = preferences
sesh.preferences_path = preferences_path
- if sesh.useDLC:
+ if sesh.useDLC and stage < 5:
try:
saved_dlc_paths = preferences['saved']['dlc_config_paths']
except:
@@ -79,6 +79,8 @@ def Run(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,d
if sesh.setDataPath == True:
basePath = runmeGUI.RunChooseDataPathGUI(session)
#sesh.dataFolderPath = Path(basePath)/sesh.dataFolderName
+ elif sesh.userDataPath is not None:
+ basePath = sesh.userDataPath
else:
try:
current_path_to_data = preferences['saved']['path_to_save']
@@ -232,7 +234,7 @@ def Run(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,d
# %% Stage Six
if stage <= 6:
print ('Starting PyQT Animation')
- createvideo.createBodyTrackingVideos(sesh)
+ #createvideo.createBodyTrackingVideos(sesh)
displayVid = 1
#if displayVid = 0, will show the synced videos
#if displayVid = 1, will show the openPosed videos
@@ -244,7 +246,7 @@ def Run(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,d
print('Starting Skeleton Plotting')
playskeleton.ReplaySkeleton_matplotlib(
sesh,
- vidType=1,
+ vidType=0,
startFrame=40,
azimuth=-90,
elevation=-80,
diff --git a/freemocap/playskeleton.py b/freemocap/playskeleton.py
index 8d00cdd4..346ab2d4 100644
--- a/freemocap/playskeleton.py
+++ b/freemocap/playskeleton.py
@@ -56,7 +56,8 @@ def ReplaySkeleton_matplotlib(
ballTrailLen = 4
if useOpenPose:
- imgPathList = session.session_settings['openPose_imgPathList']
+ for camera_number in range(session.numCams):
+ imgPathList = session.session_settings['openPose_imgPathList']
camImgPathList = {}
diff --git a/freemocap/recordingconfig.py b/freemocap/recordingconfig.py
index ead7102b..540feaa4 100644
--- a/freemocap/recordingconfig.py
+++ b/freemocap/recordingconfig.py
@@ -7,6 +7,8 @@ Created on Thu Mar 11 11:54:12 2021
from pathlib import Path
+dataFolder = 'FreeMocap_Data'
+
folder_setup = ['RawVideos','SyncedVideos','CalVideos','DataArrays','DLCData','OpenPoseData','MediaPipeData','imOut']
default_parameters = {'path_to_save': str(Path.cwd()),'dlc_config_paths':[], 'rotations':{},'parameters':{'exposure':-5,'resWidth':640,'resHeight':480,'framerate':25,'codec':'DIVX'}}
diff --git a/freemocap/session.py b/freemocap/session.py
index abc75d6f..e4c8b86a 100644
--- a/freemocap/session.py
+++ b/freemocap/session.py
@@ -162,7 +162,8 @@ class Session: #self like "recording self"
for key,value in session_settings_dictionary['session_paths'].items():
session_settings_dictionary['session_paths'][key] = Path(value)
- self.load_session_paths(session_settings_dictionary)
+ #self.load_session_paths(session_settings_dictionary)
+ self.create_session_paths()
self.numCams = session_settings_dictionary['recording_parameters']['numCams']
self.numFrames = session_settings_dictionary['recording_parameters']['numFrames']
self.numTrackedPoints = session_settings_dictionary['recording_parameters']['numTrackedPoints']
@@ -170,18 +171,18 @@ class Session: #self like "recording self"
return session_settings_dictionary
f = 2
- def load_session_paths(self, session_settings_dict):
-
- session_paths = session_settings_dict['session_paths']
-
- self.rawVidPath = session_paths['RawVideos']
- self.syncedVidPath = session_paths['SyncedVideos']
- self.calVidPath = session_paths['CalVideos']
- self.mediaPipeDataPath = session_paths['MediaPipeData']
- self.openPoseDataPath = session_paths['OpenPoseData']
- self.dlcDataPath = session_paths['DLCData']
- self.imOutPath = session_paths['imOut']
- self.dataArrayPath = session_paths['DataArrays']
+ # def load_session_paths(self, session_settings_dict):
+
+ # session_paths = session_settings_dict['session_paths']
+
+ # self.rawVidPath = session_paths['RawVideos']
+ # self.syncedVidPath = session_paths['SyncedVideos']
+ # self.calVidPath = session_paths['CalVideos']
+ # self.mediaPipeDataPath = session_paths['MediaPipeData']
+ # self.openPoseDataPath = session_paths['OpenPoseData']
+ # self.dlcDataPath = session_paths['DLCData']
+ # self.imOutPath = session_paths['imOut']
+ # self.dataArrayPath = session_paths['DataArrays']
def save_user_preferences(self,preferences):
preferences_yaml = YAML()