Free Motion Capture for Everyone πβ¨
TypeScript
Lots of aesthetic and 'usability' changes to print statements and labels
jon matthis3a99d02cb4b8
diff --git a/freemocap/calibrate.py b/freemocap/calibrate.pyindex 8fffabcc..6bd15a00 100644--- a/freemocap/calibrate.py+++ b/freemocap/calibrate.py@@ -16,7 +16,7 @@ from rich.console import Consoleconsole = Console()-def CalibrateCaptureVolume(session,board, calVideoFrameLength = .25):+def CalibrateCaptureVolume(session,board, calVideoFrameLength = .5):"""Check if a previous calibration yaml exists, and if not, create a set of shortened calibration videos and run Anipose functionsto create a calibration yaml. Takes the 2D charuco board points and reconstructs them into 3D points that are saved out@@ -31,15 +31,18 @@ def CalibrateCaptureVolume(session,board, calVideoFrameLength = .25):if type(calVideoFrameLength)==int or type(calVideoFrameLength)==float:if calVideoFrameLength < 0: # if '-1' use the whole video- calVideoFrameLength = [0, session.numFrames]+ cal_vid_frame_range = [0, session.numFrames]calibrationVideoPath = session.calVidPathelse:if calVideoFrameLength>0 and calVideoFrameLength<1: #if between 0 and 1, use as a percentage of the total video length- calVideoFrameLength = [0, round(calVideoFrameLength * session.numFrames)]+ cal_vid_frame_range = [0, round(calVideoFrameLength * session.numFrames)]else: #otherwise, just use the input value as the number of frames to use- calVideoFrameLength = [0, calVideoFrameLength]+ cal_vid_frame_range = [0, calVideoFrameLength]+ elif type(calVideoFrameLength)==list:+ if len(calVideoFrameLength) ==2:+ cal_vid_frame_range = calVideoFrameLength- createCalibrationVideos(session, calVideoFrameLength)+ createCalibrationVideos(session, cal_vid_frame_range)@@ -108,7 +111,7 @@ def CalibrateCaptureVolume(session,board, calVideoFrameLength = .25):session.cgroup = cgroup- n_frames = calVideoFrameLength[1]-calVideoFrameLength[0]+ n_frames = cal_vid_frame_range[1]-cal_vid_frame_range[0]startframe = 0n_trackedPoints = 24diff --git a/freemocap/fmc_anipose.py b/freemocap/fmc_anipose.pyindex d052462e..a02ee6b6 100644--- a/freemocap/fmc_anipose.py+++ b/freemocap/fmc_anipose.py@@ -1736,8 +1736,10 @@ class CameraGroup:):"""Takes as input a list of list of video filenames, one list of each camera.Also takes a board which specifies what should be detected in the videos"""++ print('Detecting Charuco boards in each video...')- all_rows = self.get_rows_videos(videos, board, verbose=verbose)+ all_rows = self.get_rows_videos(videos, board, verbose=True)if init_extrinsics:self.set_camera_sizes_videos(videos)diff --git a/freemocap/fmc_pyqtgraph.py b/freemocap/fmc_pyqtgraph.pyindex eab43d4a..4e047438 100644--- a/freemocap/fmc_pyqtgraph.py+++ b/freemocap/fmc_pyqtgraph.py@@ -228,7 +228,7 @@ class PlaySkeletonWidget:def update(self):- # Plot Mr. Skreleton :D+ # Plots up Mr. Skreleton :D# Plots the dotsself.skelScatterItem.setData(diff --git a/freemocap/fmc_runme.py b/freemocap/fmc_runme.pyindex 3bbe3cac..6c23cc95 100644--- a/freemocap/fmc_runme.py+++ b/freemocap/fmc_runme.py@@ -1,4 +1,5 @@+from scipy.ndimage.measurements import center_of_massfrom freemocap.fmc_startup import startup, startupGUIfrom freemocap.webcam import camera_settings, timesync@@ -54,7 +55,7 @@ def RunMe(sessionID=None,showAnimation = True,reconstructionConfidenceThreshold = .7,charucoSquareSize = 36,#mm - ~the size of the squares when printed on 8.5x11" paper based on parameters in ReadMe.md- calVideoFrameLength = -1,+ calVideoFrameLength = .5,startFrame = 0,useBlender = False,resetBlenderExe = False,@@ -128,9 +129,9 @@ def RunMe(sessionID=None,if stage <= 1:thisStage=1- console.rule(style="color({})".format(thisStage))- console.rule('Starting Video Recordings'.upper(), style="color({})".format(thisStage))- console.rule(style="color({})".format(thisStage))+ console.rule(style="color({})".format(14))+ console.rule('Starting Video Recordings'.upper(), style="color({})".format(14))+ console.rule(style="color({})".format(14))runcams.RecordCams(sesh, sesh.cam_inputs, sesh.parameterDictionary, sesh.rotationInputs)sesh.save_session()@@ -156,11 +157,47 @@ def RunMe(sessionID=None,console.rule(style="color({})".format(thisStage))console.rule('Starting Capture Volume Calibration'.upper(),style="color({})".format(thisStage))console.rule(style="color({})".format(thisStage))- console.print(Padding('Using Anipose to calculate 6 degree-of-freedom position (and distortion coeffs) of each camera based on detected charuco boards. This information is used to create a Camera Projection Matrix for each camera, which is later used in the 3d reconstruction stage', (1,4)), overflow="fold", justify='center')+ console.print(Padding('Using Anipose to calculate 6 degree-of-freedom position (and distortion coeffs) of each camera based on detected charuco boards. This information is used to create a Camera Projection Matrix for each camera, which is later used in the 3d reconstruction stage', (1,4)), overflow="fold", justify='center',style="color({})".format(thisStage))console.rule('See https://anipose.org for details', style="color({})".format(thisStage))console.rule(style="color({})".format(thisStage))- sesh.cgroup, sesh.mean_charuco_fr_mar_xyz = calibrate.CalibrateCaptureVolume(sesh,board, calVideoFrameLength, spoof_anipose_fail_bool=False)++ 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')@@ -169,9 +206,9 @@ def RunMe(sessionID=None,if stage <= 4:thisStage=4console.rule(style="color({})".format(thisStage))- console.rule('Starting 2D Point Trackers'.upper(),style="color({})".format(thisStage))- console.rule('This step impolements the machine learning driven computer vision convolutional neural networks that track the skeleton, etc', style="color({})".format(thisStage))- console.rule('This part is crazy future tech sci fi stuff. Seriously unbelievable this kind of thing is possible.', style="color({})".format(thisStage))+ console.rule('Starting 2D Point Trackers'.upper(),style="color({})".format(thisStage))+ stage4_msg ='This step implements various computer vision that track the skeleton (and other objects) in the 2d videos, to produce the data that will be combined with the `camera projection matrices` from the calibration stage to produce the estimates of 3d movement. \n \n Each algorithm is different, but most involve using [bold magenta] convolutional neural networks [/bold magenta] trained from labeled videos to produce a 2d probability map of the likelihood that the tracked bodypart/object/feature (e.g. \'LeftElbow\') is in a given location. \n \n The peak of that distrubtion on each frame is recorded as the pixel-location of that item on that frame (e.g. \'LeftElbow(pixel-x, pixel-y, confidence\') where the a confidence value proportional to the underlying probability distribution (i.e. tall peaks in the probablitiy distribution -> high confidence that the LeftElbow actually is at this pixel-x, pixel-y location) \n \nThis part is crazy future tech sci fi stuff. Seriously unbelievable this kind of thing is possible β¨'+ console.print(Padding(stage4_msg, (1,4)), overflow="fold", justify='center',style="color({})".format(thisStage))console.rule(style="color({})".format(thisStage))time.sleep(pauseBetweenStages)@@ -240,12 +277,12 @@ def RunMe(sessionID=None,output = subprocess.run([blenderEXEpath, "--background", "--python", str(subprocessPath), "--", str(sesh.dataArrayPath/'mediaPipeSkel_3d.npy')], capture_output=True, text=True, check=True)print(output)- # %% Stage Five - Make Skreleton Animation+ # %% Stage Five - Make Animationif stage <= 6:thisStage=6console.rule(style="color({})".format(thisStage))- console.rule('Creating the Skelton animation!'.upper(),style="color({})".format(thisStage))- console.rule('The video creation is very slow. This whole animation maker is crazy slow, tbh. Sorry about that :sweat_smile:',style="color({})".format(thisStage))+ console.rule('Creating the Skreleton animation!'.upper(),style="color({})".format(thisStage))+ console.print('The video creation is very slow. This whole animation maker is crazy slow, tbh. Sorry about that, future iterations will be better lol :sweat_smile:',overflow="fold", justify='center',style="color({})".format(thisStage))console.rule(style="color({})".format(thisStage))time.sleep(pauseBetweenStages)@@ -271,12 +308,11 @@ def RunMe(sessionID=None,console.rule('Session Data folder is at: ', style="color({})".format(13))console.rule(str(sesh.sessionPath), style="color({})".format(13))console.rule(style="color({})".format(13))- console.rule("Thank you for supporting the FreeMoCap Project", style="color({})".format(13))+ console.rule(style="color({})".format(10))+ console.rule("Thank you for supporting the FreeMoCap Project", style="color({})".format(10))+ console.rule(style="color({})".format(10))console.rule(style="color({})".format(13))+ console.print('~β¨πβ¨~',justify="center")+ console.print('β€οΈ', justify="center")console.rule(style="color({})".format(13))- console.rule('~β¨πβ¨~',style="color({})".format(0))- time.sleep(.1) #Maybe helps so that rich doesn't print a newline after a rule with an emoji?- console.rule('β€οΈ',style="color({})".format(0))- console.rule(style="color({})".format(13))- console.rule(style="color({})".format(13))-+ console.rule(style="color({})".format(14))diff --git a/freemocap/reconstruct3D.py b/freemocap/reconstruct3D.pyindex cdb7dbce..de1fb8c7 100644--- a/freemocap/reconstruct3D.py+++ b/freemocap/reconstruct3D.py@@ -1,5 +1,7 @@from freemocap import fmc_aniposeimport numpy as np+from rich.console import Console+console=Console()# from numba import jit@@ -52,6 +54,7 @@ def reconstruct3D(session, data_nCams_nFrames_nImgPts_XYC, confidenceThreshold=0dataFlat_nCams_nTotalPoints_XY = data_nCams_nFrames_nImgPts_XY.reshape(nCams, -1, 2) # reshape data to collapse across 'frames' so it becomes [numCams, numFrames*numPoints, XY]+ console.print('Reconstructing 3d points...')data3d_flat = session.cgroup.triangulate(dataFlat_nCams_nTotalPoints_XY, progress=True)dataReprojerr_flat = session.cgroup.reprojection_error( data3d_flat, dataFlat_nCams_nTotalPoints_XY, mean=True)diff --git a/freemocap/webcam/camera_settings.py b/freemocap/webcam/camera_settings.pyindex cf1cad99..6296664e 100644--- a/freemocap/webcam/camera_settings.py+++ b/freemocap/webcam/camera_settings.py@@ -20,9 +20,9 @@ def initialize(session, stage, board):"""- console.rule(style="color({})".format(stage))- console.rule('Finding available webcams',style="color({})".format(stage))- console.rule(style="color({})".format(stage))+ console.rule(style="color({})".format(13))+ console.rule('Finding available webcams',style="color({})".format(13))+ console.rule(style="color({})".format(13))# if stage == 1:filepath = Path.cwd()diff --git a/freemocap/webcam/camsetup.py b/freemocap/webcam/camsetup.pyindex c4c175af..655c7496 100644--- a/freemocap/webcam/camsetup.py+++ b/freemocap/webcam/camsetup.py@@ -28,9 +28,8 @@ class VideoSetup(threading.Thread):exposure = parameterDictionary.get("exposure")resWidth = parameterDictionary.get("resWidth")resHeight = parameterDictionary.get("resHeight")- camName = "Camera" + str(self.camID)-- cv2.namedWindow(camName)+ camWindowName = "Camera" + str(self.camID)+' Preview - Press ESC to exit Setup'+ cv2.namedWindow(camWindowName)if platform.system() == 'Windows':cap = cv2.VideoCapture(self.camID, cv2.CAP_DSHOW)@@ -64,14 +63,15 @@ class VideoSetup(threading.Thread):if ret1 == True:if rotNum is not None:frame1 = imutils.rotate_bound(frame1, angle=rotNum)- cv2.imshow(camName, frame1)++ cv2.imshow(camWindowName, frame1)if cv2.waitKey(1) & 0xFF == 27:# == ord('q') for qbreakelse:break- cv2.destroyWindow(camName)+ cv2.destroyWindow(camWindowName)class MediaPipeVideoSetup(threading.Thread):"""@@ -91,9 +91,9 @@ class MediaPipeVideoSetup(threading.Thread):exposure = parameterDictionary.get("exposure")resWidth = parameterDictionary.get("resWidth")resHeight = parameterDictionary.get("resHeight")- camName = "Camera" + str(self.camID)+ camWindowName = "RECORDING - Camera" + str(self.camID)+' - Press ESC to exit'- cv2.namedWindow(camName)+ cv2.namedWindow(camWindowName)if platform.system() == 'Windows':cap = cv2.VideoCapture(self.camID, cv2.CAP_DSHOW)@@ -146,14 +146,14 @@ class MediaPipeVideoSetup(threading.Thread):.get_default_pose_landmarks_style())if rotNum is not None:frame1 = imutils.rotate_bound(frame1, angle=rotNum)- cv2.imshow(camName, frame1)+ cv2.imshow(camWindowName, frame1)if cv2.waitKey(1) & 0xFF == 27:# == ord('q') for qbreakelse:break- cv2.destroyWindow(camName)+ cv2.destroyWindow(camWindowName)diff --git a/freemocap/webcam/recordGUI.py b/freemocap/webcam/recordGUI.pyindex 621c4372..dc9cbe87 100644--- a/freemocap/webcam/recordGUI.py+++ b/freemocap/webcam/recordGUI.py@@ -52,7 +52,7 @@ class recordGUI:# ---create the task radiobuttontk.Label(- self.master, text="""Choose your task""", justify=tk.LEFT, padx=20+ self.master, text="""Select 'Setup' to preview cameras \n or \n 'Record' to create recording""", justify=tk.CENTER).pack()for option, val in options:@@ -60,7 +60,7 @@ class recordGUI:self.master, text=option, padx=20, variable=self.currentTask, value=val).pack(anchor=tk.W)- self.refresh_button = Button(bottom_frame, text="Refresh", command=self.Refresh)+ self.refresh_button = Button(bottom_frame, text="Re-detect Cameras", command=self.Refresh)self.refresh_button.pack(side=tk.RIGHT)@@ -213,7 +213,7 @@ class SettingsGUI:self.FPSEntry.insert(0, parameter_dictionary["framerate"])# ---Submit button to hit when things are finalized- self.sub_button = Button(bottomFrame, text="Submit", command=self.Submit)+ self.sub_button = Button(bottomFrame, text="Submit - Start Cameras", command=self.Submit)self.sub_button.pack(side=tk.BOTTOM)def openFileDialog(self):@@ -275,7 +275,7 @@ class ProceedToRecordGUI:self.sessionID_out = ""self.currentPath = current_path_to_save- sessionText = "Proceed to recording with this sessionID?"+ sessionText = "Proceed to recording? \n sessionID:"sessionLabel = Label(master, text=sessionText)sessionLabel.pack(side="top")@@ -298,7 +298,7 @@ class ProceedToRecordGUI:changepath_button.pack(side = 'left')# master.title("Proceed to Recording?")- self.proceed_button = Button(text="Proceed", command=self.proceed)+ self.proceed_button = Button(text="Begin Recording!", command=self.proceed)self.change_button = Button(text = "Change Parameters", command = self.change_params)self.stop_button = Button(text="Quit", command=self.stop)self.stop_button.pack(side=tk.RIGHT)diff --git a/freemocap/webcam/startcamrecording.py b/freemocap/webcam/startcamrecording.pyindex 6826df0f..49453b4d 100644--- a/freemocap/webcam/startcamrecording.py+++ b/freemocap/webcam/startcamrecording.py@@ -49,8 +49,8 @@ def CamRecording(# necessary, since each webcam runs as it's own object.global flagflag = False-- cv2.namedWindow(camID) # name the preview window for the camera its showing+ camWindowName = "RECORDING - " + str(camID)+' - Press ESC to exit'+ cv2.namedWindow(camWindowName) # name the preview window for the camera its showingif platform.system() == 'Windows':cam = cv2.VideoCapture(camInput, cv2.CAP_DSHOW)@@ -99,7 +99,7 @@ def CamRecording(breaksuccess, frame = cam.read()- cv2.imshow(camID, frame)+ cv2.imshow(camWindowName, frame)frame_sized = cv2.resize(frame, (resWidth, resHeight))# frame_sized = frameout.write(frame_sized)@@ -111,7 +111,7 @@ def CamRecording(with open(session.rawVidPath/camID, "wb") as f:pickle.dump(timeStamps, f) # dump the databreak- cv2.destroyWindow(camID)+ cv2.destroyWindow(camWindowName)return timeStamps