Free Motion Capture for Everyone πβ¨
TypeScript
merging aaron's branch onto pipy (and HOPEFULLY saving aaron's version)
jon matthis2926ff614b20
diff --cc freemocap/calibrate.pyindex ca5f60dd,d3515444..0cf44b5f--- a/freemocap/calibrate.py+++ b/freemocap/calibrate.py@@@ -10,14 -10,18 +10,19 @@@ import ofrom rich.progress import track+def CalibrateCaptureVolume(session, board):+ def CalibrateCaptureVolume(session,board):++ session.calVidPath.mkdir(exist_ok = True)+ session.dataArrayPath.mkdir(exist_ok = True)+calVideoFrameLength = 60- createCalibrationVideos(session,calVideoFrameLength)+ createCalibrationVideos(session, calVideoFrameLength)- vidnames = []- cam_names = []- for count,thisVidPath in enumerate(session.calVidPath.glob('*.mp4'),start=1):+ vidnames = []+ cam_names = []+ for count, thisVidPath in enumerate(session.calVidPath.glob("*.mp4"), start=1):vidnames.append([str(thisVidPath)])cam_names.append(str(count))session.numCams = count@@@ -65,55 -69,53 +70,68 @@@# ax.set_xlim(ymin, ymax)plt.show()---#%% This next bit is a copy-paste of the inner bits of `cgroup.calibrate_videos` - Part 2 of 2- #error, merged = cgroup.calibrate_rows(all_rows, board,- # init_intrinsics=True,- # init_extrinsics=True)-#%% End of the copy-paste of the inner bits of `cgroup.calibrate_videos` - END+ #%% This next bit is a copy-paste of the inner bits of `cgroup.calibrate_videos` - Part 2 of 2+ # error, merged = cgroup.calibrate_rows(all_rows, board,+ # init_intrinsics=True,+ # 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++ ## 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+ #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+ 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.dataArrayPath/'charuco_2d_points.npy'+ np.save(mergename,merged)+ else:+ cgroup = CameraGroup.load(session.cameraCalFilePath) #load previous calibration config++session.cgroup = cgroup- n_frames= 40+ n_frames = 40startframe = 0n_trackedPoints = 24- framelist = range(startframe,startframe+n_frames)+ framelist = range(startframe, startframe + n_frames)- charucoarray = np.empty([session.numCams,n_frames,n_trackedPoints,1,2])+ charucoarray = np.empty([session.numCams, n_frames, n_trackedPoints, 1, 2])charucoarray[:] = np.nan- data = np.load(session.sessionPath / "merged.npy", allow_pickle=True)+ data = np.load(session.dataArrayPath/'charuco_2d_points.npy',allow_pickle = True)for cam in range(session.numCams):- for count,frame in enumerate(framelist):+ for count, frame in enumerate(framelist):try:- charucoarray[cam][count] = data[frame][cam]['filled']- except:- print('failed frame:', frame)+ charucoarray[cam][count] = data[frame][cam]["filled"]+ except:+ print("failed frame:", frame)continuecharuco_nCams_nFrames_nImgPts_XY = np.squeeze(np.array(charucoarray))-+session.charuco_nCams_nFrames_nImgPts_XY = charuco_nCams_nFrames_nImgPts_XY-- charuco_fr_mar_dim = reconstruct3D.reconstruct3D(session,charuco_nCams_nFrames_nImgPts_XY)-- mean_charuco_fr_mar_dim = np.nanmean(charuco_fr_mar_dim,axis = 0)+ charuco_fr_mar_dim = reconstruct3D.reconstruct3D(+ session, charuco_nCams_nFrames_nImgPts_XY+ )++ mean_charuco_fr_mar_dim = np.nanmean(charuco_fr_mar_dim, axis=0)# charry_reshaped = charucoarray.reshape(session.numCams, -1, 2)@@@ -169,40 -169,33 +187,40 @@@# ax2.set_title('Charuco Point positions over time')plt.show()- path_to_charuco_array = session.dataArrayPath / "charuco_points.npy"+ path_to_charuco_array = session.dataArrayPath/'charuco_3d_points.npy'np.save(path_to_charuco_array, mean_charuco_fr_mar_dim)- return cgroup,mean_charuco_fr_mar_dim+ return cgroup, mean_charuco_fr_mar_dim+-def createCalibrationVideos(session,calVideoFrameLength):+def createCalibrationVideos(session, calVideoFrameLength):vidList = os.listdir(session.syncedVidPath)framelist = list(range(calVideoFrameLength))- codec = 'DIVX'- for count,vid in enumerate(vidList,start=1):+ codec = "DIVX"+ for count, vid in enumerate(vidList, start=1):cam_name = "Cam{}".format(count)- cap = cv2.VideoCapture(str(session.syncedVidPath/vid))+ cap = cv2.VideoCapture(str(session.syncedVidPath / vid))fourcc = cv2.VideoWriter_fourcc(*codec)-- #grab resolution parameters from the videos- resWidth = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))++ # grab resolution parameters from the videos+ resWidth = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))resHeight = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))framerate = int(cap.get(cv2.CAP_PROP_FPS))-- saveName = session.sessionID +'_trimmed_' + cam_name + '.mp4' #create a name for the trimmed video- saveCalVidPath = str(session.calVidPath/saveName) #create an output path for the function-- success, image = cap.read() #start reading frames-- out = cv2.VideoWriter(saveCalVidPath, fourcc, framerate, (resWidth,resHeight))- print('Trimming ' + cam_name)++ saveName = (+ session.sessionID + "_trimmed_" + cam_name + ".mp4"+ ) # create a name for the trimmed video+ saveCalVidPath = str(+ session.calVidPath / saveName+ ) # create an output path for the function++ success, image = cap.read() # start reading frames++ out = cv2.VideoWriter(saveCalVidPath, fourcc, framerate, (resWidth, resHeight))+ print("Trimming " + cam_name)for frame in track(framelist):- cap.set(cv2.CAP_PROP_POS_FRAMES, frame) #set the video to the frame that we need+ cap.set(+ cv2.CAP_PROP_POS_FRAMES, frame+ ) # set the video to the frame that we needsuccess, image = cap.read()out.write(image)cap.release()diff --cc freemocap/createvideo.pyindex d5aeb3f8,7462a8b2..2c790db2--- a/freemocap/createvideo.py+++ b/freemocap/createvideo.py@@@ -37,27 -37,21 +37,31 @@@ def createBodyTrackingVideos(session)if session.useOpenPose:++<<<<<<< HEAD+ for count, videoPath in enumerate(+ session.config_settings["openPose_imgPathList"]+ ):++=======+ for count,videoPath in enumerate(session.session_settings['openPose_imgPathList']):++>>>>>>> merge-pipy-aaronframe_array = []- vidSavePath = str(session.openPoseDataPath/'openPoseVideo_cam{}.mp4'.format(count))+ vidSavePath = str(+ session.openPoseDataPath / "openPoseVideo_cam{}.mp4".format(count)+ )videoPath = Path(videoPath)- for filename in videoPath.glob('*.png'):-- filename= str(filename)- #reading each files+ for filename in videoPath.glob("*.png"):++ filename = str(filename)+ # reading each filesimg = cv2.imread(filename)- #resized = cv2.resize(img,shape)- #shape = img.shape[:2]- resized = cv2.resize(img,shape)- #inserting the frames into an image array+ # resized = cv2.resize(img,shape)+ # shape = img.shape[:2]+ resized = cv2.resize(img, shape)+ # inserting the frames into an image arrayframe_array.append(resized)- out = cv2.VideoWriter(vidSavePath,cv2.VideoWriter_fourcc(*'DIVX'), fps, shape)+ out = cv2.VideoWriter(+ vidSavePath, cv2.VideoWriter_fourcc(*"DIVX"), fps, shape+ )for i in range(len(frame_array)):# writing to a image arrayout.write(frame_array[i])diff --cc freemocap/fmc_openpose.pyindex 033ed2bb,20debb1d..89758940--- a/freemocap/fmc_openpose.py+++ b/freemocap/fmc_openpose.py@@@ -41,158 -31,102 +41,254 @@@ def runOpenPose(session, dummyRun=FalseopenPose_imgPathList_yaml.append(str(imgPath))openPose_jsonPathList_yaml.append(str(jsonPath))if not dummyRun:- subprocess.run(['bin\OpenPoseDemo.exe', '--video', str(thisVidPath), '--write_json', str(jsonPath),'--write_images', str(imgPath),'--write_images_format','png','--net_resolution','-1x320','--hand','--face', '--number_people_max', '1'],shell = True)+ subprocess.run(+ [+ "bin\OpenPoseDemo.exe",+ "--video",+ str(thisVidPath),+ "--write_json",+ str(jsonPath),+ "--write_images",+ str(imgPath),+ "--write_images_format",+ "png",+ "--net_resolution",+ "-1x320",+ "--hand",+ "--face",+ "--number_people_max",+ "1",+ ],+ shell=True,+ )else:- print('Skipping: ', thisVidPath.name )+ print("Skipping: ", thisVidPath.name)session.openPose_jsonPathList = openPose_jsonPathListsession.openPose_imgPathList = openPose_imgPathList++<<<<<<< HEAD++ yaml = YAML()+ data = yaml.load(session.yamlPath)+ data["openPose_imgPathList"] = openPose_imgPathList_yaml+ data["openPose_jsonPathList"] = openPose_jsonPathList_yaml+ yaml.dump(data, session.yamlPath)+++=======++ session.session_settings['openPose_imgPathList'] = openPose_imgPathList_yaml+ session.session_settings['openPose_jsonPathList'] = openPose_jsonPathList_yaml+ # yaml = YAML()+ # data = yaml.load(session.session_yaml_path)+ # data['openPose_imgPathList'] = openPose_imgPathList_yaml+ # data['openPose_jsonPathList'] = openPose_jsonPathList_yaml+ # yaml.dump(data, session.session_yaml_path)+++>>>>>>> merge-pipy-aaronos.chdir(session.sessionPath)-++# @jit(nopython=True)def parseOpenPose(session):++<<<<<<< HEAD+ thisCamNum = -1++ ## %%+ # build header for dataframe - NOTE - #openpose data comes in a line ordered 'pixel x location (px)', 'pixel y (py)', 'confidence (conf)' for each keypoint++ dataFrameHeader = []+ bodyCols = 75+ handCols = 63 # per hand+ faceCols = 210 # das alotta face!+ headerLength = (+ bodyCols + 2 * handCols + faceCols+ ) # should be 411 for whatever version of openpose i was using on 11 Jan 2021+ numImgPoints = headerLength++ for bb in range(+ 0, int(bodyCols / 3)+ ): # loop through the number of body markers (i.e. #bodyCols/3)+ dataFrameHeader.append("body_" + str(bb).zfill(3) + "_pixx")+ dataFrameHeader.append("body_" + str(bb).zfill(3) + "_pixy")+ dataFrameHeader.append("body_" + str(bb).zfill(3) + "_conf")++ for hr in range(+ 0, int(handCols / 3)+ ): # loop through the number of handR markers (i.e. #handCols/3)+ dataFrameHeader.append("handR_" + str(hr).zfill(3) + "_pixx")+ dataFrameHeader.append("handR_" + str(hr).zfill(3) + "_pixy")+ dataFrameHeader.append("handR_" + str(hr).zfill(3) + "_conf")++ for hl in range(+ 0, int(handCols / 3)+ ): # loop through the number of handL markers (i.e. #handCols/3)+ dataFrameHeader.append("handL_" + str(hl).zfill(3) + "_pixx")+ dataFrameHeader.append("handL_" + str(hl).zfill(3) + "_pixy")+ dataFrameHeader.append("handL_" + str(hl).zfill(3) + "_conf")++ for ff in range(+ 0, int(faceCols / 3)+ ): # loop through the number of Face markers (i.e. #faceCols/3)+ dataFrameHeader.append("face_" + str(ff).zfill(3) + "_pixx")+ dataFrameHeader.append("face_" + str(ff).zfill(3) + "_pixy")+ dataFrameHeader.append("face_" + str(ff).zfill(3) + "_conf")++ assert len(dataFrameHeader) == headerLength, [+ "Header is the wrong length! Should be "+ + str(headerLength)+ + " but it is "+ + str(len(dataFrameHeader))+ + " Check version of OpenPose?"+ ]++ ## %%+ ## load in data from json files+ numFrames = int(len(list(Path(session.openPose_jsonPathList[0]).glob("*")))) # lol+ numMarkers = int(int(len(dataFrameHeader) / 3))+ numCams = int(session.numCams)++ openPoseData_nCams_nFrames_nImgPts_XYC = np.ndarray(+ [numCams, numFrames, numMarkers, 3]+ ) # hardcoding for now because I am a bad person++ for thisCams_JsonFolderPath in track(+ session.openPose_jsonPathList,+ description="Parsing json's into a dataframe (per cam)",+ ):+ thisCamNum += 1+ # print('Parsing into a dataframe: ', thisCams_JsonFolderPath.name )+ jsonPaths = sorted(+ Path(thisCams_JsonFolderPath).glob("*.json")+ ) # glob is a "generator(?)" for paths to all the jason for THIS camara++ for (+ thisJsonPath+ ) in (+ jsonPaths+ ): # loop throug all the json files and save their 'people' data to a dictionary (which will then be formatted into a pandas dataframe). NOTE - will be empty array if no hoomans visible in frame+ # print('loading: ', thisJsonPath.name)+ frameNum = int(thisJsonPath.stem.split("_")[-2]) # frame number we're on+ thisJsonData = json.loads(thisJsonPath.read_bytes())+ thisJsonData = thisJsonData[+ "people"+ ] # #FEATURE_REQUEST - at some point, we should check the openpose version (save it with the data somehow, verify everything is the same version, use different markernamlists for different versions, etc)++ if thisJsonData: # if this json has data+ bodyData = np.array(thisJsonData[0]["pose_keypoints_2d"])+ handRData = np.array(thisJsonData[0]["hand_right_keypoints_2d"])+ handLData = np.array(thisJsonData[0]["hand_left_keypoints_2d"])+ faceData = np.array(thisJsonData[0]["face_keypoints_2d"])+ thisFrameRow = np.hstack(+ (bodyData, handRData, handLData, faceData)+ ) # horizontally concatenate these arrays+ else: # if this json is empty, just stuff it fulla NaNs+ thisFrameRow = np.empty([headerLength])+ thisFrameRow.fill(np.nan)++ 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++ # session.dataFrameHeader = dataFrameHeader+ # session.numImgPoints = numImgPoints+ session.numFrames = frameNum # NOTE - Need to find a safer way to get this number++ path_to_openpose_2d = session.dataArrayPath / "openPoseData_2d.npy"+ np.save(path_to_openpose_2d, openPoseData_nCams_nFrames_nImgPts_XYC)++ return openPoseData_nCams_nFrames_nImgPts_XYC++=======+ thisCamNum = -1++ ## %%+ #build header for dataframe - NOTE - #openpose data comes in a line ordered 'pixel x location (px)', 'pixel y (py)', 'confidence (conf)' for each keypoint++ dataFrameHeader = []+ bodyCols = 75+ handCols = 63 #per hand+ faceCols = 210 #das alotta face!+ headerLength = bodyCols + 2*handCols + faceCols#should be 411 for whatever version of openpose i was using on 11 Jan 2021+ numImgPoints = headerLength++ for bb in range(0,int(bodyCols/3)): #loop through the number of body markers (i.e. #bodyCols/3)+ dataFrameHeader.append('body_' + str(bb).zfill(3) + '_pixx')+ dataFrameHeader.append('body_' + str(bb).zfill(3) + '_pixy')+ dataFrameHeader.append('body_' + str(bb).zfill(3) + '_conf')++ for hr in range(0,int(handCols/3)): #loop through the number of handR markers (i.e. #handCols/3)+ dataFrameHeader.append('handR_' + str(hr).zfill(3) + '_pixx')+ dataFrameHeader.append('handR_' + str(hr).zfill(3) + '_pixy')+ dataFrameHeader.append('handR_' + str(hr).zfill(3) + '_conf')++ for hl in range(0,int(handCols/3)): #loop through the number of handL markers (i.e. #handCols/3)+ dataFrameHeader.append('handL_' + str(hl).zfill(3) + '_pixx')+ dataFrameHeader.append('handL_' + str(hl).zfill(3) + '_pixy')+ dataFrameHeader.append('handL_' + str(hl).zfill(3) + '_conf')++ for ff in range(0,int(faceCols/3)): #loop through the number of Face markers (i.e. #faceCols/3)+ dataFrameHeader.append('face_' + str(ff).zfill(3) + '_pixx')+ dataFrameHeader.append('face_' + str(ff).zfill(3) + '_pixy')+ dataFrameHeader.append('face_' + str(ff).zfill(3) + '_conf')++ assert len(dataFrameHeader) == headerLength, ['Header is the wrong length! Should be ' + str(headerLength) + ' but it is ' + str(len(dataFrameHeader)) + ' Check version of OpenPose?']++ ## %%+ ## load in data from json files+ #numFrames = int(len(list(Path(session.openPose_jsonPathList[0]).glob('*')))) #lol+ numFrames = session.numFrames+ numMarkers= int(int(len(dataFrameHeader)/3))+ numCams = int(session.numCams)++ openPoseData_nCams_nFrames_nImgPts_XYC = np.ndarray([numCams,numFrames,numMarkers,3]) #hardcoding for now because I am a bad person++ for thisCams_JsonFolderPath in track(session.openPose_jsonPathList, description='Parsing json\'s into a dataframe (per cam)' ):+ thisCamNum += 1+ # print('Parsing into a dataframe: ', thisCams_JsonFolderPath.name )+ jsonPaths = sorted(Path(thisCams_JsonFolderPath).glob('*.json')) #glob is a "generator(?)" for paths to all the jason for THIS camara++ for thisJsonPath in jsonPaths: #loop throug all the json files and save their 'people' data to a dictionary (which will then be formatted into a pandas dataframe). NOTE - will be empty array if no hoomans visible in frame+ # print('loading: ', thisJsonPath.name)+ frameNum = int(thisJsonPath.stem.split('_')[-2]) #frame number we're on+ thisJsonData = json.loads(thisJsonPath.read_bytes())+ thisJsonData = thisJsonData['people'] # #FEATURE_REQUEST - at some point, we should check the openpose version (save it with the data somehow, verify everything is the same version, use different markernamlists for different versions, etc)++ if thisJsonData: #if this json has data+ bodyData = np.array(thisJsonData[0]['pose_keypoints_2d'])+ handRData = np.array(thisJsonData[0]['hand_right_keypoints_2d'])+ handLData = np.array(thisJsonData[0]['hand_left_keypoints_2d'])+ faceData = np.array(thisJsonData[0]['face_keypoints_2d'])+ thisFrameRow = np.hstack((bodyData,handRData, handLData, faceData)) #horizontally concatenate these arrays+ else: #if this json is empty, just stuff it fulla NaNs+ thisFrameRow = np.empty([headerLength])+ thisFrameRow.fill(np.nan)+++ 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+++++ # session.dataFrameHeader = dataFrameHeader+ # session.numImgPoints = numImgPoints+ #session.numFrames = frameNum #NOTE - Need to find a safer way to get this number++ path_to_openpose_2d = session.dataArrayPath/'openPoseData_2d.npy'+ np.save(path_to_openpose_2d, openPoseData_nCams_nFrames_nImgPts_XYC)+- return openPoseData_nCams_nFrames_nImgPts_XYC++ return openPoseData_nCams_nFrames_nImgPts_XYC++>>>>>>> merge-pipy-aarondiff --cc freemocap/fmc_pyqtgraph.pyindex 8c8eddc1,ccc6272e..cc9b7223--- a/freemocap/fmc_pyqtgraph.py+++ b/freemocap/fmc_pyqtgraph.py@@@ -200,19 -102,20 +200,24 @@@ class PlaySkeletonWidgetself.Skel3dViewWidget.addItem(self.dlc2LineItem)self.tailLength = 10---++<<<<<<< HEAD+ self.charuco_mar_dim = np.load(session.dataArrayPath / "charuco_points.npy")+ self.charucoScatterItem = gl.GLScatterPlotItem(+ pos=self.charuco_mar_dim, color=(1, 1, 1, 0.8), size=10, pxMode=False+ )++=======+ self.charuco_mar_dim = np.load(session.dataArrayPath/'charuco_3d_points.npy')+ self.charucoScatterItem = gl.GLScatterPlotItem(pos=self.charuco_mar_dim, color=(1,1,1,.8), size=10, pxMode=False)++>>>>>>> merge-pipy-aaronself.Skel3dViewWidget.addItem(self.charucoScatterItem)- #plot videos Frames!+ # plot videos Frames!- #set frame counter+ # set frame counterself.currentFrameNumber = 0- self.framerate = 50 #frames per second- self.frameDuration = 1000/self.framerate #milliseconds+ self.framerate = 50 # frames per second+ self.frameDuration = 1000 / self.framerate # milliseconds# def start(self):# if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):diff --cc freemocap/parameters.yamlindex 92b9b5df,6d326a0d..057e4e87--- a/freemocap/parameters.yaml+++ b/freemocap/parameters.yaml@@@ -17,15 -16,12 +16,19 @@@ default-saved:rotations:++<<<<<<< HEAD:parameters.yaml+ 0: 90+ 1: 270+ 2: 90+ 3: 270++=======+ 1: 0+ 2: 0++>>>>>>> merge-pipy-aaron:freemocap/parameters.yamlparameters:- exposure: -8+ exposure: -6resWidth: 640resHeight: 480framerate: 30diff --cc freemocap/playskeleton.pyindex e8eae815,56f0b57a..8061a9eb--- a/freemocap/playskeleton.py+++ b/freemocap/playskeleton.py@@@ -13,86 -12,83 +13,107 @@@ import cvfrom pathlib import Pathimport pyqtgraph as pg-################################################################################################################################################################################################################################################################################-##-## ββββ ββββ ββββββ ββββββββββββββββ βββ βββββββ ββββββββββββ ββββββββββ-## βββββ βββββββββββββββββββββββββββββββββ βββββββββββββββββββββ βββββββββββ-## βββββββββββββββββββ βββ βββββββββββ βββ βββ βββ βββ βββββββββββ-## βββββββββββββββββββ βββ βββββββ βββ βββ βββ βββ βββ βββββββββββ-## βββ βββ ββββββ βββ βββ βββ βββββββββββββββββ βββ βββββββββββββββββββ-## βββ ββββββ βββ βββ βββ ββββββββ βββββββ βββ ββββββββββββββββββ-########################################################################################################################################+########################################################################################################################################+##+## ββββ ββββ ββββββ ββββββββββββββββ βββ βββββββ ββββββββββββ βββββββββ+## βββββ βββββββββββββββββββββββββββββββββ βββββββββββββββββββββ ββββββββββ+## βββββββββββββββββββ βββ βββββββββββ βββ βββ βββ βββ βββββββββ+## βββββββββββββββββββ βββ βββββββ βββ βββ βββ βββ βββ ββββββββββ+## βββ βββ ββββββ βββ βββ βββ βββββββββββββββββ βββ βββββββββββββββββ+##+################################################################################################################################################################################################################################################################################-def ReplaySkeleton_matplotlib( session,- vidType=1,- startFrame=40,- azimuth=-90,- elevation=-80,- useOpenPose=True,- useMediaPipe=False,- useDLC=False):+def ReplaySkeleton_matplotlib(+ session,+ vidType=1,+ startFrame=40,+ azimuth=-90,+ elevation=-80,+ useOpenPose=True,+ useMediaPipe=False,+ useDLC=False,+):+++<<<<<<< HEAD+ mean_charuco_fr_mar_dim = np.load(session.dataArrayPath / "charuco_points.npy")++=======++ mean_charuco_fr_mar_dim = np.load(session.dataArrayPath/'charuco_3d_points.npy')++>>>>>>> merge-pipy-aaronif useOpenPose:- skel_fr_mar_dim = np.load(session.dataArrayPath/'openPoseSkel_3d.npy')+ skel_fr_mar_dim = np.load(session.dataArrayPath / "openPoseSkel_3d.npy")if useMediaPipe:- mediaPipe_skel_fr_mar_dim = np.load(session.dataArrayPath/'mediaPipeSkel_3d.npy')-+ mediaPipe_skel_fr_mar_dim = np.load(+ session.dataArrayPath / "mediaPipeSkel_3d.npy"+ )+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,:])+ 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-if useOpenPose:++<<<<<<< HEAD+ imgPathList = session.config_settings["openPose_imgPathList"]+ session.numCams = len(session.openPose_imgPathList)++ 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]++=======+ imgPathList = session.session_settings['openPose_imgPathList']+++ 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]++>>>>>>> merge-pipy-aaronrArm = [17, 15, 0, 16, 18]- rArm = [4 ,3 ,2 ,1]+ 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]+ 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])+ # 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))+ fig = plt.figure(figsize=(11, 8))if vidType == 0:- axMain = fig.add_subplot(111,projection='3d')+ axMain = fig.add_subplot(111, projection="3d")elif vidType == 1:- axMain = fig.add_subplot(121,projection='3d')+ axMain = fig.add_subplot(121, projection="3d")axCam1 = fig.add_subplot(122)# fig.tight_layout(h_pad = 5)@@@ -302,72 -203,77 +323,112 @@@########################################################################################################################################+def ReplaySkeleton_matplotlib(+ session,+ vidType=1,+ startFrame=40,+ azimuth=-90,+ elevation=-80,+ useOpenPose=True,+ useMediaPipe=False,+ useDLC=False,+):++<<<<<<< HEAD+ mean_charuco_fr_mar_dim = np.load(session.dataArrayPath / "charuco_points.npy")++ if session.useMediaPipe:+ mediaPipe_skel_fr_mar_dim = np.load(+ session.dataArrayPath / "mediaPipeSkel_3d.npy"+ )+ imgPathList = session.config_settings["mediaPipe_imgPathList"]++=======+++ 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']++>>>>>>> merge-pipy-aaronsession.numCams = len(session.mediaPipe_imgPathList)-if session.useOpenPose:++<<<<<<< HEAD+ skel_fr_mar_dim = np.load(session.dataArrayPath / "openPoseSkel_3d.npy")+ imgPathList = session.config_settings["openPose_imgPathList"]+ session.numCams = len(session.openPose_imgPathList)+++=======+ skel_fr_mar_dim = np.load(session.dataArrayPath/'openPoseSkel_3d.npy')+ imgPathList = session.session_settings['openPose_imgPathList']+ #session.numCams = len(session.openPose_imgPathList)+++>>>>>>> merge-pipy-aaronif 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,:])+ 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):++<<<<<<< HEAD+ 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]++=======+ 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]++>>>>>>> merge-pipy-aaronlArm = [1, 5, 6, 7]- rLeg = [11 ,10, 9, 8]- lLeg = [14 ,13 ,12, 8]- rFoot = [11, 23,22, 11, 24]+ 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+ # 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])+ 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))+ fig = plt.figure(figsize=(11, 8))if vidType == 0:- axMain = fig.add_subplot(111,projection='3d')+ axMain = fig.add_subplot(111, projection="3d")elif vidType == 1:- axMain = fig.add_subplot(121,projection='3d')+ axMain = fig.add_subplot(121, projection="3d")axCam1 = fig.add_subplot(122)# fig.tight_layout(h_pad = 5)diff --cc freemocap/recordingconfig.pyindex 2539e609,d1692375..2ecca474--- a/freemocap/recordingconfig.py+++ b/freemocap/recordingconfig.py@@@ -4,136 -4,141 +4,254 @@@ Created on Thu Mar 11 11:54:12 202@author: Rontc"""- from ruamel.yaml import YAML- from pathlib import Path++<<<<<<< HEAD++def createSession(session, filepath, existing_data=False):+ # create file paths for the session, raw and synced videos++ pathList = []++ recordPath = filepath / "Data"+ recordPath.mkdir(exist_ok=True)++ session.sessionPath = recordPath / session.sessionID+ # if existing_data:+ # session.sessionPath.mkdir(exist_ok = True)+ # else:+ session.sessionPath.mkdir(exist_ok=True)+ pathList.append(session.sessionPath)++ session.rawVidPath = session.sessionPath / "RawVideos"+ session.rawVidPath.mkdir(exist_ok=True)+ pathList.append(session.rawVidPath)++ session.syncedVidPath = session.sessionPath / "SyncedVideos"+ session.syncedVidPath.mkdir(exist_ok=True)+ pathList.append(session.syncedVidPath)++ session.calVidPath = session.sessionPath / "CalVideos"+ session.calVidPath.mkdir(exist_ok=True)+ pathList.append(session.calVidPath)++ session.openPoseDataPath = session.sessionPath / "OpenPoseData"+ session.openPoseDataPath.mkdir(exist_ok=True)+ pathList.append(session.openPoseDataPath)++ session.mediaPipeDataPath = session.sessionPath / "MediaPipeData"+ session.mediaPipeDataPath.mkdir(exist_ok=True)+ pathList.append(session.mediaPipeDataPath)++ session.dlcDataPath = session.sessionPath / "DLCdata"+ session.dlcDataPath.mkdir(exist_ok=True, parents=True)+ pathList.append(session.dlcDataPath)++ session.imOutPath = session.sessionPath / "imOut"+ session.imOutPath.mkdir(exist_ok=True)+ pathList.append(session.imOutPath)++ session.dataArrayPath = session.sessionPath / "Data Arrays"+ session.dataArrayPath.mkdir(exist_ok=True)+ pathList.append(session.dataArrayPath)++ # create a list of paths that is passed to the recording script+ # pathList = [session.sessionPath,session.rawVidPath,session.syncedVidPath,session.openPoseDataPath,session.dlcDataPath,session.imOutPath, session.dataArrayPath]++ config_settings, config_yaml = create_config_yaml()+ session.config_settings = config_settings++ yaml_name = session.sessionPath / "{}_config.yaml".format(session.sessionID)+ session.yamlPath = yaml_name+ # print(yaml_name)+ write_config_yaml(session, config_settings, config_yaml, pathList, yaml_name)++ return yaml_name+++def createSessionTxt(session, paramDict, rotDict):+ # create a text file listing recording parameters+ parameter_text = session.sessionPath / "sessionSettings.txt"+ text = open(parameter_text, "w")+ text.write("Session ID = %s\n" % (session.sessionID))+ text.write("%s = %s\n" % ("Parameters", paramDict))+ text.write("%s = %s\n" % ("Rotations", rotDict))+ text.close()+++=======+ folder_setup = ['RawVideos','SyncedVideos','CalVideos','DataArrays','DLCData','OpenPoseData','MediaPipeData','imOut']+++++ # def createSession(session,filepath, existing_data = False):+ # #create file paths for the session, raw and synced videos++ # pathList = []++ # recordPath = filepath/'Data'+ # recordPath.mkdir(exist_ok= True)++ # session.sessionPath = recordPath/session.sessionID+ # #if existing_data:+ # #session.sessionPath.mkdir(exist_ok = True)+ # #else:+ # session.sessionPath.mkdir(exist_ok= True)+ # pathList.append(session.sessionPath)++ # session.rawVidPath = session.sessionPath/'RawVideos'+ # session.rawVidPath.mkdir(exist_ok = True)+ # pathList.append(session.rawVidPath)++ # session.syncedVidPath = session.sessionPath/'SyncedVideos'+ # session.syncedVidPath.mkdir(exist_ok = True)+ # pathList.append(session.syncedVidPath)++ # session.calVidPath = session.sessionPath/'CalVideos'+ # session.calVidPath.mkdir(exist_ok = True)+ # pathList.append(session.calVidPath)++ # session.openPoseDataPath = session.sessionPath/'OpenPoseData'+ # session.openPoseDataPath.mkdir(exist_ok = True)+ # pathList.append(session.openPoseDataPath)++ # session.mediaPipeDataPath = session.sessionPath/'MediaPipeData'+ # session.mediaPipeDataPath.mkdir(exist_ok = True)+ # pathList.append(session.mediaPipeDataPath)++ # session.dlcDataPath = session.sessionPath / 'DLCdata'+ # session.dlcDataPath.mkdir(exist_ok = True, parents = True)+ # pathList.append(session.dlcDataPath)++ # session.imOutPath = session.sessionPath / 'imOut'+ # session.imOutPath.mkdir(exist_ok=True)+ # pathList.append(session.imOutPath)++ # session.dataArrayPath = session.sessionPath/'Data Arrays'+ # session.dataArrayPath.mkdir(exist_ok=True)+ # pathList.append(session.dataArrayPath)++ # #create a list of paths that is passed to the recording script+ # #pathList = [session.sessionPath,session.rawVidPath,session.syncedVidPath,session.openPoseDataPath,session.dlcDataPath,session.imOutPath, session.dataArrayPath]+++ # config_settings,config_yaml = create_config_yaml()+ # session.config_settings = config_settings++ # yaml_name = session.sessionPath/'{}_config.yaml'.format(session.sessionID)+ # session.yamlPath = yaml_name+ # # print(yaml_name)+ # write_config_yaml(session,config_settings,config_yaml,pathList,yaml_name)++ # return yaml_name++ # def createSessionTxt(session,paramDict,rotDict):+ # #create a text file listing recording parameters+ # parameter_text = session.sessionPath/'sessionSettings.txt'+ # text = open(parameter_text, 'w')+ # text.write("Session ID = %s\n" %(session.sessionID))+ # text.write("%s = %s\n" %("Parameters", paramDict))+ # text.write("%s = %s\n" %("Rotations", rotDict))+ # text.close()+++++ # def create_config_yaml():++>>>>>>> merge-pipy-aaron+def create_config_yaml():- yaml_str = """\- # Camera Inputs- CamInputs:- RotationInputs:- ParameterDict:-- # Paths- Paths:- sessionPath:- rawVidPath:- syncedVidPath:- calVidPath:- openPoseDataPath:- mediaPipeDataPath:- dlcDataPath:- imOutPath:- dataArrayPath:- \n- """- config_yaml = YAML()- config_settings = config_yaml.load(yaml_str)-+ # yaml_str = """\+ # # Camera Inputs+ # CamInputs:+ # RotationInputs:+ # ParameterDict:++ # # Paths+ # Paths:+ # sessionPath:+ # rawVidPath:+ # syncedVidPath:+ # calVidPath:+ # openPoseDataPath:+ # mediaPipeDataPath:+ # dlcDataPath:+ # imOutPath:+ # dataArrayPath:+ # \n+ # """+ # config_yaml = YAML()+ # config_settings = config_yaml.load(yaml_str)+++<<<<<<< HEAD+ return config_settings, config_yaml+++=======+ # return config_settings,config_yaml++>>>>>>> merge-pipy-aaron++def write_config_yaml(session, config_settings, config_yaml, pathList, yaml_name):+++<<<<<<< HEAD+ for count, key in enumerate(config_settings["Paths"].keys()):+ config_settings["Paths"][key] = str(pathList[count])++ config_settings["CamInputs"]["RotationInputs"] = session.rotationInputs+ config_settings["CamInputs"]["ParameterDict"] = session.parameterDictionary++ # yamlPath = sessionPath/'config_yaml'+ # print(config_settings,yaml_name)+ with open(yaml_name, "w") as outfile:+ config_yaml.dump(config_settings, outfile)+++def load_config_yaml(yaml_path):+ config_yaml = YAML()+ with open(yaml_path, "r") as fp:+ config_settings = config_yaml.load(fp)+ return config_settings+def load_session_paths(session, config_settings):+ configPaths = config_settings["Paths"]+ session.rawVidPath = Path(configPaths["rawVidPath"])+ session.syncedVidPath = Path(configPaths["syncedVidPath"])+ session.calVidPath = Path(configPaths["calVidPath"])+ session.mediaPipeDataPath = Path(configPaths["mediaPipeDataPath"])+ session.openPoseDataPath = Path(configPaths["openPoseDataPath"])+ session.dlcDataPath = Path(configPaths["dlcDataPath"])+ session.imOutPath = Path(configPaths["imOutPath"])+ session.dataArrayPath = Path(configPaths["dataArrayPath"])++=======+ # def write_config_yaml(session,config_settings,config_yaml,pathList,yaml_name):++ # for count,key in enumerate(config_settings['Paths'].keys()):+ # config_settings['Paths'][key] = str(pathList[count])++ # config_settings['CamInputs']['RotationInputs'] = session.rotationInputs+ # config_settings['CamInputs']['ParameterDict'] = session.parameterDictionary+++ # #yamlPath = sessionPath/'config_yaml'+ # #print(config_settings,yaml_name)+ # with open(yaml_name, 'w') as outfile:+ # config_yaml.dump(config_settings, outfile)+++ # def load_config_yaml(yaml_path):+ # config_yaml = YAML()+ # with open(yaml_path,'r') as fp:+ # config_settings = config_yaml.load(fp)+ # return config_settings++ # def load_session_paths(session,config_settings):+ # configPaths = config_settings['Paths']+ # session.rawVidPath = Path(configPaths['rawVidPath'])+ # session.syncedVidPath = Path(configPaths['syncedVidPath'])+ # session.calVidPath = Path(configPaths['calVidPath'])+ # session.mediaPipeDataPath = Path(configPaths['mediaPipeDataPath'])+ # session.openPoseDataPath = Path(configPaths['openPoseDataPath'])+ # session.dlcDataPath = Path(configPaths['dlcDataPath'])+ # session.imOutPath = Path(configPaths['imOutPath'])+ # session.dataArrayPath = Path(configPaths['dataArrayPath'])++>>>>>>> merge-pipy-aarondiff --cc freemocap/runcams.pyindex e0699f03,30b80d2b..9defb0c9--- a/freemocap/runcams.py+++ b/freemocap/runcams.py@@@ -8,101 -9,78 +8,126 @@@ import numpy as nfrom tkinter import Tk++<<<<<<< HEAD+def RecordCams(session, camInputs, parameterDictionary, rotationInputs):++=======+ def RecordCams(session,camInputs,parameterDictionary,rotationInputs):+ #Create RawVideos folder+ session.rawVidPath.mkdir(exist_ok = True)++>>>>>>> merge-pipy-aaron#%% Setting up recordingsbeginTime = time.time()- numCams = len(camInputs) #number of cameras- numCamRange = range(numCams) #a range for the number of cameras that we have+ numCams = len(camInputs) # number of cameras+ numCamRange = range(numCams) # a range for the number of cameras that we havevidNames = []camIDs = []- for x in numCamRange: #create names for each of the initial untrimmed videos- singleCamID = 'Cam{}'.format(x+1)- camIDs.append(singleCamID) #creates IDs for each camera based on the number of cameras entered- singleVidName = 'raw_cam{}.mp4'.format(x+1)- vidNames.append(singleVidName)+ for x in numCamRange: # create names for each of the initial untrimmed videos+ singleCamID = "Cam{}".format(x + 1)+ camIDs.append(+ singleCamID+ ) # creates IDs for each camera based on the number of cameras entered+ singleVidName = "raw_cam{}.mp4".format(x + 1)+ vidNames.append(singleVidName)#%% Starting the thread recordings for each camera- threads = []- for n in numCamRange: #starts recording video, opens threads for each camera- camRecordings = startcamrecording.CamRecordingThread(camIDs[n],camInputs[n],vidNames[n],session.rawVidPath,beginTime,parameterDictionary)+ threads = []+ for n in numCamRange: # starts recording video, opens threads for each camera+ camRecordings = startcamrecording.CamRecordingThread(+ camIDs[n],+ camInputs[n],+ vidNames[n],+ session.rawVidPath,+ beginTime,+ parameterDictionary,+ )camRecordings.start()-- threads.append(camRecordings)-++ threads.append(camRecordings)+for camRecordings in threads:- camRecordings.join() #make sure that one thread ending doesn't immediately end all the others (before they can dump data in a pickle file)-- print('finished recordings')-- timeStampList = []-- for e in numCamRange: #open the saved pickle file for each camera, and add the timestamps to the dataList list- with open(camIDs[e], 'rb') as f:+ camRecordings.join() # make sure that one thread ending doesn't immediately end all the others (before they can dump data in a pickle file)++ print("finished recordings")++ timeStampList = []++ for (+ e+ ) in (+ numCamRange+ ): # open the saved pickle file for each camera, and add the timestamps to the dataList list+ with open(camIDs[e], "rb") as f:camTimeList = pickle.load(f)timeStampList.append(camTimeList)-- timeDictionary = {}-- id_and_time = zip(camIDs,timeStampList)-- for cam,data in id_and_time:- timeDictionary[cam] = np.array(data) #create a dictionary that holds the timestamps for each camera--- df = pd.DataFrame.from_dict(timeDictionary, orient = 'index') #create a data frame from this dictionary++ timeDictionary = {}++ id_and_time = zip(camIDs, timeStampList)++ for cam, data in id_and_time:+ timeDictionary[cam] = np.array(+ data+ ) # create a dictionary that holds the timestamps for each camera++ df = pd.DataFrame.from_dict(+ timeDictionary, orient="index"+ ) # create a data frame from this dictionarytimeStampData = df.transpose()- csvName = session.sessionID + '.csv' #create our csv filename- csvPath = session.sessionPath/csvName- timeStampData.to_csv(csvPath) #turn dataframe into a CSV+ csvName = session.sessionID + ".csv" # create our csv filename+ csvPath = session.sessionPath / csvName+ timeStampData.to_csv(csvPath) # turn dataframe into a CSVsession.numCams = numCams+ session.session_settings['recording_parameters'].update({'numCams':session.numCams})session.timeStampData = timeStampDatasession.camIDs = camIDssession.numCamRange = numCamRangesession.vidNames = vidNames++<<<<<<< HEAD++def SyncCams(session, timeStampData, numCamRange, vidNames, camIDs):++ # start the timesync process+ frameTable, timeTable, frameRate, resultsTable, plots = timesync.TimeSync(+ timeStampData, numCamRange, camIDs+ )++ # this message shows you your percentages and asks if you would like to continue or not. shuts down the program if no++=======+ def SyncCams(session, timeStampData,numCamRange,vidNames,camIDs):+ session.syncedVidPath.mkdir(exist_ok = True)++ #start the timesync process+ frameTable,timeTable,frameRate,resultsTable,plots = timesync.TimeSync(session,timeStampData,numCamRange,camIDs)++ #this message shows you your percentages and asks if you would like to continue or not. shuts down the program if no++>>>>>>> merge-pipy-aaronroot = Tk()- proceed = timesync.proceedGUI(root,resultsTable,plots) #create a GUI instance called proceed+ proceed = timesync.proceedGUI(+ root, resultsTable, plots+ ) # create a GUI instance called proceedroot.mainloop()- if proceed.proceed == True:+ if proceed.proceed == True:print()++<<<<<<< HEAD+ print("Starting editing")+ videotrim.VideoTrim(+ session,+ vidNames,+ frameTable,+ session.parameterDictionary,+ session.rotationInputs,+ numCamRange,+ )+ # videotrim.createCalibrationVideos(session,60,parameterDictionary)+ print("all done")++=======+ print('Starting editing')+ videotrim.VideoTrim(session,vidNames,frameTable,session.parameterDictionary,session.rotationInputs,numCamRange)+ session.session_settings['recording_parameters'].update({'numFrames':session.numFrames})+ #videotrim.createCalibrationVideos(session,60,parameterDictionary)- print('all done')++ print('all done')++>>>>>>> merge-pipy-aarondiff --cc freemocap/session.pyindex 58cf9eef,f72f5c11..dac7701d--- a/freemocap/session.py+++ b/freemocap/session.py@@@ -1,13 -1,23 +1,36 @@@++<<<<<<< HEAD+class Session: # session like "recording session"+ def __init__(self):+ self.sessionID = (+ "" # The sessionID tag will be used to generate files names and whatnot+ )+ self.sessionPath = "" # The folder where the to-be-processed videos live (in a folder called "synced Vids")+ self.numCams = "" # The number of cameras used in this recording session+ self.openPoseDataPath = "" # Where the open pose data lives+ self.dlcDataPath = "" # Where the DLC data lives+ self.openPoseExePath = r"C:\openpose"++=======+ from pathlib import Path+ from ruamel.yaml import YAML++ from freemocap import recordingconfig++ class Session: #self like "recording self"+ def __init__(self):++ self.numCams = None+ self.numFrames = None+ self.numTrackedPoints = None++ self.basePath = Path.cwd()++ self.sessionID = '' #The sessionID tag will be used to generate files names and whatnot+ self.sessionPath = '' #The folder where the to-be-processed videos live (in a folder called "synced Vids")+ #self.numCams = ''#The number of cameras used in this recording self+ self.openPoseDataPath = ''#Where the open pose data lives+ self.dlcDataPath = ''#Where the DLC data lives+ self.openPoseExePath = r'C:\openpose'++>>>>>>> merge-pipy-aaronself.cam_inputs = Noneself.parameterDictionary = None@@@ -20,3 -30,175 +43,178 @@@self.mediaPipe_imgPathList = Noneself.openPose_imgPathList = None++<<<<<<< HEAD++=======++ def start_session(self,paramDict,rotDict):+ #start a session, create all the file paths necessary, and create a session dictionary to save settings+ recordPath = self.basePath/'Data'+ recordPath.mkdir(exist_ok= True)++ self.sessionPath = recordPath/self.sessionID+ self.sessionPath.mkdir(exist_ok=True)++ #create all the session filepaths and settings - create and load them into a dictionary+ self.pathList = self.create_session_paths()+ self.session_settings = self.create_session_dictionary()+ self.create_session_txt(paramDict,rotDict)++ self.save_session()++++ def create_session_paths(self):+ #creates Path objects to each folder created in a recording self and adds them all to the pathList variable+ #folders for these paths are created at the start of each stage where they are needed++ pathList = []++ self.rawVidPath = self.sessionPath/'RawVideos'+ pathList.append(self.rawVidPath)++ self.syncedVidPath = self.sessionPath/'SyncedVideos'+ pathList.append(self.syncedVidPath)++ self.calVidPath = self.sessionPath/'CalVideos'+ pathList.append(self.calVidPath)++ self.dataArrayPath = self.sessionPath/'DataArrays'+ pathList.append(self.dataArrayPath)++ self.dlcDataPath = self.sessionPath/'DLCData'+ pathList.append(self.dlcDataPath)++ self.openPoseDataPath = self.sessionPath/'OpenPoseData'+ pathList.append(self.openPoseDataPath)++ self.mediaPipeDataPath = self.sessionPath/'MediaPipeData'+ pathList.append(self.mediaPipeDataPath)++ self.imOutPath = self.sessionPath/'imOut'+ pathList.append(self.imOutPath)++ return pathList++ def create_session_dictionary(self):+ #creates a dictionary of settings that should be saved into a YAML throughout each self++ recording_parameters = {'numCams': self.numCams, 'numFrames': self.numFrames, 'numTrackedPoints': self.numTrackedPoints}++ #create a dictionary with the folder names (taken from the recordingconfig.py file) and the folder paths from pathList+ #NOTE AC- 6/30/21 - as of right now, the order of folder names in the recordingconfig.folder_setup list needs to match the+ # the order of folder paths in the pathList+ session_paths = {}++ for foldername, folderpath in zip(recordingconfig.folder_setup,self.pathList):+ session_paths[foldername] = folderpath++ session_settings_dictionary = {'recording_parameters':recording_parameters, 'session_paths':session_paths}++ return session_settings_dictionary+++ def create_session_txt(self,paramDict,rotDict):+ #create a text file listing recording parameters+ parameter_text = self.sessionPath/'sessionSettings.txt'+ text = open(parameter_text, 'w')+ text.write("Session ID = %s\n" %(self.sessionID))+ text.write("%s = %s\n" %("Parameters", paramDict))+ text.write("%s = %s\n" %("Rotations", rotDict))+ text.close()++ def save_session(self):+ #save the self settings you want to keep from self to self into a yaml+ #because some items are not yaml-able, a copy of the sessionDictionary is made and adjusted to be fully yaml-able+ #Adjustments Made:+ #pathLib objects are all converted to strings+ session_dictionary_to_save = self.session_settings++ for key,value in session_dictionary_to_save['session_paths'].items():+ session_dictionary_to_save['session_paths'][key] = str(value)++ self.session_yaml_path = self.sessionPath/'{}_config.yaml'.format(self.sessionID)++ session_yaml = YAML()+++ with open(self.session_yaml_path,'w') as outfile:+ session_yaml.dump(session_dictionary_to_save,outfile)+++ def initialize(self,stage):+ #load all session settings back into the session class for this run-through of the code++ recordPath = self.basePath/'Data' #create a Data folder in the filepath if none exists yet+ recordPath.mkdir(exist_ok= True)++ self.sessionPath = recordPath/self.sessionID+ self.sessionPath.mkdir(exist_ok=True)++ self.session_yaml_path = self.sessionPath/'{}_config.yaml'.format(self.sessionID)++ if stage == 3:+ #this is for the case of GoPro recordings/external recordings - if no config file exists, create one+ if self.session_yaml_path.is_file():+ self.session_settings = self.load_session()+ else:+ self.start_session({},{})+ else:+ self.session_settings = self.load_session()+++++ def load_session(self):++ #session_yaml_path = self.sessionPath/'{}_config.yaml'.format(self.sessionID)+ session_yaml = YAML(typ='safe', pure=True)++ with open(self.session_yaml_path,'r') as fp:+ session_dictionary_to_load = session_yaml.load(fp)++ session_settings_dictionary = session_dictionary_to_load #create a copy of the loaded dictionary++ for key,value in session_settings_dictionary['session_paths'].items():+ session_settings_dictionary['session_paths'][key] = Path(value)++ self.load_session_paths(session_settings_dictionary)+ self.numCams = session_settings_dictionary['recording_parameters']['numCams']+ self.numFrames = session_settings_dictionary['recording_parameters']['numFrames']+ self.numTrackedPoints = session_settings_dictionary['recording_parameters']['numTrackedPoints']++ return session_settings_dictionary+ f = 2++ def load_session_paths(self, session_settings_dict):++ session_paths = session_settings_dict['session_paths']++ self.rawVidPath = session_paths['RawVideos']+ self.syncedVidPath = session_paths['SyncedVideos']+ self.calVidPath = session_paths['CalVideos']+ self.mediaPipeDataPath = session_paths['MediaPipeData']+ self.openPoseDataPath = session_paths['OpenPoseData']+ self.dlcDataPath = session_paths['DLCData']+ self.imOutPath = session_paths['imOut']+ self.dataArrayPath = session_paths['DataArrays']++++ f = 2++++++++++++++++++>>>>>>> merge-pipy-aarondiff --cc freemocap/webcam/timesync.pyindex d954e21c,e857c529..45009978--- a/freemocap/webcam/timesync.py+++ b/freemocap/webcam/timesync.py@@@ -4,148 -4,144 +4,262 @@@ import syfrom matplotlib.figure import Figurefrom matplotlib.backends.backend_tkagg import FigureCanvasTkAggimport tkinter as tk-from tkinter import Tk,Label, Button, Frame+from tkinter import Tk, Label, Button, Frame++<<<<<<< HEAD++=======+ def TimeSync(session,timeStampData,numCamRange,camNames):++ def CloseNeighb(camera,point):+ closestPoint = (np.abs(camera - point)).argmin()+ return closestPoint++>>>>>>> merge-pipy-aaron-- #this section auto-finds the start and end points for our master timeline to the nearest second- masterTimelineBegin = np.ceil(max(timeStampData.iloc[0]))+def TimeSync(timeStampData, numCamRange, camNames):+ def CloseNeighb(camera, point):+ closestPoint = (np.abs(camera - point)).argmin()+ return closestPoint++ # this section auto-finds the start and end points for our master timeline to the nearest second+ masterTimelineBegin = np.ceil(max(timeStampData.iloc[0]))lastPoints = []for name in camNames:- cameraLastPoint = timeStampData[name][timeStampData[name].last_valid_index()] #find the last non-nan value in each camera+ cameraLastPoint = timeStampData[name][+ timeStampData[name].last_valid_index()+ ] # find the last non-nan value in each cameralastPoints.append(cameraLastPoint)++<<<<<<< HEAD++ masterTimelineEnd = np.floor(+ min(lastPoints)+ ) # find where the fastest camera ended, round down, use that as the end point++ # print('end',endList)+ print("intervals:", masterTimelineBegin, masterTimelineEnd)++ totalFrameIntvl = [] # list for storing frame rates for each camera++ n = 0+ # counter for going through camera names+ for x in numCamRange:+ currentCam = timeStampData[camNames[x]]+ # finds the closest point in each camera to the start and end points of our timeline+ currentCamStart = CloseNeighb(currentCam, masterTimelineBegin)+ currentCamEnd = CloseNeighb(currentCam, masterTimelineEnd)+ print("using frames:", currentCamStart, "-", currentCamEnd, "for", camNames[n])+ n += 1+ currentCamTimeline = currentCam[+ currentCamStart:currentCamEnd+ ] # grab the times from start to finish for each camera+ currentCamFrameInterval = np.mean(+ np.diff(currentCamTimeline)+ ) # calculate the interval between each frame and take the mean+ totalFrameIntvl.append(currentCamFrameInterval) # add interval to list+ # print(camNames[x],currentCamStart,currentCamEnd)+ totalAverageIntvl = np.mean(+ totalFrameIntvl+ ) # find the total average interval across all cameras+ masterTimeline = np.arange(+ masterTimelineBegin, masterTimelineEnd, totalAverageIntvl+ ) # build a master timeline with the average interval++ # now we start the syncing process++ frameList = masterTimeline # start a list of frames, with the first row being our master timeline+ timeList = masterTimeline # start a list of timestamps,with the first row being our master timeline++ delNum = []+ # stores number of deleted frames/camera+ bufNum = []+ # stores number of buffered frames/camera+ bufPercentList = []+ # stores percentage of deleted frames/camera+ delPercentList = []+ # stores percentage of buffered frames/camera++ count = 0 # Keeps track of what frame we're on (I think?)+ n = 0+ # I don't remember why I did this but I'm sure I'll figure it out later+++=======++ masterTimelineEnd = np.floor(min(lastPoints)) #find where the fastest camera ended, round down, use that as the end point+++ #print('end',endList)+ print('intervals:',masterTimelineBegin,masterTimelineEnd)++ preSyncTotalNumFrames = []+ totalFrameIntvl= [] #list for storing frame rates for each camera+++ n = 0; #counter for going through camera names+ for x in numCamRange:+ currentCam = timeStampData[camNames[x]]+ #finds the closest point in each camera to the start and end points of our timeline+ currentCamStart = CloseNeighb(currentCam,masterTimelineBegin)+ currentCamEnd = CloseNeighb(currentCam,masterTimelineEnd)+++ print("using frames:", currentCamStart,"-",currentCamEnd,"for",camNames[n])+ n +=1+ currentCamTimeline = currentCam[currentCamStart:currentCamEnd] #grab the times from start to finish for each camera++ currentCamNumFrames = len(currentCamTimeline)++ currentCamFrameInterval = np.mean(np.diff(currentCamTimeline)) #calculate the interval between each frame and take the mean++ totalFrameIntvl.append(currentCamFrameInterval) #add interval to list+ preSyncTotalNumFrames.append(currentCamNumFrames)+ #print(camNames[x],currentCamStart,currentCamEnd)++ #print(preSyncTotalNumFrames, 'presync')+ #assert preSyncTotalNumFrames.count(preSyncTotalNumFrames[0]) == len(preSyncTotalNumFrames), "Number of frames sliced for each camera pre-syncing is not the same"++ totalAverageIntvl = np.mean(totalFrameIntvl) #find the total average interval across all cameras+ masterTimeline = np.arange(masterTimelineBegin,masterTimelineEnd,totalAverageIntvl) #build a master timeline with the average interval++ #now we start the syncing process++ frameList = masterTimeline #start a list of frames, with the first row being our master timeline+ timeList = masterTimeline #start a list of timestamps,with the first row being our master timeline++ delNum= []; #stores number of deleted frames/camera+ bufNum= []; #stores number of buffered frames/camera+ bufPercentList = []; #stores percentage of deleted frames/camera+ delPercentList = []; #stores percentage of buffered frames/camera++ count = 0 #Keeps track of what frame we're on (I think?)+ n = 0; #I don't remember why I did this but I'm sure I'll figure it out later+++ postSyncTotalNumFrames = []++>>>>>>> merge-pipy-aaronfor y in numCamRange:thisCam = timeStampData[camNames[y]]- camTimes = []; #stored times- camFrames =[]; #stored frames-+ camTimes = []+ # stored times+ camFrames = []+ # stored frames+count += 1- #--------------Adjust each camera to start at the first point in the master timeline- beginFrame = CloseNeighb(thisCam,masterTimeline[0])+ # --------------Adjust each camera to start at the first point in the master timeline+ beginFrame = CloseNeighb(thisCam, masterTimeline[0])timeDif = masterTimeline[0] - thisCam[beginFrame]thisCam = thisCam + timeDif++<<<<<<< HEAD++ for z in masterTimeline: # for each point in the master timeline+ closestFrame = CloseNeighb(+ thisCam, z+ ) # find the closest frame in this camera to each point of the master timeline+ camFrames.append(closestFrame) # add that frame to the list+ camTimes.append(+ thisCam[closestFrame]+ ) # find the time corresponding to this frame++ print(+ "starting detection:", camNames[n]+ ) # now to start finding deleted/buffered slides+ frameList = np.column_stack(+ (frameList, camFrames)+ ) # update our framelist with our new frames+ timeList = np.column_stack((timeList, camTimes)) # update our timelist++ # start counters for the number of buffered and deleted slides+ bufCount = 0+ delCount = 0++ for i in range(0, len(camFrames) - 1):+ distanceBetweenFrames = (+ camFrames[i + 1] - camFrames[i]+ ) # find the distance between adjacent frames+ if distanceBetweenFrames == 1: # these frames are consecutive, do nothing+ None+ elif distanceBetweenFrames == 0: # we have a buffered slide++=======++ for z in masterTimeline: #for each point in the master timeline+ closestFrame = CloseNeighb(thisCam, z) #find the closest frame in this camera to each point of the master timeline+ camFrames.append(closestFrame) #add that frame to the list+ camTimes.append(thisCam[closestFrame]) #find the time corresponding to this frame++ print("starting detection:",camNames[n]) #now to start finding deleted/buffered slides+ frameList = np.column_stack((frameList,camFrames)) #update our framelist with our new frames+ timeList = np.column_stack((timeList,camTimes)) #update our timelist+++ #start counters for the number of buffered and deleted slides+ bufCount = 0;+ delCount = 0;++ thisCamNumFrames = len(camFrames)+ postSyncTotalNumFrames.append(thisCamNumFrames)++ for i in range(0,len(camFrames)-1):+ distanceBetweenFrames = camFrames[i+1] - camFrames[i] #find the distance between adjacent frames+ if distanceBetweenFrames == 1: #these frames are consecutive, do nothing+ None+ elif distanceBetweenFrames == 0: #we have a buffered slide++>>>>>>> merge-pipy-aaronbufCount += 1- #this section looks at our two timepoints, and finds the which point on the master timeline is closest- frame1 = abs(masterTimeline[i]-camTimes[i])- frame2 = abs(masterTimeline[i+1]-camTimes[i])- #finds which frame is closest, and sets the other frame as a buffer (indicated by the -1)- if frame1>frame2:- frameList[i,count] = -1- timeList[i,count] = -1+ # this section looks at our two timepoints, and finds the which point on the master timeline is closest+ frame1 = abs(masterTimeline[i] - camTimes[i])+ frame2 = abs(masterTimeline[i + 1] - camTimes[i])+ # finds which frame is closest, and sets the other frame as a buffer (indicated by the -1)+ if frame1 > frame2:+ frameList[i, count] = -1+ timeList[i, count] = -1else:- frameList[i+1,count] = -1;- timeList[i+1,count] = -1;- elif distanceBetweenFrames > 1: #deletion- delCount += 1+ frameList[i + 1, count] = -1+ timeList[i + 1, count] = -1+ elif distanceBetweenFrames > 1: # deletion+ delCount += 1else:-+print("something else happened")++<<<<<<< HEAD+ # update and calculate our percentages and numbers for buffers/deletions+ delNum.append(round(delCount, 1))+ bufNum.append(round(bufCount, 1))+ # print(bufCount,len(frameList))+ bufPercent = (bufCount / len(frameList)) * 100+ delPercent = (delCount / len(frameList)) * 100+ bufPercentList.append(round(bufPercent, 2))+ delPercentList.append(round(delPercent, 2))++ # print(delNum,bufNum,bufPercentList,delPercentList)+ # print("deleted frames:",delCount)+ # print("buffered frames:",bufCount)+ n += 1++ # create our data frame for both times and frames+ frameTable = pd.DataFrame(frameList)+ columnNames = ["Master Timeline"] + camNames++=======+ #update and calculate our percentages and numbers for buffers/deletions+ delNum.append(round(delCount,1))+ bufNum.append(round(bufCount,1))+ #print(bufCount,len(frameList))+ bufPercent = (bufCount/len(frameList))*100+ delPercent = (delCount/len(frameList))*100+ bufPercentList.append(round(bufPercent,2))+ delPercentList.append(round(delPercent,2))++ #print(delNum,bufNum,bufPercentList,delPercentList)+ #print("deleted frames:",delCount)+ #print("buffered frames:",bufCount)+ n +=1++ #print(postSyncTotalNumFrames, 'post-sync')+ assert postSyncTotalNumFrames.count(postSyncTotalNumFrames[0]) == len(postSyncTotalNumFrames), "Number of frames sliced for each camera post-syncing is not the same"++ session.postSyncNumFrames = postSyncTotalNumFrames[0]++ #create our data frame for both times and frames+ frameTable = pd.DataFrame(frameList)+ columnNames = ['Master Timeline'] + camNames++>>>>>>> merge-pipy-aaronframeTable.columns = columnNamestimeTable = pd.DataFrame(timeList)timeTable.columns = columnNamesdiff --cc freemocap/webcam/videotrim.pyindex 90abd4d5,67609eb0..7d56298a--- a/freemocap/webcam/videotrim.py+++ b/freemocap/webcam/videotrim.py@@@ -4,35 -4,29 +4,45 @@@ import imutilimport numpy as npimport os-def VideoTrim(session,vidList,ft,parameterDictionary,rotationState,numCamRange):- camList = list(ft.columns[1:len(vidList)+1]) #grab the camera identifiers from the data frame- resWidth = parameterDictionary.get('resWidth')- resHeight = parameterDictionary.get('resHeight')- framerate = parameterDictionary.get('framerate')- trueWidth = resWidth #creating true resWidth and resHeight in case we need to rotate our images++def VideoTrim(session, vidList, ft, parameterDictionary, rotationState, numCamRange):+ camList = list(+ ft.columns[1 : len(vidList) + 1]+ ) # grab the camera identifiers from the data frame+ resWidth = parameterDictionary.get("resWidth")+ resHeight = parameterDictionary.get("resHeight")+ framerate = parameterDictionary.get("framerate")+ trueWidth = resWidth # creating true resWidth and resHeight in case we need to rotate our imagestrueHeight = resHeight- codec = parameterDictionary.get('codec')+ codec = parameterDictionary.get("codec")++<<<<<<< HEAD+ for vid, cam, camNum in zip(+ vidList, camList, numCamRange+ ): # iterate in parallel through camera identifiers and matching videos+ print("Editing " + cam + " from " + vid)+ cap = cv2.VideoCapture(+ str(session.rawVidPath / vid)+ ) # initialize OpenCV capture+ frameTable = ft[cam] # grab the frames needed for that camera+ success, image = cap.read() # start reading frames++=======+ postTrimmingTotalNumFrames = []++ for vid,cam,camNum in zip(vidList,camList,numCamRange): #iterate in parallel through camera identifiers and matching videos+ print('Editing '+cam+' from ' +vid)+ cap = cv2.VideoCapture(str(session.rawVidPath/vid)) #initialize OpenCV capture+ frameTable = ft[cam] #grab the frames needed for that camera+ success, image = cap.read() #start reading frames++>>>>>>> merge-pipy-aaronfourcc = cv2.VideoWriter_fourcc(*codec)- saveName = session.sessionID +'_synced_' + cam + '.mp4'--- saveSyncedVidPath = str(session.syncedVidPath/saveName) #create an output path for the function- if rotationState[camNum] == 90 or rotationState[camNum] == 270:- #if we are rotating to these angles, we need to temporarily swap our resWidth and resHeight+ saveName = session.sessionID + "_synced_" + cam + ".mp4"++ saveSyncedVidPath = str(+ session.syncedVidPath / saveName+ ) # create an output path for the function+ if rotationState[camNum] == 90 or rotationState[camNum] == 270:+ # if we are rotating to these angles, we need to temporarily swap our resWidth and resHeighttempHeight = resHeightresHeight = resWidthresWidth = tempHeight@@@ -62,39 -50,40 +72,54 @@@resHeight = trueHeightcap.release()out.release()++<<<<<<< HEAD+ print("Saved " + saveSyncedVidPath)+ print()+++def createCalibrationVideos(session, calVideoFrameLength, parameterDictionary):++=======+ frame_length_cap = cv2.VideoCapture(saveSyncedVidPath)+ thisCamNumFrame = int(frame_length_cap.get(cv2.CAP_PROP_FRAME_COUNT))+ postTrimmingTotalNumFrames.append(thisCamNumFrame)+ print('Saved '+ saveSyncedVidPath)+ print()++ assert postTrimmingTotalNumFrames.count(postTrimmingTotalNumFrames[0]) == len(postTrimmingTotalNumFrames), "Number of frames in each synced video is not the same"+ session.postTrimmingNumFrames = postTrimmingTotalNumFrames[0]+ session.numFrames = postTrimmingTotalNumFrames[0]+++ def createCalibrationVideos(session,calVideoFrameLength,parameterDictionary):++>>>>>>> merge-pipy-aaronvidList = os.listdir(session.syncedVidPath)framelist = list(range(calVideoFrameLength))- codec = parameterDictionary.get('codec')- for count,vid in enumerate(vidList,start=1):+ codec = parameterDictionary.get("codec")+ for count, vid in enumerate(vidList, start=1):cam_name = "Cam{}".format(count)- cap = cv2.VideoCapture(str(session.syncedVidPath/vid))+ cap = cv2.VideoCapture(str(session.syncedVidPath / vid))fourcc = cv2.VideoWriter_fourcc(*codec)-- #grab resolution parameters from the videos- resWidth = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))++ # grab resolution parameters from the videos+ resWidth = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))resHeight = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))framerate = int(cap.get(cv2.CAP_PROP_FPS))-- saveName = session.sessionID +'_trimmed_' + cam_name + '.mp4' #create a name for the trimmed video- saveCalVidPath = str(session.calVidPath/saveName) #create an output path for the function-- success, image = cap.read() #start reading frames-- out = cv2.VideoWriter(saveCalVidPath, fourcc, framerate, (resWidth,resHeight))- print('Trimming ' + cam_name)++ saveName = (+ session.sessionID + "_trimmed_" + cam_name + ".mp4"+ ) # create a name for the trimmed video+ saveCalVidPath = str(+ session.calVidPath / saveName+ ) # create an output path for the function++ success, image = cap.read() # start reading frames++ out = cv2.VideoWriter(saveCalVidPath, fourcc, framerate, (resWidth, resHeight))+ print("Trimming " + cam_name)for frame in track(framelist):- cap.set(cv2.CAP_PROP_POS_FRAMES, frame) #set the video to the frame that we need+ cap.set(+ cv2.CAP_PROP_POS_FRAMES, frame+ ) # set the video to the frame that we needsuccess, image = cap.read()out.write(image)cap.release()diff --cc freemocap/webcamGUI.pyindex 5db9a02c,83ca4e81..07eb8f1d--- a/freemocap/webcamGUI.py+++ b/freemocap/webcamGUI.py@@@ -24,103 -25,106 +24,167 @@@ def initialize(session, stage, board)sessionID_in = datetime.datetime.now().strftime("sesh_%y-%m-%d_%H%M%S")session.sessionID = sessionID_in++<<<<<<< HEAD:freemocap/initialization.py+ # load the parameters YAML and extract the saved parameters if possible, and the default otherwise+ parameter_path = filepath / "parameters.yaml"++=======+ #load the parameters YAML and extract the saved parameters if possible, and the default otherwise+ here = Path(__file__).parent+ parameter_path = here/'parameters.yaml'++>>>>>>> merge-pipy-aaron:freemocap/webcamGUI.pyparameters_yaml = YAML()parameters = parameters_yaml.load(parameter_path)- try:- rotation_entry = parameters['saved']['rotations']- parameter_entry = parameters['saved']['parameters']+ try:+ rotation_entry = parameters["saved"]["rotations"]+ parameter_entry = parameters["saved"]["parameters"]except:++<<<<<<< HEAD:freemocap/initialization.py+ print("Using Default Config")+ rotation_entry = parameters["default"]["rotations"]+ parameter_entry = parameters["default"]["parameters"]++ proceedToRecording = False # create this boolean, set it to false, and if the user wants to record+ # later in the pipeline, it will be set to true++ # run the GUI to get the tasks, the cams chosen, the camera settings, and the session ID+ task, cam_inputs, rotDict, paramDict, session.sessionID = recordGUI.RunGUI(+ sessionID_in, rotation_entry, parameter_entry+ )++ # update the saved parameters in the YAML+ parameters["saved"]["rotations"] = rotDict+ parameters["saved"]["parameters"] = paramDict+ parameters_yaml.dump(parameters, parameter_path)++ # create a list from the rotation dictionary to be used in running webcams++=======+ print("Could not load saved parameters, using default parameters")+ rotation_entry = parameters['default']['rotations']+ parameter_entry = parameters['default']['parameters']++ proceedToRecording = False #create this boolean, set it to false, and if the user wants to record+ #later in the pipeline, it will be set to true++ #run the GUI to get the tasks, the cams chosen, the camera settings, and the session ID+ task, cam_inputs, rotDict, paramDict, session.sessionID = recordGUI.RunGUI(sessionID_in,rotation_entry,parameter_entry)++ #update the saved parameters in the YAML+ #recordingconfig.rotation_settings['saved'] = rotDict+ #recordingconfig.camera_parameters['saved'] = paramDict+ parameters['saved']['rotations'] = rotDict+ parameters['saved']['parameters'] = paramDict+ parameters_yaml.dump(parameters, parameter_path)++ #save recording parameters to the config yaml+++ #create a list from the rotation dictionary to be used in running webcams++>>>>>>> merge-pipy-aaron:freemocap/webcamGUI.pyrotation_input = list(rotDict.values())- if task == 'setup':- #run setup processes, and then check if th user wants to proceed to recording- camsetup.RunSetup(cam_inputs,rotation_input,paramDict)- proceedToRecording,session.sessionID = recordGUI.RunProceedtoRecordGUI(sessionID_in)+ if task == "setup":+ # run setup processes, and then check if th user wants to proceed to recording+ camsetup.RunSetup(cam_inputs, rotation_input, paramDict)+ proceedToRecording, session.sessionID = recordGUI.RunProceedtoRecordGUI(+ sessionID_in+ )- elif task == 'record':+ elif task == "record":proceedToRecording = True-+if proceedToRecording:- #create these session properties to be used later in the pipeline+ # create these session properties to be used later in the pipelinesession.cam_inputs = cam_inputssession.parameterDictionary = paramDictsession.rotationInputs = rotation_input++<<<<<<< HEAD:freemocap/initialization.py+ # create a config yaml and text file for this session+ config_yaml_path = recordingconfig.createSession(session, filepath)+ recordingconfig.createSessionTxt(session, paramDict, rotDict)++=======+ #create a config yaml and text file for this session+ session.start_session(session.parameterDictionary,session.rotationInputs)+ session.session_settings['recording_parameters']['RotationInputs'] = rotDict+ session.session_settings['recording_parameters']['ParameterDict'] = paramDict+ #configyaml = YAML()+ #sessionsettings = configyaml.load(session.session_yaml_path)+ #sessionsettings['recording_parameters']['RotationInputs'] = rotDict+ #sessionsettings['recording_parameters']['ParameterDict'] = paramDict+ #configyaml.dump(sessionsettings, session.session_yaml_path)+ #print(sessionsettings)+ #config_yaml_path = recordingconfig.createSession(session,filepath)+ #recordingconfig.createSessionTxt(session,paramDict,rotDict)++ print('Proceeding to Stage One')++ else:++ sys.exit('Recording Cancelled')+ # %% Stage Two Initalization+ if stage == 2:+ # session.sessionPath = filepath/'Data'/session.sessionID #create a session path based on the sessionID++ # #load the config yaml for this session, and add all the paths to the session file+ # session.yamlPath = session.sessionPath/'{}_config.yaml'.format(session.sessionID)+ # session.config_settings = recordingconfig.load_config_yaml(session.yamlPath) #config settings = paths and camera parameter inputs+ # recordingconfig.load_session_paths(session,session.config_settings) #add paths to session class+ session.initialize(stage)++ #from the config settings add the camera input parameters to parameter dictionary+ session.parameterDictionary = session.session_settings['recording_parameters']['ParameterDict']+ session.rotationInputs = session.session_settings['recording_parameters']['RotationInputs']++>>>>>>> merge-pipy-aaron:freemocap/webcamGUI.py- #initialize the path to the timestamp csv- csvName = session.sessionID + '.csv'- csvPath = session.sessionPath/csvName+ print("Proceeding to Stage One")- #read CSV data, turn it into a data frame- timeStampData = pd.read_csv (csvPath)- timeStampData = timeStampData.iloc[:,1:]+ else:- #get the camIDs and number of cameras (numCamRange) from the dataframe+ sys.exit("Recording Cancelled")+ # %% Stage Two Initalization+ if stage == 2:+ session.sessionPath = (+ filepath / "Data" / session.sessionID+ ) # create a session path based on the sessionID++ # load the config yaml for this session, and add all the paths to the session file+ session.yamlPath = session.sessionPath / "{}_config.yaml".format(+ session.sessionID+ )+ session.config_settings = recordingconfig.load_config_yaml(+ session.yamlPath+ ) # config settings = paths and camera parameter inputs+ recordingconfig.load_session_paths(+ session, session.config_settings+ ) # add paths to session class++ # from the config settings add the camera input parameters to parameter dictionary+ session.parameterDictionary = session.config_settings["CamInputs"][+ "ParameterDict"+ ]+ session.rotationInputs = session.config_settings["CamInputs"]["RotationInputs"]++ # initialize the path to the timestamp csv+ csvName = session.sessionID + ".csv"+ csvPath = session.sessionPath / csvName++ # read CSV data, turn it into a data frame+ timeStampData = pd.read_csv(csvPath)+ timeStampData = timeStampData.iloc[:, 1:]++ # get the camIDs and number of cameras (numCamRange) from the dataframecamIDs = list(timeStampData.columns)numCams = len(camIDs)- numCamRange = range(len(camIDs))-- #create names for each of the raw videos+ numCamRange = range(len(camIDs))++ # create names for each of the raw videosvidNames = []for x in numCamRange:- singleVidName = 'raw_cam{}.mp4'.format(x+1)- vidNames.append(singleVidName)+ singleVidName = "raw_cam{}.mp4".format(x + 1)+ vidNames.append(singleVidName)-- #initialize all the session variables we'll need to run the rest of the pipeline+ # initialize all the session variables we'll need to run the rest of the pipelinesession.timeStampData = timeStampDatasession.camIDs = camIDssession.numCamRange = numCamRange