Free Motion Capture for Everyone πβ¨
TypeScript
various tweaks - including replacing blank frams with previous frames in Sync (stage=2)
jon matthis1c06d60f32c3
diff --git a/freemocap/fmc_anipose.py b/freemocap/fmc_anipose.pyindex 979b8e41..47c02088 100644--- a/freemocap/fmc_anipose.py+++ b/freemocap/fmc_anipose.py@@ -666,7 +666,8 @@ class CameraGroup:to reduce the influence of outliers.This is inspired by the algorithm for Fast Global Registration by Zhou, Park, and Koltun"""-+ error_list = []+assert p2ds.shape[0] == len(self.cameras), \"Invalid points shape, first dim should be equal to" \" number of cameras ({}), but shape is {}".format(@@ -710,6 +711,7 @@ class CameraGroup:p2ds[:, good], extra_good, n_samp=n_samp_iter)error = np.median(errors_norm)+ error_list.append(error)if error < error_threshold:break@@ -717,6 +719,7 @@ class CameraGroup:if verbose:pprint(error_dict)print('error: {:.2f}, mu: {:.1f}, ratio: {:.3f}'.format(error, mu, np.mean(good)))+ print(f'previous error scores: {error_list}')self.bundle_adjust(p2ds_samp, extra_samp,loss='linear', ftol=ftol,@@ -1568,7 +1571,7 @@ class CameraGroup:self.set_rotations(rvecs)self.set_translations(tvecs)- error = self.bundle_adjust_iter(imgp, extra, verbose=verbose, **kwargs)+ error = self.bundle_adjust_iter(imgp, extra, verbose=verbose, error_threshold=1)return error,merged,charuco_framesdiff --git a/freemocap/fmc_runme.py b/freemocap/fmc_runme.pyindex 8e30012f..19197238 100644--- a/freemocap/fmc_runme.py+++ b/freemocap/fmc_runme.py@@ -228,20 +228,30 @@ def RunMe(sessionID=None,if runMediaPipe:fmc_mediapipe.runMediaPipe(sesh)sesh.mediaPipeData_nCams_nFrames_nImgPts_XYC = fmc_mediapipe.parseMediaPipe(sesh)- 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+ else:+ print('`runMediaPipe` set to False, so we\'re loading MediaPipe data from npy file')+ sesh.mediaPipeData_nCams_nFrames_nImgPts_XYC = np.load(sesh.dataArrayPath/'mediaPipeData_2d.npy', allow_pickle=True)++ 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++ #smoooooooooth, just a bit+ 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:console.rule(style="color({})".format(thisStage))diff --git a/freemocap/webcam/camsetup.py b/freemocap/webcam/camsetup.pyindex 7b25e263..c29af680 100644--- a/freemocap/webcam/camsetup.py+++ b/freemocap/webcam/camsetup.py@@ -3,8 +3,10 @@ import cv2import imutilsimport osimport platform+import timeimport mediapipe as mp+import numpy as npmp_drawing = mp.solutions.drawing_utilsmp_drawing_styles = mp.solutions.drawing_styles@@ -102,8 +104,8 @@ class MediaPipeVideoSetup(threading.Thread):cap = cv2.VideoCapture(self.camID, cv2.CAP_ANY)with mp_holistic.Holistic(- static_image_mode=True,- model_complexity=0,+ static_image_mode=False,+ model_complexity=2,enable_segmentation=True) as holistic:cap.set(cv2.CAP_PROP_FRAME_WIDTH, resWidth)@@ -127,12 +129,19 @@ class MediaPipeVideoSetup(threading.Thread):print("CAP_PROP_GAIN : '{}'".format(cap.get(cv2.CAP_PROP_GAIN)))print("CAP_PROP_CONVERT_RGB : '{}'".format(cap.get(cv2.CAP_PROP_CONVERT_RGB)))print("__________________________________________")-+ timestamps = []while True:ret1, frame1 = cap.read()+ timestamps.append(time.time())++ print(f"mean fps for cam {self.camID} is {1/np.mean(np.diff(timestamps))}")+if ret1 == True:frame1.flags.writeable = False- results = holistic.process(cv2.cvtColor(frame1, cv2.COLOR_BGR2RGB))+ try:+ results = holistic.process(cv2.cvtColor(frame1, cv2.COLOR_BGR2RGB))+ except Exception as e:+ print(e)mp_drawing.draw_landmarks(frame1,results.face_landmarks,@@ -146,6 +155,18 @@ class MediaPipeVideoSetup(threading.Thread):mp_holistic.POSE_CONNECTIONS,landmark_drawing_spec=mp_drawing_styles.get_default_pose_landmarks_style())+ mp_drawing.draw_landmarks(+ frame1,+ results.left_hand_landmarks,+ mp_holistic.HAND_CONNECTIONS,+ landmark_drawing_spec=mp_drawing_styles+ .get_default_hand_landmarks_style())+ mp_drawing.draw_landmarks(+ frame1,+ results.right_hand_landmarks,+ mp_holistic.HAND_CONNECTIONS,+ landmark_drawing_spec=mp_drawing_styles+ .get_default_hand_landmarks_style())if rotNum is not None:frame1 = imutils.rotate_bound(frame1, angle=rotNum)cv2.imshow(camWindowName, frame1)diff --git a/freemocap/webcam/startcamrecording.py b/freemocap/webcam/startcamrecording.pyindex cd7746ce..e8a1c30d 100644--- a/freemocap/webcam/startcamrecording.py+++ b/freemocap/webcam/startcamrecording.py@@ -96,13 +96,16 @@ def CamRecording(pickle.dump(timeStamps, f)breaksuccess, frame = cam.read()-+ timeStamps.append(time.time() - beginTime) # add each timestamp to the list+ timeStamps_unix.append(time.time())+cv2.imshow(camWindowName, frame)frame_sized = cv2.resize(frame, (resWidth, resHeight))frame_sized = frameout.write(frame)timeStamps.append(time.time() - beginTime) # add each timestamp to the list+key = cv2.waitKey(20)if key == 27: # exit on ESCflag = True # set flag to true to shut down all other webcamsdiff --git a/freemocap/webcam/videotrim.py b/freemocap/webcam/videotrim.pyindex 43fc4533..d176578e 100644--- a/freemocap/webcam/videotrim.py+++ b/freemocap/webcam/videotrim.py@@ -27,6 +27,7 @@ def VideoTrim(session, vidList, ft, parameterDictionary, rotationState, numCamRacap = cv2.VideoCapture(str(this_vid_path)) #initialize OpenCV captureframeTable = ft[cam] #grab the frames needed for that camerasuccess, image = cap.read() #start reading frames+ prev_image=image.copy()fourcc = cv2.VideoWriter_fourcc(*codec)saveName = session.sessionID + "_synced_" + cam + ".mp4"@@ -57,12 +58,12 @@ def VideoTrim(session, vidList, ft, parameterDictionary, rotationState, numCamRacap.set(cv2.CAP_PROP_POS_FRAMES, frame) # set the video to the frame that we need- success, image = cap.read()+ success, image = cap.read()if rotationState[camNum] is not None:image = imutils.rotate_bound(image, angle=rotationState[camNum])image = cv2.resize(image, (resWidth, resHeight))out.write(image)- f = 2+ prev_image=image.copy()resWidth = trueWidthresHeight = trueHeight