Skip to content

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

TypeScript

Updating data path choices

Aaron Cherian5011f6b5c4c3
diff --git a/.gitignore b/.gitignore
index dfb39d35..9160080e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@ Data/
.vscode/
*.py[cod]
*$py.class
+FreeMoCap_Data/
# C extensions
*.so
diff --git a/freemocap/__init__.py b/freemocap/__init__.py
index 01181b38..1327aaae 100644
--- a/freemocap/__init__.py
+++ b/freemocap/__init__.py
@@ -5,5 +5,5 @@ del get_versions
from freemocap import fmc_runme
-def RunMe(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,dlcConfigPath=None,debug=False):
- fmc_runme.Run(sessionID,stage,useOpenPose,useMediaPipe,useDLC,dlcConfigPath,debug)
\ No newline at end of file
+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
diff --git a/freemocap/fmc_runme.py b/freemocap/fmc_runme.py
index 817e2325..dc5b041a 100644
--- a/freemocap/fmc_runme.py
+++ b/freemocap/fmc_runme.py
@@ -2,6 +2,7 @@ from freemocap import (
createvideo,
recordingconfig,
runcams,
+ runmeGUI,
calibrate,
fmc_mediapipe,
fmc_openpose,
@@ -20,7 +21,9 @@ from aniposelib.boards import CharucoBoard
import numpy as np
-def Run(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,dlcConfigPath=None,debug=False):
+from ruamel.yaml import YAML
+
+def Run(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,dlcConfigPath=None,debug=False,setDataPath=False):
sesh = session.Session()
sesh.sessionID = sessionID
@@ -28,24 +31,69 @@ def Run(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,d
sesh.useMediaPipe = useMediaPipe
sesh.useDLC= useDLC
sesh.debug = debug
-
-
+ sesh.setDataPath = setDataPath
+ sesh.dataFolderName = 'FreeMocap_Data'
if sesh.useDLC:
import deeplabcut as dlc
sesh.dlcConfigPath =dlcConfigPath
# sesh.dlcConfigPath = Path("C:\\Users\\jonma\\Dropbox\\GitKrakenRepos\\freemocap\\DLC_Models\\PinkGreenRedJugglingBalls-JSM-2021-05-31\\config.yaml")
#sesh.dlcConfigPath = Path("C:\\Users\\jonma\\Desktop\\freemocap\\DLC_Models\\PinkGreenRedJugglingBalls-JSM-2021-05-31\\config.yaml")
+ if stage > 1:
+ if sesh.setDataPath == True:
+ basePath = runmeGUI.RunChooseDataPathGUI(session)
+ sesh.dataFolderPath = Path(basePath)/sesh.dataFolderName
+ else:
+ here = Path(__file__).parent
+ preferences_path = here/'user_preferences.yaml'
+ preferences_yaml = YAML()
+
+ if not preferences_path.exists():
+ raise FileNotFoundError('The user preferences yaml could not be located. Please change setDataPath to True to manually set the path to the Data folder')
+
+ preferences = preferences_yaml.load(preferences_path)
+ current_path_to_data = preferences['saved']['path_to_save']
+ dataFolder = Path(current_path_to_data)/sesh.dataFolderName
+ sesh.dataFolderPath = dataFolder
+
+ if not dataFolder.exists():
+ raise FileNotFoundError('No data folder located at: ' + str(dataFolder))
+ if sesh.sessionID == None:
+ subfolders = [f.path for f in os.scandir(sesh.dataFolderPath) if f.is_dir()] # copy-pasta from who knows where
+ sesh.sessionID = Path(subfolders[-1]).stem # grab the name of the last folder in the list of subfolders
+
+
- dataFolder = Path.cwd()/'Data'
- if dataFolder.exists():
- subfolders = [f.path for f in os.scandir(dataFolder) if f.is_dir()] # copy-pasta from who knows where
- sesh.sessionID = Path(subfolders[-1]).stem # grab the name of the last folder in the list of subfolders
- else: #First time run! Make 'FreeMoCap_Data' Folder (and eventually, prompt to download sample data)
- dataFolder.mkdir()
- sampleDataFolder = dataFolder / '_sample_data_folder'
- sampleDataFolder.mkdir()
+
+ print('Running ' + str(sesh.sessionID) + ' from ' + str(sesh.dataFolderPath))
+
+ # if sesh. setDataPath == True:
+ # #run file dialog GUI (select folder where the data folder)
+ # here = Path(__file__).parent
+ # parameter_path = here/'user_preferences.yaml'
+ # if parameter_path.exists():
+ # #this section looks for the Data folder at the last saved path from the user_preferences.yaml, if none exists, it raises an error
+ # #if not, if finds the most recent session from that Data folder
+ # parameters_yaml = YAML()
+ # parameters = parameters_yaml.load(parameter_path)
+ # current_path_to_data = parameters['saved']['path_to_save']
+ # dataFolder = Path(current_path_to_data)/'Data'
+ # try:
+ # subfolders = [f.path for f in os.scandir(dataFolder) if f.is_dir()] # copy-pasta from who knows where
+ # sesh.sessionID = Path(subfolders[-1]).stem # grab the name of the last folder in the list of subfolders
+ # except FileNotFoundError:
+ # raise FileNotFoundError('No data folder located at: ' + str(dataFolder))
+
+ # print('Running ' + str(sesh.sessionID) + ' from ' + str(dataFolder))
+ # sesh.dataPath = dataFolder
+
+
+
+ #else: #First time run! Make 'FreeMoCap_Data' Folder (and eventually, prompt to download sample data)
+ # dataFolder.mkdir()
+ # sampleDataFolder = dataFolder / '_sample_data_folder'
+ # sampleDataFolder.mkdir()
board = CharucoBoard(7, 5,
#square_length=1, # here, in mm but any unit works (JSM NOTE - just using '1' so resulting units will be in 'charuco squarelenghts`)
diff --git a/freemocap/runmeGUI.py b/freemocap/runmeGUI.py
new file mode 100644
index 00000000..3528ca42
--- /dev/null
+++ b/freemocap/runmeGUI.py
@@ -0,0 +1,53 @@
+import tkinter as tk
+from tkinter import Tk, Label, Button, Frame, Listbox, Entry, filedialog
+from pathlib import Path
+
+class setDataPathGUI:
+ def __init__(self, master,session):
+ self.master = master
+ self.session = session
+
+ chooseText = "Choose the directory where your data folder is located"
+ chooseLabel = Label(master, text=chooseText)
+ chooseLabel.pack(side="top")
+
+ self.currentPath = Path.cwd()
+ text = 'Current file path: ' + str(self.currentPath)
+ self.currentPathText = tk.StringVar()
+ self.currentPathText.set(text)
+ currentPathLabel = Label(master,textvariable = self.currentPathText)
+ currentPathLabel.pack()
+
+ changepath_button = Button(master,text = 'Change Folder Path',command = self.openFileDialog)
+ changepath_button.pack(side = 'left')
+
+ proceed_button = Button(text="Proceed", command=self.proceed)
+ stop_button = Button(text="Quit", command=self.stop)
+ proceed_button.pack()
+ stop_button.pack()
+
+
+
+ def openFileDialog(self):
+ self.currentPath = filedialog.askdirectory(
+ title='Open a file',
+ initialdir= Path.cwd())
+ self.currentPathText.set('Current file path: ' + self.currentPath)
+
+
+ def stop(self):
+ self.master.destroy()
+
+
+ def proceed(self):
+ self.continueToRecording = True
+ self.dataPath = self.currentPath
+ self.master.destroy()
+
+
+def RunChooseDataPathGUI(session):
+ root = tk.Tk()
+ chosenDataPath = setDataPathGUI(root, session)
+ root.mainloop()
+
+ return chosenDataPath.dataPath
\ No newline at end of file
diff --git a/freemocap/session.py b/freemocap/session.py
index 73672c48..0af37787 100644
--- a/freemocap/session.py
+++ b/freemocap/session.py
@@ -33,10 +33,10 @@ class Session: #self like "recording self"
def start_session(self,paramDict,rotDict):
#start a session, create all the file paths necessary, and create a session dictionary to save settings
- recordPath = self.basePath/'Data'
- recordPath.mkdir(exist_ok= True)
+ dataFolderPath = self.basePath/self.dataFolderName
+ dataFolderPath.mkdir(exist_ok= True)
- self.sessionPath = recordPath/self.sessionID
+ self.sessionPath = dataFolderPath/self.sessionID
self.sessionPath.mkdir(exist_ok=True)
#create all the session filepaths and settings - create and load them into a dictionary
@@ -129,10 +129,10 @@ class Session: #self like "recording self"
def initialize(self,stage):
#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
- recordPath.mkdir(exist_ok= True)
+ #recordPath = self.basePath/'Data' #create a Data folder in the filepath if none exists yet
+ #recordPath.mkdir(exist_ok= True)
- self.sessionPath = recordPath/self.sessionID
+ self.sessionPath = self.dataFolderPath/self.sessionID
self.sessionPath.mkdir(exist_ok=True)
self.session_yaml_path = self.sessionPath/'{}_config.yaml'.format(self.sessionID)
diff --git a/freemocap/webcam/recordGUI.py b/freemocap/webcam/recordGUI.py
index 21d9decb..f0ca86f3 100644
--- a/freemocap/webcam/recordGUI.py
+++ b/freemocap/webcam/recordGUI.py
@@ -259,7 +259,7 @@ class ProceedToRecordGUI:
self.sessionIDEntry.insert(0, self.sessionID_in)
- pathText = 'Choose where to create your Freemocap_Data folder:'
+ pathText = 'Choose where to create your data folder:'
pathLabel = Label(master,text=pathText)
pathLabel.pack()