Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

Merge branch 'DynamicWalking2021_aaron_in_progress' into main

aaroncherian5b8f50d4f00e
diff --cc freemocap/calibrate.py
index 279cb514,74f3e8dc..528b83d3
--- a/freemocap/calibrate.py
+++ b/freemocap/calibrate.py
@@@ -74,16 -75,18 +74,18 @@@ def CalibrateCaptureVolume(session,boar
# init_extrinsics=True)
#%% End of the copy-paste of the inner bits of `cgroup.calibrate_videos` - END
- #JSM NOTE - need add method to extract Charuco board points from the calibrate_videos pipeline
+ #JSM NOTE - need add method to extract Charuco board points from the calibrate_videos pipeline
- ## if you need to save and load
- ## example saving and loading for later
- error,merged = cgroup.calibrate_videos(vidnames, board)
- cgroup.dump(session.cameraCalFilePath) #JSM NOTE - let's just use .yaml's unless there is some reason to use .toml
- mergename = session.sessionPath/'merged.npy'
- np.save(mergename,merged)
- # else:
- # cgroup = CameraGroup.load(session.cameraCalFilePath) #load previous calibration config
+ ## if you need to save and load
+ ## example saving and loading for later
+ if not session.cameraCalFilePath.is_file():
+ error,merged = cgroup.calibrate_videos(vidnames, board)
+ cgroup.dump(session.cameraCalFilePath) #JSM NOTE - let's just use .yaml's unless there is some reason to use .toml
+ mergename = session.sessionPath/'merged.npy'
+ np.save(mergename,merged)
+ else:
+ cgroup = CameraGroup.load(session.cameraCalFilePath) #load previous calibration config
+
session.cgroup = cgroup
n_frames= 40
diff --cc freemocap/fmc_deeplabcut.py
index bd002983,715ce81a..3a947bb5
--- a/freemocap/fmc_deeplabcut.py
+++ b/freemocap/fmc_deeplabcut.py
@@@ -8,63 -8,75 +8,75 @@@ import glo
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
- import matplotlib as mpl
+ import yaml
+ from pathlib import Path
+ import h5py
- def ParseDLCdata(sesh): #note this is all sloppy af just to get a completed video together. Latter iterations will use DLC methods and be smarter about Pandas Dataframs and whatnot
-
+
+
+
+ def parseDeepLabCut(session): # NOTE this is assuming both the dlc config file and dlc data h5 foles are in the same folder specified in the session.dlcDataPath, if that is not the case either dlcconfig or h5files variable need to be changed
+
+ dlcConfig = session.dlcConfigPath #File path for dlcConfig file
+
+
+ with open(dlcConfig) as configFile:
+ #Open the config file
+ configList = yaml.load(configFile, Loader = yaml.FullLoader)
+ for item, doc in configList.items(): #For each item in the config file
+ if item == 'bodyparts': #If the item is bodyparts
+ bodypartList = doc #Set that list to a variable
+ if item == 'skeleton': #If the item is skeleton
+ skeletonList = doc #Set that list to a variable
+
+ h5files =session.dlcDataPath.glob('*.h5') #Take all h5 files from folder
- dlcCSVPaths = sesh.dlcDataPath.glob('*.csv') #NOTE - Super hacky here. Need to fix these methods (replace with DLC native functions?)
-
- numCams = int(sesh.numCams)
- numFrames = sesh.numFrames+1
+ numCams = int(session.numCams)#Get num of cams
+ numFrames = session.numFrames+1#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
+
+ nn=0#counter for each camera
+ for data in h5files:#Loop throuxgh each camera
+ with h5py.File(data) as f:#Open each h5 file
+ fullDataGroup = f.get('df_with_missing')#Open main h5 group
+ dataTable = fullDataGroup.get('table')#Open datatable with all DLC tracked points
+ for ii in range(len(dataTable)):#Loop through each frame
+ dataFromOneFrame = dataTable[ii] #Assign frame to varible
+ idx =(len(dataFromOneFrame[1])/3) #index for reshaping data
+ sortedFrame = np.array(dataFromOneFrame[1]) #Put data in numoy array
+ dlcData_nCams_nFrames_nImgPts_XYC[nn,ii,:,:] =sortedFrame.reshape(int(idx),3) #Reshape the data into the correct form
+ nn+=1
+
+ if session.debug:
+ fig = plt.figure()
- if sesh.sessionID == 'test6_01_21a': #NOTE - THIS IS DUMB AND BAD
- numCols = 8 #this is the number of tracked points in DLC - hardcoding for now because I am a bad person
- else:
- numCols = 3 #NOTE - AGAIN< THIS IS DUMB AND BAD >
-
- dlc_nCams_nFrames_nImgPts_XYC = np.ndarray([numCams, numFrames, numCols, 3])
- dlc_nCams_nFrames_nImgPts_XYC.fill(np.nan)
- camNum = -1
- for thisCSVpath in dlcCSVPaths: #triple nested for loop so I don't have to figure out np.reshape lol
- camNum += 1
- thisCam_dlcDataFrame = pd.read_csv(thisCSVpath, skiprows=1, header = [0,1]) #NOTE - This is dumb and bad. No need for this pandas dataframe, I think
- thisCam_dlcNumpy = thisCam_dlcDataFrame.to_numpy()
- thisCam_dlcNumpy = thisCam_dlcNumpy[:, 1:] #remove first column (frame numbers)
-
- for thisFrame in range(thisCam_dlcNumpy.shape[0]):
- for thisImgPt in range(0,thisCam_dlcNumpy.shape[1],3):
- dlc_nCams_nFrames_nImgPts_XYC[camNum,thisFrame,int(thisImgPt/3), 0] = thisCam_dlcNumpy[thisFrame, thisImgPt]
- dlc_nCams_nFrames_nImgPts_XYC[camNum,thisFrame,int(thisImgPt/3), 1] = thisCam_dlcNumpy[thisFrame, thisImgPt+1]
- dlc_nCams_nFrames_nImgPts_XYC[camNum,thisFrame,int(thisImgPt/3), 2] = thisCam_dlcNumpy[thisFrame, thisImgPt+2]
+ ax1 = fig.add_subplot(221)
+ ax2 = fig.add_subplot(222)
+ ax3 = fig.add_subplot(223)
+ ax4 = fig.add_subplot(224)
+
+ cam1im = session.firstImage_nCams_list[0]
+ cam2im = session.firstImage_nCams_list[1]
+ cam3im = session.firstImage_nCams_list[2]
+ cam4im = session.firstImage_nCams_list[3]
+ ax1.imshow(cam1im)
+ ax1.plot(dlcData_nCams_nFrames_nImgPts_XYC[0,0,:,0],dlcData_nCams_nFrames_nImgPts_XYC[0,0,:,1])
- if sesh.debug:
- fig = plt.figure()
-
- ax1 = fig.add_subplot(221)
- ax2 = fig.add_subplot(222)
- ax3 = fig.add_subplot(223)
- ax4 = fig.add_subplot(224)
-
- cam1im = sesh.firstImage_nCams_list[0]
- cam2im = sesh.firstImage_nCams_list[1]
- cam3im = sesh.firstImage_nCams_list[2]
- cam4im = sesh.firstImage_nCams_list[3]
-
- ax1.imshow(cam1im)
- ax1.plot(dlc_nCams_nFrames_nImgPts_XYC[0,0,:,0],dlc_nCams_nFrames_nImgPts_XYC[0,0,:,1])
+ ax2.imshow(cam2im)
+ ax2.plot(dlcData_nCams_nFrames_nImgPts_XYC[1,0,:,0],dlcData_nCams_nFrames_nImgPts_XYC[1,0,:,1])
- ax2.imshow(cam2im)
- ax2.plot(dlc_nCams_nFrames_nImgPts_XYC[1,0,:,0],dlc_nCams_nFrames_nImgPts_XYC[1,0,:,1])
+ ax3.imshow(cam3im)
+ ax3.plot(dlcData_nCams_nFrames_nImgPts_XYC[2,0,:,0],dlcData_nCams_nFrames_nImgPts_XYC[2,0,:,1])
- ax3.imshow(cam3im)
- ax3.plot(dlc_nCams_nFrames_nImgPts_XYC[2,0,:,0],dlc_nCams_nFrames_nImgPts_XYC[2,0,:,1])
+ ax4.imshow(cam4im)
+ ax4.plot(dlcData_nCams_nFrames_nImgPts_XYC[3,0,:,0],dlcData_nCams_nFrames_nImgPts_XYC[3,0,:,1])
- ax4.imshow(cam4im)
- ax4.plot(dlc_nCams_nFrames_nImgPts_XYC[3,0,:,0],dlc_nCams_nFrames_nImgPts_XYC[3,0,:,1])
+ plt.show()
- plt.show()
-
- sesh.dlc_nCams_nFrames_nImgPts_XYC = dlc_nCams_nFrames_nImgPts_XYC
+ np.save(session.dataArrayPath/'deepLabCutData_2d.npy', dlcData_nCams_nFrames_nImgPts_XYC)
+
- return dlcData_nCams_nFrames_nImgPts_XYC
++ return dlcData_nCams_nFrames_nImgPts_XYC
diff --cc freemocap/playskeleton.py
index 796eb0cf,1144197a..61591890
--- a/freemocap/playskeleton.py
+++ b/freemocap/playskeleton.py
@@@ -249,9 -296,7 +296,6 @@@ def ReplaySkeleton( session
axMain.set_ylabel('y')
axMain.set_zlabel('z')
- axMain.set_xlim(-1000,1000)
- axMain.set_ylim(-1000,1000)
- axMain.set_zlim(1000,3000)
-
if vidType ==0:
pass
diff --cc parameters.yaml
index fc70851d,6d326a0d..6e3a79e9
--- a/parameters.yaml
+++ b/parameters.yaml
@@@ -1,30 -1,28 +1,32 @@@
--#default parameters
--
--
--
--default:
-- rotations: {}
-- parameters:
-- exposure: -5
-- resWidth: 640
-- resHeight: 480
-- framerate: 25
-- codec: DIVX
--
--#saved parameters
--
--
--
--
--saved:
-- rotations:
- 0: 90
- 1: 270
- 2: 90
- 4: 90
- 1: 0
- 2: 0
-- parameters:
- exposure: -7
- exposure: -6
-- resWidth: 640
-- resHeight: 480
-- framerate: 30
-- codec: H264
++#default parameters
++
++
++
++
++default:
++ rotations: {}
++ parameters:
++ exposure: -5
++ resWidth: 640
++ resHeight: 480
++ framerate: 25
++ codec: DIVX
++
++#saved parameters
++
++
++
++
++
++saved:
++ rotations:
++ 0: 90
++ 1: 270
++ 2: 90
++ 4: 90
++ parameters:
++ exposure: -6
++ resWidth: 640
++ resHeight: 480
++ framerate: 30
++ codec: H264