Free Motion Capture for Everyone πβ¨
TypeScript
working with matplot lib 'Animation' methods
jon matthis8993e68728e1
diff --git a/freemocap/dev_scratchpad/playSkeletonAnimation.py b/freemocap/dev_scratchpad/playSkeletonAnimation.pyindex b9851151..cca022c5 100644--- a/freemocap/dev_scratchpad/playSkeletonAnimation.py+++ b/freemocap/dev_scratchpad/playSkeletonAnimation.py@@ -19,6 +19,7 @@ from rich import inspectfrom rich.console import Consoleconsole = Console()from rich.traceback import install as rich_traceback_install+from rich.markdown import Markdownrich_traceback_install()def main():@@ -35,25 +36,32 @@ def main():dims is the number of dimensions the line has."""lineData = np.empty((dims, length))- lineData[:, 0] = np.random.rand(dims)+ lineData[:, 0] = np.random.rand(dims)*1e2for index in range(1, length):# scaling the random numbers by 0.1 so# movement is small compared to position.# subtraction by 0.5 is to change the range to [-0.5, 0.5]# to allow a line to move backwards.- step = ((np.random.rand(dims) - 0.5) * 0.1)- lineData[:, index] = lineData[:, index - 1] + step+ step = ((np.random.rand(dims) - 0.5) * 1e2)+ lineData[:, index] = lineData[:, index - 1] + step*2return lineData- def update_lines(num, dataLines, lines):- for line, data in zip(lines, dataLines):+ def update_figure(frameNum, dataLines, plotting_data, skel_trajectories):+ print(frameNum)++ skel_dottos = plotting_data['skel_dottos']+ # for line, dotto, skel_dotto, data, skelTraj in zip(lines,dottos, skel_dottos, dataLines, skel_trajectories):+ for thisSkelDotto, thisTraj in zip(skel_dottos,skel_trajectories):# NOTE: there is no .set_data() for 3 dim data...- line.set_data(data[0:2, :num])- line.set_3d_properties(data[2, :num])- animSlider.set_val(val=num)- return lines+ # line.set_data(data[0:2, frameNum-4:frameNum])+ # line.set_3d_properties(data[2, frameNum-4:frameNum])++ thisSkelDotto.set_data(thisTraj[ frameNum-1, 0:2])+ thisSkelDotto.set_3d_properties(thisTraj[ frameNum-1, 2])++ animSlider.set_val(val=frameNum)# Attaching 3D axis to the figurefig = plt.figure()@@ -63,22 +71,28 @@ def main():ax3d = p3.Axes3D(fig)ax3d.set_position([.1, .1, .8, .8]) # [left, bottom, width, height])+ skel_fr_mar_dim = np.load(r"C:\Users\jonma\Dropbox\GitKrakenRepos\freemocap\Data\sesh_21-07-08_131030\DataArrays\openPoseSkel_3d.npy")+ skel_trajectories = [skel_fr_mar_dim[:,markerNum,:] for markerNum in range(skel_fr_mar_dim.shape[1])]+ numFrames = skel_fr_mar_dim.shape[0]+# Fifty lines of random 3-D lines- data = [Gen_RandLine(100, 3) for index in range(5)]+ data = [Gen_RandLine(numFrames, 3) for index in range(15)]# Creating fifty line objects.# NOTE: Can't pass empty arrays into 3d version of plot()- lines = [ax3d.plot(dat[0, 0:1], dat[1, 0:1], dat[2, 0:1])[0] for dat in data]-+ plotting_data = dict()+ # plotting_data['lines'] = [ax3d.plot(dat[0, 0:1], dat[1, 0:1], dat[2, 0:1],'bo')[0] for dat in data]+ plotting_data['skel_dottos'] = [ax3d.plot(thisTraj[0, 0:1], thisTraj[1, 0:1], thisTraj[2, 0:1],'ro')[0] for thisTraj in skel_trajectories]+# Setting the axes properties- ax3d.set_xlim3d([0.0, 1.0])+ ax3d.set_xlim3d([-1e3, 1e3])ax3d.set_xlabel('X')- ax3d.set_ylim3d([0.0, 1.0])+ ax3d.set_ylim3d([-1e3, 1e3])ax3d.set_ylabel('Y')- ax3d.set_zlim3d([0.0, 1.0])+ ax3d.set_zlim3d([-1e3, 1e3])ax3d.set_zlabel('Z')ax3d.set_title('3D Test')@@ -86,21 +100,20 @@ def main():- numFrames = 100#slideraxControls = fig.add_subplot(2,1,2)axControls.set_position([0.25, 0.01, 0.6, 0.05])animSlider = Slider(ax=axControls,label="FrameNum",- valmin=0,+ valmin=10,valmax=numFrames,- valinit=0,+ valinit=500,orientation="horizontal")# Creating the Animation object- line_animation = animation.FuncAnimation(fig, update_lines, numFrames, fargs=(data, lines),- interval=50, blit=False)+ line_animation = animation.FuncAnimation(fig, update_figure, range(200,numFrames), fargs=(data, plotting_data, skel_trajectories),+ interval=1, blit=False)plt.draw()plt.pause(.001) # pause a bit so that plots are updated