Skip to content

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

TypeScript

joint openpose and mediapipe reconstructions more or less working :D

jon matthis2dfff28e6550
diff --git a/freemocap/fmc_anipose.py b/freemocap/fmc_anipose.py
index e42a14f0..481a2501 100644
--- a/freemocap/fmc_anipose.py
+++ b/freemocap/fmc_anipose.py
@@ -542,6 +542,7 @@ class CameraGroup:
subp = points[:, ip, :]
good = ~np.isnan(subp[:, 0])
if np.sum(good) >= 2:
+
out[ip] = triangulate_simple(subp[good], cam_mats[good])
if one_point:
@@ -1656,6 +1657,9 @@ class CameraGroup:
verbose=True,
**kwargs
):
+
+ all_rowsOG = all_rows.copy()
+
"""Assumes camera sizes are set properly"""
for rows, camera in zip(all_rows, self.cameras):
size = camera.get_size()
@@ -1688,9 +1692,18 @@ class CameraGroup:
rtvecs = extract_rtvecs(merged)
if verbose:
pprint(get_connections(rtvecs, self.get_names()))
- rvecs, tvecs = get_initial_extrinsics(rtvecs)
- self.set_rotations(rvecs)
- self.set_translations(tvecs)
+
+
+ for camNum in range(rtvecs.shape[0]):
+ if np.sum(np.isnan(rtvecs[camNum,:,:])) == rtvecs[camNum,:,:].size:
+ rtvecsOG = rtvecs.copy() #for posterity
+ rtvecs = np.delete(rtvecs, 0,0)
+ print('REMOVING CAM# {} BECAUSE ANIPOSE HAD IT AS NaNs FOR SOME UNKNOWN REASON'.format(camNum))
+
+ rvecs, tvecs = get_initial_extrinsics(rtvecs)
+ self.set_rotations(rvecs)
+ self.set_translations(tvecs)
+
error = self.bundle_adjust_iter(imgp, extra, verbose=verbose, **kwargs)
diff --git a/freemocap/fmc_runme.py b/freemocap/fmc_runme.py
index b0fe4e3e..8b10fb5d 100644
--- a/freemocap/fmc_runme.py
+++ b/freemocap/fmc_runme.py
@@ -216,15 +216,15 @@ def RunMe(sessionID=None,
fmc_mediapipe.runMediaPipe(sesh)
sesh.mediaPipeData_nCams_nFrames_nImgPts_XYC = fmc_mediapipe.parseMediaPipe(sesh)
- sesh.mediaPipeSkel_fr_mar_xyz, sesh.mediaPipe_reprojErr = reconstruct3D.reconstruct3D(sesh,sesh.mediaPipeData_nCams_nFrames_nImgPts_XYC, confidenceThreshold=reconstructionConfidenceThreshold)
+ 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.mediaPipe_reprojErr) #save data to npy
+ np.save(sesh.dataArrayPath/'mediaPipeSkel_reprojErr.npy', sesh.mediaPipeSkel_reprojErr) #save data to npy
sesh.save_session()
if sesh.useOpenPose:
fmc_openpose.runOpenPose(sesh, runOpenPose=runOpenPose)
sesh.openPoseData_nCams_nFrames_nImgPts_XYC = fmc_openpose.parseOpenPose(sesh)
- sesh.openPoseSkel_fr_mar_xyz, sesh.openPose_reprojErr = reconstruct3D.reconstruct3D(sesh,sesh.openPoseData_nCams_nFrames_nImgPts_XYC, confidenceThreshold=reconstructionConfidenceThreshold)
+ sesh.openPoseSkel_fr_mar_xyz, sesh.openPoseSkel_reprojErr = reconstruct3D.reconstruct3D(sesh,sesh.openPoseData_nCams_nFrames_nImgPts_XYC, confidenceThreshold=reconstructionConfidenceThreshold)
np.save(sesh.dataArrayPath/'openPoseSkel_3d.npy', sesh.openPoseSkel_fr_mar_xyz) #save data to npy
np.save(sesh.dataArrayPath/'openPoseSkel_reprojErr.npy', sesh.openPoseSkel_reprojErr) #save data to npy
sesh.save_session()
diff --git a/freemocap/play_skeleton_animation.py b/freemocap/play_skeleton_animation.py
index 8830704e..9f97ab5f 100644
--- a/freemocap/play_skeleton_animation.py
+++ b/freemocap/play_skeleton_animation.py
@@ -692,16 +692,20 @@ def PlaySkeletonAnimation(
fps=30 #NOTE - This should be saved in the session Class some how
time = np.arange(0, numFrames)/fps
if useMediaPipe:
- rHandX = mediaPipe_skel_fr_mar_xyz[:,4,0]/1000 #convert mm to meters
- rHandY = -mediaPipe_skel_fr_mar_xyz[:,4,1]/1000
- lHandX = mediaPipe_skel_fr_mar_xyz[:,7,0]/1000
- lHandY = -mediaPipe_skel_fr_mar_xyz[:,7,1]/1000
+ rHandIdx = 20
+ lHandIdx = 19
+ rHandX = mediaPipe_skel_fr_mar_xyz[:,rHandIdx,0]/1000 #convert mm to meters
+ rHandY = -mediaPipe_skel_fr_mar_xyz[:,rHandIdx,1]/1000
+ lHandX = mediaPipe_skel_fr_mar_xyz[:,lHandIdx,0]/1000
+ lHandY = -mediaPipe_skel_fr_mar_xyz[:,lHandIdx,1]/1000
if useOpenPose:
- rHandX = openPose_skel_fr_mar_xyz[:,4,0]/1000 #convert mm to meters
- rHandY = -openPose_skel_fr_mar_xyz[:,4,1]/1000
- lHandX = openPose_skel_fr_mar_xyz[:,7,0]/1000
- lHandY = -openPose_skel_fr_mar_xyz[:,7,1]/1000
+ rHandIdx = 4
+ lHandIdx = 7
+ rHandX = openPose_skel_fr_mar_xyz[:,rHandIdx,0]/1000 #convert mm to meters
+ rHandY = -openPose_skel_fr_mar_xyz[:,rHandIdx,1]/1000
+ lHandX = openPose_skel_fr_mar_xyz[:,lHandIdx,0]/1000
+ lHandY = -openPose_skel_fr_mar_xyz[:,lHandIdx,1]/1000
linePlotWidth = .45
diff --git a/freemocap/user_preferences.yaml b/freemocap/user_preferences.yaml
index c7d4a449..3f21f371 100644
--- a/freemocap/user_preferences.yaml
+++ b/freemocap/user_preferences.yaml
@@ -16,7 +16,7 @@ saved:
3: 0
parameters:
exposure: -7
- resWidth: 640
- resHeight: 480
+ resWidth: 960
+ resHeight: 720
framerate: 30
codec: DIVX
diff --git a/freemocap_runme_script.py b/freemocap_runme_script.py
index 684b5ce7..166fe369 100644
--- a/freemocap_runme_script.py
+++ b/freemocap_runme_script.py
@@ -1,18 +1,18 @@
from freemocap.fmc_mediapipe import runMediaPipe
import freemocap as fmc
from pathlib import Path
-import socket
+import sys
-try:
- fmc.RunMe( stage=5,
- useOpenPose=False,
- runOpenPose=True,
- useMediaPipe=True,
- runMediaPipe = True,
- useDLC=False,
- recordVid = True,
- reconstructionConfidenceThreshold = 0.5,
- calVideoFrameLength = -1)
-except:
- print("Unexpected error:", sys.exc_info()[0])
- raise
\ No newline at end of file
+
+fmc.RunMe(
+ sessionID = 'sesh_2021-08-29_15_26_34',
+ stage = 4,
+ useOpenPose=True,
+ runOpenPose=True,
+ useMediaPipe=True,
+ runMediaPipe = True,
+ useDLC=False,
+ recordVid = True,
+ reconstructionConfidenceThreshold = 0.5,
+ calVideoFrameLength = -1,
+)