Free Motion Capture for Everyone πβ¨
TypeScript
tweak
Jon3544c0fa777b
diff --git a/freemocap/freemocap_blender_megascript.py b/freemocap/freemocap_blender_megascript.pyindex 91c2ad42..a8251c78 100644--- a/freemocap/freemocap_blender_megascript.py+++ b/freemocap/freemocap_blender_megascript.py@@ -57,8 +57,8 @@ for this_frame in range(mediapipe_skel_fr_mar_dim.shape[0]):nan_times_vis = np.array(frame_nan_counts)*np.array(frame_mean_reproj_error)num_frames = len(frame_nan_counts)-nan_times_vis[0:int(num_frames/5)] = np.nanmax(nan_times_vis)-nan_times_vis[-int(num_frames/5):-1] = np.nanmax(nan_times_vis)+# nan_times_vis[0:int(num_frames/5)] = np.nanmax(nan_times_vis)+# nan_times_vis[-int(num_frames/5):-1] = np.nanmax(nan_times_vis)good_clean_frame_number = np.nanargmin(nan_times_vis) # the frame with the fewest nans (i.e. hopefully a frame where all tracked points are visible)diff --git a/freemocap/play_skeleton_animation.py b/freemocap/play_skeleton_animation.pyindex 47223672..9e3aff1b 100644--- a/freemocap/play_skeleton_animation.py+++ b/freemocap/play_skeleton_animation.py@@ -41,6 +41,7 @@ import moviepy.editor as mpimport osimport copyfrom pathlib import Path+import time#RICH CONSOLE STUFFfrom rich import pretty@@ -704,7 +705,7 @@ def PlaySkeletonAnimation(fps=30 #NOTE - This should be saved in the session Class some how- time = np.arange(0, numFrames)/fps+ timestamps = np.arange(0, numFrames)/fpsif useMediaPipe:rHandIdx = 20lHandIdx = 19@@ -728,8 +729,8 @@ def PlaySkeletonAnimation(yTimeSeriesAx = fig.add_subplot(position=[.07, .225, linePlotWidth, linePlotHeight])yTimeSeriesAx.set_title('Hand Position vs Time', fontsize = 7, pad=2)- yTimeSeriesAx.plot(time, rHandY, color=humon_red, linewidth=.75, label='Right Hand')- yTimeSeriesAx.plot(time, lHandY, color=humon_blue, linewidth=.75, label='Left Hand')+ yTimeSeriesAx.plot(timestamps, rHandY, color=humon_red, linewidth=.75, label='Right Hand')+ yTimeSeriesAx.plot(timestamps, lHandY, color=humon_blue, linewidth=.75, label='Left Hand')timeRange = 3ylimRange = .6@@ -767,8 +768,8 @@ def PlaySkeletonAnimation(xTimeSeriesAx = fig.add_subplot(position=[.07, 0.05, linePlotWidth, linePlotHeight])- xTimeSeriesAx.plot(time, rHandX, color=humon_red, linewidth=.75, label='Right Hand')- xTimeSeriesAx.plot(time, lHandX, color=humon_blue, linewidth=.75, label='Left Hand')+ xTimeSeriesAx.plot(timestamps, rHandX, color=humon_red, linewidth=.75, label='Right Hand')+ xTimeSeriesAx.plot(timestamps, lHandX, color=humon_blue, linewidth=.75, label='Left Hand')@@ -823,7 +824,7 @@ def PlaySkeletonAnimation(# animationFramePath.mkdir(parents=True, exist_ok=True)# Creating the Animation object- line_animation = animation.FuncAnimation(fig, update_figure, range(startFrame,numFrames), fargs=(),+ out_animation = animation.FuncAnimation(fig, update_figure, range(startFrame,numFrames), fargs=(),interval=1, blit=False)@@ -832,17 +833,28 @@ def PlaySkeletonAnimation(# vidSavePath = '{}_animVid.mp4'.format(str(session.sessionPath / session.sessionID))gifSavePath = '{}_animVid.gif'.format(str(session.sessionPath / session.sessionID)) #NOTE - saving as a gif first then converting to MP4, because saving directly to MP4 requires users to install ffmpeg (independently of the pip install)with console.status('Saving animation for {}'.format(session.sessionID)):- # Writer = animation.writers['ffmpeg']++ # ffmpeg, not actually much faster :-/+ # tik = time.time()+ # vidSavePath = f'{str(session.sessionPath / session.sessionID)}_outVid.mp4'+ # video_writer = animation.FFMpegWriter(fps=fps)+ # out_animation.save(vidSavePath, writer=video_writer)+ # print(f'Done! Saved animation video to: {str(vidSavePath)}')+ # tok = time.time()-tik+ # print(f'Took {tok} seconds to save animation video wtih ffmpeg')+ # # # except:++ tik = time.time()Writer = animation.writers['pillow']writer = Writer(fps=fps, metadata=dict(artist='FreeMoCap'))#, bitrate=1800)- line_animation.save(gifSavePath, writer = writer)- # Writer = animation.FFMpegWriter(fps=30, metadata=dict(artist='FreeMoCap', comment=session.sessionID), bitrate=1800)- # vidSavePath = '{}_outVid.mp4'.format(str(session.sessionPath / session.sessionID))- # Writer.saving(fig = fig, outfile=vidSavePath, dpi=150)-- gif_filepath = mp.VideoFileClip(gifSavePath)- gif_filepath.write_videofile(gifSavePath.replace('.gif','.mp4'))- os.remove(gifSavePath)+ out_animation.save(gifSavePath, writer = writer)+ gif_filepath = mp.VideoFileClip(gifSavePath)+ gif_filepath.write_videofile(gifSavePath.replace('.gif','.mp4'))+ os.remove(gifSavePath)+ tok = time.time()-tik+ print(f'Took {tok} seconds to save animation video wtih pillow')++try: