Free Motion Capture for Everyone πβ¨
TypeScript
Create dev_jon branch
jon matthis9aa439d51b26
diff --git a/freemocap/__init__.py b/freemocap/__init__.pyindex 01181b38..e5c20d9b 100644--- a/freemocap/__init__.py+++ b/freemocap/__init__.py@@ -5,5 +5,7 @@ del get_versionsfrom freemocap import fmc_runme-def RunMe(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,dlcConfigPath=None,debug=False):- fmc_runme.Run(sessionID,stage,useOpenPose,useMediaPipe,useDLC,dlcConfigPath,debug)\ No newline at end of file++def RunMe(sessionID=None, stage=1, useOpenPose=True, openPoseDummyRun = False, useMediaPipe=False, useDLC=True, dlcConfigPath=None, debug=False):\++ fmc_runme.Run(sessionID, stage, useOpenPose, openPoseDummyRun, useMediaPipe, useDLC, dlcConfigPath, debug)\ No newline at end of filediff --git a/freemocap/dev_scratchpad/fmc_rich.py b/freemocap/dev_scratchpad/fmc_rich.pynew file mode 100644index 00000000..6f55dec3--- /dev/null+++ b/freemocap/dev_scratchpad/fmc_rich.py@@ -0,0 +1,66 @@+#%% Working from this youtube vid - https://www.youtube.com/watch?v=JrGFQp9njas+from rich import print+from rich import pretty+pretty.install() #makes all print statement output pretty++from rich import inspect++#%%+print('[red]hello[/red] :poop:')+# %%+locals()+#%%+print(locals())++# %%+inspect('asdf')+# %%++inspect('asfdf',methods=True)+++# %%+from rich.console import Console+console = Console()+console.print('[green]hello[/green] :poop:')+console.log('hello :poop:', style='bold blue')+console.info('hello :poop:', style='bold green')+# inspect(console, methods=True)++# %%+from rich.table import Table++table = Table(show_header=True, header_style="bold magenta")+table.add_column("Date", style="dim", width=12)+table.add_column("Title")+table.add_column("Production Budget", justify="right")+table.add_column("Box Office", justify="right")+table.add_row(+ "Dev 20, 2019", "Star Wars: The Rise of Skywalker", "$275,000,000", "$375,126,118"+)+table.add_row(+ "May 25, 2018",+ "[red]Solo[/red]: A Star Wars Story",+ "$275,000,000",+ "$393,151,347",+)+table.add_row(+ "Dec 15, 2017",+ "Star Wars Ep. VIII: The Last Jedi",+ "$262,000,000",+ "[bold]$1,332,539,889[/bold]",+)++console.print(table)+# %%+from time import sleep+from rich.progress import track++for step in track(range(10)):+ sleep(0.5)+ step+# %%+from rich.traceback import install as rich_traceback_install+rich_traceback_install()+1/0+# %%diff --git a/freemocap/dev_scratchpad/playAnimWithSlider.py b/freemocap/dev_scratchpad/playAnimWithSlider.pynew file mode 100644index 00000000..7a3a34d2--- /dev/null+++ b/freemocap/dev_scratchpad/playAnimWithSlider.py@@ -0,0 +1,72 @@+#https://matplotlib.org/stable/api/animation_api.html+from operator import is_+import numpy as np+import matplotlib.pyplot as plt+from matplotlib.animation import FuncAnimation+from mpl_toolkits.mplot3d import axes3d+from matplotlib.widgets import Slider++fig = plt.figure()+ax3d = fig.add_subplot(211,projection="3d")+xdata, ydata , zdata = [], [], []+ln, = plt.plot([], [], [], 'r-o')++axControls = fig.add_subplot(212)++numFrames = 128+#slider+animSlider = Slider(+ ax=axControls,+ label="FrameNum",+ valmin=0,+ valmax=100,+ valinit=0,+ orientation="horizontal"+)+# Animation controls+is_manual = False # True if user has taken control of the animation+interval = 0 # ms, time between animation frames+loop_len = 0.1 # seconds per loop+scale = interval / 1000 / loop_len++def init():+ ax3d.set_xlim(0, 2*np.pi)+ ax3d.set_ylim(-1, 1)+ ax3d.set_zlim(-1, 1)+ return ln,++def update_slider(frameNum):+ global is_manual+ is_manual = True+ update_figure(frameNum)++def update_figure(frameNum):+ global is_manual+ if is_manual:+ return ln, #don't change in manual mode++ xdata.append(frameNum)+ ydata.append(np.sin(frameNum))+ zdata.append(np.sin(frameNum))+ ln.set_data_3d(xdata, ydata,zdata)+ is_manual = False # the above line called update_slider, so we need to reset this+ return ln,++def on_click(event):+ # Check where the click happened+ (xm,ym),(xM,yM) = animSlider.label.clipbox.get_points()+ if xm < event.x < xM and ym < event.y < yM:+ # Event happened within the slider, ignore since it is handled in update_slider+ return+ else:+ # user clicked somewhere else on canvas = unpause+ global is_manual+ is_manual=False++# call update function on slider value change+animSlider.on_changed(update_slider)+fig.canvas.mpl_connect('button_press_event', on_click)++ani = FuncAnimation(fig, update_figure, frames=np.linspace(0, 2*np.pi, numFrames),+ init_func=init, blit=True)+plt.show()\ No newline at end of filediff --git a/freemocap/dev_scratchpad/playSkeletonAnimation.py b/freemocap/dev_scratchpad/playSkeletonAnimation.pynew file mode 100644index 00000000..b9851151--- /dev/null+++ b/freemocap/dev_scratchpad/playSkeletonAnimation.py@@ -0,0 +1,111 @@+"""+============+3D animation+============++An animated plot in 3D.+from - https://matplotlib.org/2.1.2/gallery/animation/simple_3danim.html+"""+import numpy as np+import matplotlib.pyplot as plt+import mpl_toolkits.mplot3d.axes3d as p3+import matplotlib.animation as animation+from matplotlib.widgets import Slider++#RICH CONSOLE STUFF+from rich import pretty+pretty.install() #makes all print statement output pretty+from rich import inspect+from rich.console import Console+console = Console()+from rich.traceback import install as rich_traceback_install+rich_traceback_install()++def main():+ # Fixing random state for reproducibility+ np.random.seed(19680801)++++ def Gen_RandLine(length, dims=2):+ """+ Create a line using a random walk algorithm++ length is the number of points for the line.+ dims is the number of dimensions the line has.+ """+ lineData = np.empty((dims, length))+ lineData[:, 0] = np.random.rand(dims)+ for 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++ return lineData+++ def update_lines(num, dataLines, lines):+ for line, data in zip(lines, dataLines):+ # 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++ # Attaching 3D axis to the figure+ fig = plt.figure()+ plt.ion()+ plt.show()++ ax3d = p3.Axes3D(fig)+ ax3d.set_position([.1, .1, .8, .8]) # [left, bottom, width, height])+++ # Fifty lines of random 3-D lines+ data = [Gen_RandLine(100, 3) for index in range(5)]++ # 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]++ # Setting the axes properties+ ax3d.set_xlim3d([0.0, 1.0])+ ax3d.set_xlabel('X')++ ax3d.set_ylim3d([0.0, 1.0])+ ax3d.set_ylabel('Y')++ ax3d.set_zlim3d([0.0, 1.0])+ ax3d.set_zlabel('Z')++ ax3d.set_title('3D Test')+++++ numFrames = 100+ #slider+ axControls = 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,+ valmax=numFrames,+ valinit=0,+ orientation="horizontal"+ )+ # Creating the Animation object+ line_animation = animation.FuncAnimation(fig, update_lines, numFrames, fargs=(data, lines),+ interval=50, blit=False)++ plt.draw()+ plt.pause(.001) # pause a bit so that plots are updated++ console.print(":sparkle: :skull: :sparkle:")++if __name__ == '__main__':+ main()\ No newline at end of filediff --git a/freemocap/fmc_deeplabcut.py b/freemocap/fmc_deeplabcut.pyindex 6a914103..ca69db90 100644--- a/freemocap/fmc_deeplabcut.py+++ b/freemocap/fmc_deeplabcut.py@@ -33,22 +33,20 @@ def parseDeepLabCut(numCams = int(session.numCams) # Get num of camsnumFrames = session.numFrames + 10 # Get num of frames- numPoints = len(bodypartList) # Get amount of points tracked- dlcData_nCams_nFrames_nImgPts_XYC = np.ndarray(- [numCams, numFrames, numPoints, 3]- ) # Create empty array for dlc points+ numImgPoints = len(bodypartList) # Get amount of points tracked+ dlcData_nCams_nFrames_nImgPts_XYC = np.ndarray([numCams, numFrames, numImgPoints, 3]) # Create empty array for dlc pointsnn = 0 # counter for each camerafor data in h5files: # Loop throuxgh each camera+with h5py.File(data) as f: # Open each h5 filefullDataGroup = f.get("df_with_missing") # Open main h5 group- dataTable = fullDataGroup.get(- "table"- ) # Open datatable with all DLC tracked points+ dataTable = fullDataGroup.get("table") # Open datatable with all DLC tracked points+for ii in range(len(dataTable)): # Loop through each framedataFromOneFrame = dataTable[ii] # Assign frame to varibleidx = len(dataFromOneFrame[1]) / 3 # index for reshaping data- sortedFrame = np.array(dataFromOneFrame[1]) # Put data in numoy array+ sortedFrame = np.array(dataFromOneFrame[1]) # Put data in numpy arraydlcData_nCams_nFrames_nImgPts_XYC[nn, ii, :, :] = sortedFrame.reshape(int(idx), 3) # Reshape the data into the correct form@@ -93,9 +91,6 @@ def parseDeepLabCut(plt.show()- np.save(- session.dataArrayPath / "deepLabCutData_2d.npy",- dlcData_nCams_nFrames_nImgPts_XYC,- )+return dlcData_nCams_nFrames_nImgPts_XYCdiff --git a/freemocap/fmc_openpose.py b/freemocap/fmc_openpose.pyindex b9521381..e3ca8a2d 100644--- a/freemocap/fmc_openpose.py+++ b/freemocap/fmc_openpose.py@@ -147,7 +147,7 @@ def parseOpenPose(session):assert thisFrameRow.size == headerLength, ['Header is the wrong length! Should be ' + str(headerLength) + ' but it is ' + str(thisFrameRow.size) + ' Check version of OpenPose?']if frameNum < openPoseData_nCams_nFrames_nImgPts_XYC.shape[1]: #NOTE: THIS SHOULDN"T BE NECESSARY. CURRENT Vid Trim Methods can (apparently) produce vids with off-by-one numbers of frames- openPoseData_nCams_nFrames_nImgPts_XYC[thisCamNum, frameNum, :, :] = np.reshape(thisFrameRow, [137,3]) #hard coding b/c I'm a bad person+ openPoseData_nCams_nFrames_nImgPts_XYC[thisCamNum, frameNum, :, :] = np.reshape(thisFrameRow, [137,3]) #hard coding the number of OpenPose Image Points b/c I'm a bad persondiff --git a/freemocap/fmc_runme.py b/freemocap/fmc_runme.pyindex 817e2325..ebe4ba61 100644--- a/freemocap/fmc_runme.py+++ b/freemocap/fmc_runme.py@@ -20,7 +20,7 @@ from aniposelib.boards import CharucoBoardimport numpy as np-def Run(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,dlcConfigPath=None,debug=False):+def Run(sessionID=None,stage=1,useOpenPose=True, openPoseDummyRun = False, useMediaPipe=False,useDLC=True,dlcConfigPath=None,debug=False):sesh = session.Session()sesh.sessionID = sessionID@@ -39,12 +39,11 @@ def Run(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,d#sesh.dlcConfigPath = Path("C:\\Users\\jonma\\Desktop\\freemocap\\DLC_Models\\PinkGreenRedJugglingBalls-JSM-2021-05-31\\config.yaml")dataFolder = Path.cwd()/'Data'- if dataFolder.exists():+ if dataFolder.exists() and not sesh.sessionID:subfolders = [f.path for f in os.scandir(dataFolder) if f.is_dir()] # copy-pasta from who knows wheresesh.sessionID = Path(subfolders[-1]).stem # grab the name of the last folder in the list of subfolderselse: #First time run! Make 'FreeMoCap_Data' Folder (and eventually, prompt to download sample data)dataFolder.mkdir()- sampleDataFolder = dataFolder / '_sample_data_folder'sampleDataFolder.mkdir()board = CharucoBoard(7, 5,@@ -106,7 +105,7 @@ def Run(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,dnp.save(sesh.dataArrayPath/'mediaPipeSkel_3d.npy', sesh.mediaPipeSkel_fr_mar_dim) #save data to npyif sesh.useOpenPose:- fmc_openpose.runOpenPose(sesh, dummyRun=False)+ fmc_openpose.runOpenPose(sesh, dummyRun=openPoseDummyRun)sesh.openPoseData_nCams_nFrames_nImgPts_XYC = fmc_openpose.parseOpenPose(sesh)sesh.openPoseSkel_fr_mar_dim = reconstruct3D.reconstruct3D(sesh,sesh.openPoseData_nCams_nFrames_nImgPts_XYC, confidenceThreshold=.1)np.save(sesh.dataArrayPath/'openPoseSkel_3d.npy', sesh.openPoseSkel_fr_mar_dim) #save data to npy@@ -116,9 +115,11 @@ def Run(sessionID=None,stage=1,useOpenPose=True,useMediaPipe=False,useDLC=True,dfor vid in sesh.syncedVidPath.glob('*.mp4'):sesh.syncedVidList.append(str(vid))- dlc.analyze_videos(sesh.dlcConfigPath,sesh.syncedVidList, destfolder= sesh.dlcDataPath, save_as_csv=True)+ dlc.analyze_videos(str(sesh.dlcConfigPath),sesh.syncedVidList, destfolder= sesh.dlcDataPath, save_as_csv=True)sesh.dlcData_nCams_nFrames_nImgPts_XYC = fmc_deeplabcut.parseDeepLabCut(sesh)+ np.save(sesh.dataArrayPath / "deepLabCutData_2d.npy", sesh.dlcData_nCams_nFrames_nImgPts_XYC,)+sesh.dlc_fr_mar_dim = reconstruct3D.reconstruct3D(sesh,sesh.dlcData_nCams_nFrames_nImgPts_XYC, confidenceThreshold=.95)np.save(sesh.dataArrayPath/'deepLabCut_3d.npy', sesh.dlc_fr_mar_dim) #save data to npysesh.save_session()diff --git a/freemocap/parameters.yaml b/freemocap/parameters.yamlindex 718b3f3c..bb9c7fff 100644--- a/freemocap/parameters.yaml+++ b/freemocap/parameters.yaml@@ -20,10 +20,14 @@ default:saved:rotations:+ 0: 901: 0- 2: 0+ 2: 90+ 3: 90+ 4: 0+ 5: 270parameters:- exposure: -6+ exposure: -8resWidth: 640resHeight: 480framerate: 30diff --git a/freemocap/playskeleton.py b/freemocap/playskeleton.pyindex 8d00cdd4..704f1008 100644--- a/freemocap/playskeleton.py+++ b/freemocap/playskeleton.py@@ -37,6 +37,7 @@ def ReplaySkeleton_matplotlib(useDLC=False,):+ startFrame = 150mean_charuco_fr_mar_dim = np.load(session.dataArrayPath/'charuco_3d_points.npy')@@ -50,9 +51,8 @@ def ReplaySkeleton_matplotlib(if useDLC:dlc_fr_mar_dim = np.load(session.dataArrayPath / "deepLabCut_3d.npy")- dlc0 = np.squeeze(dlc_fr_mar_dim[:, 0, :])- dlc1 = np.squeeze(dlc_fr_mar_dim[:, 1, :])- dlc2 = np.squeeze(dlc_fr_mar_dim[:, 2, :])+ dlcData_nCams_nFrames_nImgPts_XYC = np.load(session.dataArrayPath / "deepLabCutData_2d.npy")+ballTrailLen = 4if useOpenPose:@@ -64,6 +64,8 @@ def ReplaySkeleton_matplotlib(camImgPathList[cam] = list(sorted(Path(imgPathList[cam]).glob('*.png')))#session.numFrames = len(camImgPathList[cam]) #will need to perhaps put a check in on whether numFrames between cameras are the same+ #get list of synched video paths+ syncedVidPathList = list(sorted(session.syncedVidPath.glob('*.mp4')))# define Skeleton connections# head = [17, 15, 0, 16, 18]@@ -89,12 +91,26 @@ def ReplaySkeleton_matplotlib(fig = plt.figure(figsize=(11, 8))- if vidType == 0:+ if vidType == 0: #no videosaxMain = fig.add_subplot(111, projection="3d")- elif vidType == 1:+ elif vidType == 1: #one video+ numCamSubPlots = 1axMain = fig.add_subplot(121, projection="3d")axCam1 = fig.add_subplot(122)+ #make a list of video capture objects to load images from as needed for later plot+ for camNum in range(numCamSubPlots):+ vidCapObj_list = []+ vidCapObj_list.append(cv2.VideoCapture(str(syncedVidPathList[camNum+1])))++ #read over the frames preceeding startFrame, so that the video will be at the right place in time for the plotting loop+ #(I am doing this b/c I can't figure out how to set the capture object to start reading AT startframe....)+ # SLOPPY TECH DEBT+ for fr in range(startFrame):+ for thisVidObj in enumerate(vidCapObj_list):+ success, image = thisVidObj[1].read()+ assert(success, '{} - Failed to Read Frame'.format(syncedVidPathList[thisVidObj[0]].stem))+# fig.tight_layout(h_pad = 5)axMain.view_init(azim=azimuth, elev=elevation)plt.ion()@@ -116,9 +132,8 @@ def ReplaySkeleton_matplotlib(sk_z = skel_fr_mar_dim[fr, :, 2] # skeleton z dataaxMain.scatter3D(sk_x, sk_y, sk_z, marker=".", color="k", s=4.0)- axMain.plot(- sk_x[head], sk_y[head], sk_z[head], linestyle="-", color="g", linewidth=1.0- )+ axMain.plot(sk_x[head], sk_y[head], sk_z[head], linestyle="-", color="g", linewidth=1.0)+axMain.plot(sk_x[spine],sk_y[spine],@@ -240,318 +255,18 @@ def ReplaySkeleton_matplotlib(color="b",linewidth=1.0,)-- # plot mediapipe- mp_sk_x = mediaPipe_skel_fr_mar_dim[fr, :, 0] # skeleton x data- mp_sk_y = mediaPipe_skel_fr_mar_dim[fr, :, 1] # skeleton y data- mp_sk_z = mediaPipe_skel_fr_mar_dim[fr, :, 2] # skeleton z data- axMain.scatter3D(mp_sk_x, mp_sk_y, mp_sk_z, marker=".", color="g", s=8.0)-- # plot deeplabcut-- dlc_x = dlc_fr_mar_dim[fr, :, 0]- dlc_y = dlc_fr_mar_dim[fr, :, 1]- dlc_z = dlc_fr_mar_dim[fr, :, 2]-- axMain.scatter3D(dlc_x, dlc_y, dlc_z, marker="o", color="r", s=24.0)-- # plot charuco grid- axMain.scatter(char_x, char_y, char_z, marker="o")-- # #plot camera positions (I think...)- # for camNum in range(len(session.cgroup.cameras)):- # axMain.scatter(session.cgroup.cameras[camNum].tvec[0], session.cgroup.cameras[camNum].tvec[1], session.cgroup.cameras[camNum].tvec[2], marker = 'p')- axRange = session.board.square_length * 10- mx = np.nanmean(char_x)- my = np.nanmean(char_y)- mz = np.nanmean(char_z)-- axMain.set_xlim(mx - axRange, mx + axRange)- axMain.set_ylim(my - axRange, my + axRange)- axMain.set_zlim(mz - axRange, mz + axRange)-- axMain.set_xlabel("x")- axMain.set_ylabel("y")- axMain.set_zlabel("z")-- if vidType == 0:- pass- elif vidType == 1:- axCam1.imshow(- cv2.cvtColor(cv2.imread(str(camImgPathList[0][fr])), cv2.COLOR_BGR2RGB)- )- axCam1.axis("off")-- plt.pause(0.01)- plt.show()-- frameName = str(fr).zfill(6)- saveFrameName = "{}.png".format(frameName)- saveFramePath = session.imOutPath / saveFrameName- fig.savefig(saveFramePath)---########################################################################################################################################-########################################################################################################################################-### βββββββ βββββββ ββββββββββββ βββ βββββββ ββ-### ββββββββββββββββββββββββββββββ βββ ββββββββ ββ-### βββ βββββββββββββββββ ββββββ βββ βββ ββββββ-### βββ ββββββββββ ββββββ ββββββββββ βββ βββββ-### ββββββββββββ βββββββββββ ββββββ ββββββββββββββββ-########################################################################################################################################-########################################################################################################################################----def ReplaySkeleton_matplotlib( session,- vidType=1,- startFrame=40,- azimuth=-90,- elevation=-80,- useOpenPose=True,- useMediaPipe=False,- useDLC=False):-- session.imOutPath.mkdir(exist_ok = True)- mean_charuco_fr_mar_dim = np.load(session.dataArrayPath/'charuco_3d_points.npy')--- if session.useMediaPipe:- mediaPipe_skel_fr_mar_dim = np.load(session.dataArrayPath/'mediaPipeSkel_3d.npy')- imgPathList = session.session_settings['mediaPipe_imgPathList']- session.numCams = len(session.mediaPipe_imgPathList)-- if session.useOpenPose:- skel_fr_mar_dim = np.load(session.dataArrayPath/'openPoseSkel_3d.npy')- imgPathList = session.session_settings['openPose_imgPathList']- #session.numCams = len(session.openPose_imgPathList)-- if session.useDLC:- dlc_fr_mar_dim = np.load(session.dataArrayPath / "deepLabCut_3d.npy")- dlc0 = np.squeeze(dlc_fr_mar_dim[:, 0, :])- dlc1 = np.squeeze(dlc_fr_mar_dim[:, 1, :])- dlc2 = np.squeeze(dlc_fr_mar_dim[:, 2, :])- ballTrailLen = 4-- camImgPathList = {}- for cam in range(session.numCams):- camImgPathList[cam] = list(sorted(Path(imgPathList[cam]).glob('*.png')))- #session.numFrames = len(camImgPathList[cam]) #will need to perhaps put a check in on whether numFrames between cameras are the same---# define Skeleton connections-# head = [17, 15, 0, 16, 18]- head = [ 15, 0, 16]- spine = [0,1,8]- rArm = [4 ,3 ,2 ,1]- lArm = [1, 5, 6, 7]- rLeg = [11, 10, 9, 8]- lLeg = [14, 13, 12, 8]- rFoot = [11, 23, 22, 11, 24]- lFoot = [14, 20, 19, 14, 21]-- # Make some handy maps ;D- rHandIDstart = 25- lHandIDstart = rHandIDstart + 21-- thumb = np.array([0, 1, 2, 3, 4])- index = np.array([0, 5, 6, 7, 8])- bird = np.array([0, 9, 10, 11, 12])- ring = np.array([0, 13, 14, 15, 16])- pinky = np.array([0, 17, 18, 19, 20])-- fig = plt.figure(figsize=(11, 8))-- if vidType == 0:- axMain = fig.add_subplot(111, projection="3d")- elif vidType == 1:- axMain = fig.add_subplot(121, projection="3d")- axCam1 = fig.add_subplot(122)-- # fig.tight_layout(h_pad = 5)- axMain.view_init(azim=azimuth, elev=elevation)- plt.ion()- for fr in range(startFrame, session.numFrames):- fig.suptitle(["Frame# - ", str(fr)])- axMain.cla()-- if vidType == 1:- axCam1.cla()-- char_x = mean_charuco_fr_mar_dim[:][:, 0]- char_y = mean_charuco_fr_mar_dim[:][:, 1]- char_z = mean_charuco_fr_mar_dim[:][:, 2]-- # plot skeleton (openPose by default)- if session.useOpenPose:- sk_x = skel_fr_mar_dim[fr, :, 0] # skeleton x data- sk_y = skel_fr_mar_dim[fr, :, 1] # skeleton y data- sk_z = skel_fr_mar_dim[fr, :, 2] # skeleton z data-- axMain.scatter3D(sk_x, sk_y, sk_z, marker=".", color="k", s=4.0)- axMain.plot(- sk_x[head],- sk_y[head],- sk_z[head],- linestyle="-",- color="g",- linewidth=1.0,- )- axMain.plot(- sk_x[spine],- sk_y[spine],- sk_z[spine],- linestyle="-",- color="g",- linewidth=1.0,- )- axMain.plot(- sk_x[rArm],- sk_y[rArm],- sk_z[rArm],- linestyle="-",- color="r",- linewidth=1.0,- )- axMain.plot(- sk_x[lArm],- sk_y[lArm],- sk_z[lArm],- linestyle="-",- color="b",- linewidth=1.0,- )- axMain.plot(- sk_x[rLeg],- sk_y[rLeg],- sk_z[rLeg],- linestyle="-",- color="r",- linewidth=1.0,- )- axMain.plot(- sk_x[lLeg],- sk_y[lLeg],- sk_z[lLeg],- linestyle="-",- color="b",- linewidth=1.0,- )- axMain.plot(- sk_x[rFoot],- sk_y[rFoot],- sk_z[rFoot],- linestyle="-",- color="r",- linewidth=1.0,- )- axMain.plot(- sk_x[lFoot],- sk_y[lFoot],- sk_z[lFoot],- linestyle="-",- color="b",- linewidth=1.0,- )-- # plot handybois- # right hand- axMain.plot(- sk_x[thumb + rHandIDstart],- sk_y[thumb + rHandIDstart],- sk_z[thumb + rHandIDstart],- linestyle="-",- color="r",- linewidth=1.0,- )- axMain.plot(- sk_x[index + rHandIDstart],- sk_y[index + rHandIDstart],- sk_z[index + rHandIDstart],- linestyle="-",- color="r",- linewidth=1.0,- )- axMain.plot(- sk_x[bird + rHandIDstart],- sk_y[bird + rHandIDstart],- sk_z[bird + rHandIDstart],- linestyle="-",- color="r",- linewidth=1.0,- )- axMain.plot(- sk_x[ring + rHandIDstart],- sk_y[ring + rHandIDstart],- sk_z[ring + rHandIDstart],- linestyle="-",- color="r",- linewidth=1.0,- )- axMain.plot(- sk_x[pinky + rHandIDstart],- sk_y[pinky + rHandIDstart],- sk_z[pinky + rHandIDstart],- linestyle="-",- color="r",- linewidth=1.0,- )-- # left hand- axMain.plot(- sk_x[thumb + lHandIDstart],- sk_y[thumb + lHandIDstart],- sk_z[thumb + lHandIDstart],- linestyle="-",- color="b",- linewidth=1.0,- )- axMain.plot(- sk_x[index + lHandIDstart],- sk_y[index + lHandIDstart],- sk_z[index + lHandIDstart],- linestyle="-",- color="b",- linewidth=1.0,- )- axMain.plot(- sk_x[bird + lHandIDstart],- sk_y[bird + lHandIDstart],- sk_z[bird + lHandIDstart],- linestyle="-",- color="b",- linewidth=1.0,- )- axMain.plot(- sk_x[ring + lHandIDstart],- sk_y[ring + lHandIDstart],- sk_z[ring + lHandIDstart],- linestyle="-",- color="b",- linewidth=1.0,- )- axMain.plot(- sk_x[pinky + lHandIDstart],- sk_y[pinky + lHandIDstart],- sk_z[pinky + lHandIDstart],- linestyle="-",- color="b",- linewidth=1.0,- )-- # plot mediapipe- if session.useMediaPipe:+ if useMediaPipe:+ # plot mediapipemp_sk_x = mediaPipe_skel_fr_mar_dim[fr, :, 0] # skeleton x datamp_sk_y = mediaPipe_skel_fr_mar_dim[fr, :, 1] # skeleton y datamp_sk_z = mediaPipe_skel_fr_mar_dim[fr, :, 2] # skeleton z dataaxMain.scatter3D(mp_sk_x, mp_sk_y, mp_sk_z, marker=".", color="g", s=8.0)- # plot deeplabcut- if session.useDLC:+ if useDLC:+ # plot deeplabcutdlc_x = dlc_fr_mar_dim[fr, :, 0]dlc_y = dlc_fr_mar_dim[fr, :, 1]dlc_z = dlc_fr_mar_dim[fr, :, 2]-axMain.scatter3D(dlc_x, dlc_y, dlc_z, marker="o", color="r", s=24.0)# plot charuco grid@@ -576,14 +291,23 @@ def ReplaySkeleton_matplotlib( session,if vidType == 0:passelif vidType == 1:+ success, thisFrameCamImage = vidCapObj_list[0].read() #read image from synched videoaxCam1.imshow(- cv2.cvtColor(cv2.imread(str(camImgPathList[0][fr])), cv2.COLOR_BGR2RGB)+ # cv2.cvtColor(cv2.imread(str(camImgPathList[0][fr])), cv2.COLOR_BGR2RGB)+ cv2.cvtColor(thisFrameCamImage, cv2.COLOR_BGR2RGB))++ if useDLC:+ for camNum in range(numCamSubPlots):+ plt.scatter(dlcData_nCams_nFrames_nImgPts_XYC[camNum,fr,:,0], dlcData_nCams_nFrames_nImgPts_XYC[camNum,fr,:,1], c='red' )+ #draw 2d deeplabcut dataaxCam1.axis("off")plt.pause(0.01)plt.show()+ if not session.imOutPath.exists(): session.imOutPath.mkdir()+frameName = str(fr).zfill(6)saveFrameName = "{}.png".format(frameName)saveFramePath = session.imOutPath / saveFrameNamediff --git a/freemocap_runme_script.py b/freemocap_runme_script.pyindex 837e0334..04ac8938 100644--- a/freemocap_runme_script.py+++ b/freemocap_runme_script.py@@ -1,3 +1,5 @@import freemocap as fmc+from pathlib import Path-fmc.RunMe()\ No newline at end of file+dlcConfigPath = Path(r"C:\Users\jonma\Dropbox\DLC_Models\PinkGreenRedJugglingBalls-JSM-2021-05-31\config.yaml")+fmc.RunMe(stage=4, openPoseDummyRun=True, dlcConfigPath=dlcConfigPath)\ No newline at end of filediff --git a/requirements.txt b/requirements.txtindex 06fb68a4..5f4fdae8 100644--- a/requirements.txt+++ b/requirements.txt@@ -1,7 +1,7 @@aniposelib~=0.4.1h5py>=3.1.0imutils~=0.5.4-matplotlib~=3.1.3+matplotlibmediapipe~=0.8.6opencv-contrib-python~=3.4.14.51pandas~=1.2.5