Skip to content

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

TypeScript

default bone position to NaN (no mode 'snap to 0,0,0' nonsense lol)

Jon Matthisf2b6a66952d9
diff --git a/freemocap/dev_scratchpad/dev_alpha/FMC_MultiCamera.py b/freemocap/dev_scratchpad/dev_alpha/FMC_MultiCamera.py
index 04acf6d9..0d5c667f 100644
--- a/freemocap/dev_scratchpad/dev_alpha/FMC_MultiCamera.py
+++ b/freemocap/dev_scratchpad/dev_alpha/FMC_MultiCamera.py
@@ -554,7 +554,8 @@ if __name__ == '__main__':
in_rotation_codes_list = ['cv2.ROTATE_90_COUNTERCLOCKWISE', 'cv2.ROTATE_90_COUNTERCLOCKWISE', 'cv2.ROTATE_90_CLOCKWISE', 'cv2.ROTATE_90_CLOCKWISE', 'cv2.ROTATE_90_CLOCKWISE', ]
elif this_computer_name == 'DESKTOP-DCG6K4F':
freemocap_data_path = Path(r'C:\Users\jonma\Dropbox\FreeMoCapProject\FreeMocap_Data')
-
+ elif this_computer_name == 'Jons-MacBook-Pro.local':
+ freemocap_data_path = Path('/Users/jon/Dropbox/FreeMoCapProject')
try:
multi_cam = FMC_MultiCamera(freemocap_data_folder=str(freemocap_data_path), rotation_codes_list=in_rotation_codes_list)
diff --git a/freemocap/dev_scratchpad/simple_camera.py b/freemocap/dev_scratchpad/simple_camera.py
index 9d057dee..ebcb0a9b 100644
--- a/freemocap/dev_scratchpad/simple_camera.py
+++ b/freemocap/dev_scratchpad/simple_camera.py
@@ -1,11 +1,12 @@
import cv2
-cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
+# cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
+cap = cv2.VideoCapture(2, cv2.CAP_ANY)
cap.set(cv2.CAP_PROP_EXPOSURE, -7)
-cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
-cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
+cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
+cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
diff --git a/freemocap/fmc_blender.py b/freemocap/fmc_blender.py
index 2208c451..eae0c2fe 100644
--- a/freemocap/fmc_blender.py
+++ b/freemocap/fmc_blender.py
@@ -5,6 +5,7 @@ import math
import sys
from pathlib import Path
+
# get arguments
argv = sys.argv
argv = argv[argv.index("--") + 1:]
@@ -149,8 +150,8 @@ def add_child_bone(bone_name, empty1, empty2):
#Create a new bone
new_bone = armature_data.data.edit_bones.new(bone_name)
#Set bone's size
- new_bone.head = (0,0,0)
- new_bone.tail = (0,0.1,0)
+ new_bone.head = (np.nan,np.nan,np.nan)
+ new_bone.tail = (np.nan,np.nan,np.nan)
#Set bone's location to wheel
new_bone.matrix = empty2.matrix_world
#set location of bone head
@@ -330,12 +331,12 @@ def my_handler(scene):
#iterate through list of markers in this frame
for col in markers_list:
frame = scene.frame_current
- if math.isnan(col[0]):
- col[0] = 0.0
- if math.isnan(col[1]):
- col[1] = 0.0
- if math.isnan(col[2]):
- col[2] = 0.0
+ # if math.isnan(col[0]):
+ # col[0] = 0.0
+ # if math.isnan(col[1]):
+ # col[1] = 0.0
+ # if math.isnan(col[2]):
+ # col[2] = 0.0
coord = Vector(((float(col[0])*0.001), (float(col[2])*0.001), (float(col[1]))* -0.001))
if len(order_of_markers) > 0:
empty = order_of_markers[current_marker]
@@ -379,8 +380,8 @@ def boneGeometry( l1, l2, x, z, baseSize, l1Size, l2Size, base ):
x1 = x * baseSize * l1Size * 0.8
z1 = z * baseSize * l2Size * 0.8
- x2 = Vector( (0, 0, 0) )
- z2 = Vector( (0, 0, 0) )
+ x2 = Vector( (np.nan, np.nan, np.nan) )
+ z2 = Vector( (np.nan, np.nan, np.nan) )
verts = [
l1 - x1 + z1,
diff --git a/freemocap/fmc_runme.py b/freemocap/fmc_runme.py
index 80120afd..835b81cc 100644
--- a/freemocap/fmc_runme.py
+++ b/freemocap/fmc_runme.py
@@ -10,6 +10,7 @@ import time
from aniposelib.boards import CharucoBoard
import numpy as np
+from scipy.signal import savgol_filter
from ruamel.yaml import YAML
import cv2
@@ -229,7 +230,16 @@ def RunMe(sessionID=None,
sesh.mediaPipeSkel_fr_mar_xyz, sesh.mediaPipeSkel_reprojErr = reconstruct3D.reconstruct3D(sesh,sesh.mediaPipeData_nCams_nFrames_nImgPts_XYC, confidenceThreshold=reconstructionConfidenceThreshold)
np.save(sesh.dataArrayPath/'mediaPipeSkel_3d.npy', sesh.mediaPipeSkel_fr_mar_xyz) #save data to npy
np.save(sesh.dataArrayPath/'mediaPipeSkel_reprojErr.npy', sesh.mediaPipeSkel_reprojErr) #save data to npy
-
+
+
+ smoothWinLength = 5
+ smoothOrder = 3
+ for dim in range(sesh.mediaPipeSkel_fr_mar_xyz.shape[2]):
+ for mm in range(sesh.mediaPipeSkel_fr_mar_xyz.shape[1]):
+ sesh.mediaPipeSkel_fr_mar_xyz[:,mm,dim] = savgol_filter(sesh.mediaPipeSkel_fr_mar_xyz[:,mm,dim], smoothWinLength, smoothOrder)
+
+ np.save(sesh.dataArrayPath/'mediaPipeSkel_3d_smoothed.npy', sesh.mediaPipeSkel_fr_mar_xyz) #save data to npy
+
sesh.save_session()
if sesh.useOpenPose:
@@ -281,7 +291,7 @@ def RunMe(sessionID=None,
#blenderPath = Path('C:\Program Files\Blender Foundation\Blender 2.93')
#os.chdir(blenderExePath)
- output = subprocess.run([str(blenderPath), "--background", "--python", str(subprocessPath), "--", str(sesh.dataArrayPath/'mediaPipeSkel_3d.npy'), str(sesh.dataArrayPath)], capture_output=True, text=True, check=True)
+ output = subprocess.run([str(blenderPath), "--background", "--python", str(subprocessPath), "--", str(sesh.dataArrayPath/'mediaPipeSkel_3d_smoothed.npy'), str(sesh.dataArrayPath)], capture_output=True, text=True, check=True)
print(output)
except:
console.print_exception()
diff --git a/freemocap/play_skeleton_animation.py b/freemocap/play_skeleton_animation.py
index c4f8438c..47223672 100644
--- a/freemocap/play_skeleton_animation.py
+++ b/freemocap/play_skeleton_animation.py
@@ -535,7 +535,7 @@ def PlaySkeletonAnimation(
# groundYY = np.zeros_like(groundXX)
# groundMesh = ax3d.plot_surface(groundXX, groundZZ, groundYY, color='k', alpha=.5)
- axRange = 400#session.board.square_length * 10
+ axRange = 1000#session.board.square_length * 10
# Setting the axes properties
ax3d.set_xlim3d([mx-axRange, mx+axRange])
diff --git a/freemocap/webcam/videotrim.py b/freemocap/webcam/videotrim.py
index 3b4f42e8..43fc4533 100644
--- a/freemocap/webcam/videotrim.py
+++ b/freemocap/webcam/videotrim.py
@@ -22,8 +22,9 @@ def VideoTrim(session, vidList, ft, parameterDictionary, rotationState, numCamRa
postTrimmingTotalNumFrames = []
for vid,cam,camNum in zip(vidList,camList,numCamRange): #iterate in parallel through camera identifiers and matching videos
- print('Editing '+cam+' from ' +vid)
- cap = cv2.VideoCapture(str(session.rawVidPath/vid)) #initialize OpenCV capture
+ this_vid_path = session.rawVidPath/vid
+ print('synchronizing video at - ' + str(this_vid_path))
+ cap = cv2.VideoCapture(str(this_vid_path)) #initialize OpenCV capture
frameTable = ft[cam] #grab the frames needed for that camera
success, image = cap.read() #start reading frames
fourcc = cv2.VideoWriter_fourcc(*codec)
diff --git a/freemocap_blender_addon/freemocap_blender_addon/load_marker_empties.py b/freemocap_blender_addon/freemocap_blender_addon/load_marker_empties.py
index 44f82d50..7adfa141 100644
--- a/freemocap_blender_addon/freemocap_blender_addon/load_marker_empties.py
+++ b/freemocap_blender_addon/freemocap_blender_addon/load_marker_empties.py
@@ -1,6 +1,5 @@
import bpy
import numpy as np
-from ruamel.yaml import YAML
from pathlib import Path
class FMC_OT_loadMarkerEmpties(bpy.types.Operator): #setting the type as "FMC" for "OpenMoCap"