Skip to content

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

TypeScript

add ability to specify `good_clean_frame_number` in `freemocap.RunMe` to help with Blender reconstruction

jon matthis3f5fddc46630
diff --git a/freemocap/fmc_runme.py b/freemocap/fmc_runme.py
index cf814d5c..bddb358c 100644
--- a/freemocap/fmc_runme.py
+++ b/freemocap/fmc_runme.py
@@ -61,6 +61,7 @@ def RunMe(sessionID=None,
useBlender = False,
resetBlenderExe = False,
get_synced_unix_timestamps = True,
+ good_clean_frame_number = 0,
):
"""
Starts the freemocap pipeline based on either user-input values, or default values. Creates a new session class instance (called sesh)
@@ -312,7 +313,7 @@ def RunMe(sessionID=None,
path_to_this_py_file = Path(__file__).parent.resolve()
fmc_blender_script_path = path_to_this_py_file /'freemocap_blender_megascript.py'
- command_str = str(blenderPath) + " --background" + " --python " + str(fmc_blender_script_path) + " -- " + str(sesh.sessionPath)
+ command_str = str(blenderPath) + " --background" + " --python " + str(fmc_blender_script_path) + " -- " + str(sesh.sessionPath) +' ' + str(good_clean_frame_number)
# command_str = [str(blenderPath), "--background", "--python", str(fmc_blender_script_path), "--", str(sesh.sessionPath)]
blender_process = subprocess.Popen(
command_str,
@@ -326,6 +327,11 @@ def RunMe(sessionID=None,
break
if output:
print(output.strip().decode())
+
+ if blender_process.returncode == 0:
+ print("Blender returned an error:")
+ print(blender_process.stderr.read().decode())
+
except:
diff --git a/freemocap/freemocap_blender_megascript.py b/freemocap/freemocap_blender_megascript.py
index b5942f6a..24f9fced 100644
--- a/freemocap/freemocap_blender_megascript.py
+++ b/freemocap/freemocap_blender_megascript.py
@@ -16,6 +16,11 @@ addon_utils.enable("rigify")
argv = sys.argv
argv = argv[argv.index("--") + 1:]
session_path = argv[0]
+if len(argv)>1:
+ good_clean_frame_number = int(argv[1])
+else:
+ good_clean_frame_number = 0
+
print(str(session_path))
session_path = Path(session_path)
path_to_mediapipe_npy = session_path / 'DataArrays' / 'mediaPipeSkel_3d_smoothed.npy'
@@ -55,19 +60,20 @@ bpy.context.scene.frame_end = end_frame
########################
## Find Good Clean Frame with some fiddly nonsense
-frame_nan_counts = []
-frame_mean_reproj_error = []
+if good_clean_frame_number == 0:
+ frame_nan_counts = []
+ frame_mean_reproj_error = []
-for this_frame in range(mediapipe_skel_fr_mar_dim.shape[0]):
- frame_nan_counts.append(np.sum(np.isnan(mediapipe_skel_fr_mar_dim[this_frame,:,0])))
- frame_mean_reproj_error.append(np.nanmean(mediapipe_reproj_fr_mar[this_frame,:]))
+ for this_frame in range(mediapipe_skel_fr_mar_dim.shape[0]):
+ frame_nan_counts.append(np.sum(np.isnan(mediapipe_skel_fr_mar_dim[this_frame,:,0])))
+ frame_mean_reproj_error.append(np.nanmean(mediapipe_reproj_fr_mar[this_frame,:]))
-nan_times_vis = np.array(frame_nan_counts)*np.array(frame_mean_reproj_error)
-num_frames = len(frame_nan_counts)
-# nan_times_vis[0:int(num_frames/5)] = np.nanmax(nan_times_vis)
-# nan_times_vis[-int(num_frames/5):-1] = np.nanmax(nan_times_vis)
+ nan_times_vis = np.array(frame_nan_counts)*np.array(frame_mean_reproj_error)
+ num_frames = len(frame_nan_counts)
+ # nan_times_vis[0:int(num_frames/5)] = np.nanmax(nan_times_vis)
+ # nan_times_vis[-int(num_frames/5):-1] = np.nanmax(nan_times_vis)
-good_clean_frame_number = np.nanargmin(nan_times_vis) # the frame with the fewest nans (i.e. hopefully a frame where all tracked points are visible)
+ good_clean_frame_number = np.nanargmin(nan_times_vis) # the frame with the fewest nans (i.e. hopefully a frame where all tracked points are visible)
print(f"----good_clean_frame_number: {good_clean_frame_number}----")