Free Motion Capture for Everyone πβ¨
TypeScript
starting to add support for `anipose` `optim_points` method
Jone8ed0120d958
diff --git a/freemocap/fmc_anipose.py b/freemocap/fmc_anipose.pyindex 47c02088..8bd48a20 100644--- a/freemocap/fmc_anipose.py+++ b/freemocap/fmc_anipose.py@@ -1015,7 +1015,6 @@ class CameraGroup:len(self.cameras), points.shape)- n_cams, n_frames, n_joints, _ = points.shapeconstraints = np.array(constraints)constraints_weak = np.array(constraints_weak)@@ -1255,7 +1254,7 @@ class CameraGroup:lengths = np.linalg.norm(p3ds[:, a] - p3ds[:, b], axis=1)expected = joint_lengths[cix]errors_lengths[cix] = 100*(lengths - expected)/expected- errors_lengths = errors_lengths.ravel() * scale_l0ength+ errors_lengths = errors_lengths.ravel() * scale_lengtherrors_lengths_weak = np.empty((n_constraints_weak, n_frames), dtype='float64')for cix, (a, b) in enumerate(constraints_weak):diff --git a/freemocap/fmc_runme.py b/freemocap/fmc_runme.pyindex 983b1858..c972b9ce 100644--- a/freemocap/fmc_runme.py+++ b/freemocap/fmc_runme.py@@ -173,40 +173,6 @@ def RunMe(sessionID=None,sesh.cgroup, sesh.mean_charuco_fr_mar_xyz = calibrate.CalibrateCaptureVolume(sesh,board, calVideoFrameLength)- ##this is supposed to cycle through tyhe videos with different windows to try to get Anipose to work. I can't get the dang thing working because something weird happens where a Thread will get spawned in one of the inner functions (maybe related to tqdm?) and that iteration will jump out of the try/except- # try:- # sesh.cgroup, sesh.mean_charuco_fr_mar_xyz = calibrate.CalibrateCaptureVolume(sesh,board, calVideoFrameLength)- # # anipose_success = True- # anipose_success = False- # except:- # console.print_exception()- # console.print('[bold red] - Anipose Calibration failed with user-provided (or default) `calVideoFrameLength` value! Trying again with other parts of the videos')- # anipose_success = False-- # if not anipose_success:- # if calVideoFrameLength ==.25:- # cal_video_frame_range = [round(sesh.numFrames*.25), round(sesh.numFrames*.5)]- # else:- # cal_video_frame_range = [0, round(sesh.numFrames*.25)]-- # for anipose_iter in range(4):-- # console.rule('Anipose Failed - Reprocessing - Iteration #{}'.format(anipose_iter), style="color({})".format(thisStage))- # console.rule('Trying again with frame range {} - {}'.format(cal_video_frame_range[0], cal_video_frame_range[1]), style="color({})".format(thisStage))-- # try:- # sesh.cgroup, sesh.mean_charuco_fr_mar_xyz = calibrate.CalibrateCaptureVolume(sesh,board, cal_video_frame_range)- # break- # except:- # console.print_exception()- # cal_video_frame_range = [cal_video_frame_range[0]+round(sesh.numFrames*.25), cal_video_frame_range[0]+round(sesh.numFrames*.5)]-- # if cal_video_frame_range[1] > sesh.numFrames:- # console.print('[bold red] -Sorry, we couldn\'t get Anipose calibration to complete sucessfully. Are you using a Charuco board made with the parameters described in the ReadMe (here\s a sample png -https://github.com/jonmatthis/freemocap/blob/main/charuco_board_image.png ). Is the board clearly visible to each camera? Is there glare on it from from any of the camera\'s perspective? Is it too far away from the cameras? Is your `exposure` set low enough that the black squares are black (not grey)?')----print('Anipose Calibration Successful!')else:print('Skipping Calibration')@@ -225,14 +191,10 @@ def RunMe(sessionID=None,console.rule(style="color({})".format(thisStage))console.rule('Running MediaPipe skeleton tracker - https://google.github.io/mediapipe', style="color({})".format(thisStage))console.rule(style="color({})".format(thisStage))-if runMediaPipe:fmc_mediapipe.runMediaPipe(sesh)sesh.mediaPipeData_nCams_nFrames_nImgPts_XYC = fmc_mediapipe.parseMediaPipe(sesh)---else:print('`runMediaPipe` set to False, so we\'re loading MediaPipe data from npy file')@@ -240,6 +202,20 @@ def RunMe(sessionID=None,sesh.mediaPipeSkel_fr_mar_xyz, sesh.mediaPipeSkel_reprojErr = reconstruct3D.reconstruct3D(sesh,sesh.mediaPipeData_nCams_nFrames_nImgPts_XYC, confidenceThreshold=reconstructionConfidenceThreshold)+ bundle_adjust_3d_points=True+ if bundle_adjust_3d_points:+ sesh.mediaPipeSkel_fr_mar_xyz_og = sesh.mediaPipeSkel_fr_mar_xyz.copy()+ np.save(sesh.dataArrayPath/'mediaPipeSkel_3d_raw.npy', sesh.mediaPipeSkel_fr_mar_xyz_og) #save data to npy++ from mediapipe.python.solutions import holistic as mp_holistic+ mediapipe_body_pose_connections = [this_connection for this_connection in mp_holistic.POSE_CONNECTIONS]+ print('Running bundle adjustment optimization on 3d points...')+ sesh.mediaPipeSkel_fr_mar_xyz = sesh.cgroup.optim_points(sesh.mediaPipeData_nCams_nFrames_nImgPts_XYC[:,:,:,:2],+ sesh.mediaPipeSkel_fr_mar_xyz,+ constraints=mediapipe_body_pose_connections,+ verbose=True)+ print('Done adjusting bundles!')+np.save(sesh.dataArrayPath/'mediaPipeSkel_3d.npy', sesh.mediaPipeSkel_fr_mar_xyz) #save data to npynp.save(sesh.dataArrayPath/'mediaPipeSkel_reprojErr.npy', sesh.mediaPipeSkel_reprojErr) #save data to npy