def show(self, fps=240, colors=None): if self.joints is None: raise NotImplementedError( "show function must be implemented after setvalue or set_from_trc" ) from dp.view import Visualization vis = Visualization() data = np.array(list(self.joints.values())) # [joint index][time][dim] vis.show3d(x=data[:, :, 0].T, y=data[:, :, 1].T, z=data[:, :, 2].T, jointNames=self.joints, lines=self.lines, fps=fps, colors=colors)
def showresult(self, jointName, correspondLine): if jointName not in self.correspondents.keys(): raise NotImplementedError( "There is no result about {0}: this method must call after calc" .format(jointName)) x = {jointName: self.correspondents[jointName][:, 0]} y = {jointName: self.correspondents[jointName][:, 1]} from dp.view import Visualization view = Visualization() view.show(x=x, y=y, xtime=self.reference.frame_max, ytime=self.input.frame_max, title='Matching Path', legend=True, correspondLine=correspondLine)
def save(self, path, fps=240, colors=None, saveonly=True, grid=False): if self.joints is None: raise NotImplementedError( "save function must be implemented after setvalue or set_from_trc" ) from dp.view import Visualization vis = Visualization() data = np.array(list(self.joints.values())) # [joint index][time][dim] vis.show3d(x=data[:, :, 0].T, y=data[:, :, 1].T, z=data[:, :, 2].T, jointNames=self.joints, saveonly=saveonly, savepath=path, lines=self.lines, fps=fps, colors=colors, grid=grid)
def implementDP(name, serve, successNum, failureNum): Dir = "./trc/" + name resultSuperDir = os.path.join('./compareDP/', name) if not os.path.exists(resultSuperDir): os.mkdir(resultSuperDir) #resultSuperDir = os.path.join(resultSuperDir, 'normal-independent') resultSuperDir = os.path.join( resultSuperDir, '{0}-s{1}-f{2}'.format(serve, successNum, failureNum)) if not os.path.exists(resultSuperDir): os.mkdir(resultSuperDir) #reffile = referenceReader("{0}-normal.csv".format(name), Dir, superDir=name) filename = '{0}{1:02d}.trc'.format(name, successNum) refData = Data() refData.set_from_trc(os.path.join('./trc', name, filename), lines='volleyball') for joint in list(refData.joints.keys()): refData.joints[nameExchanger[joint]] = refData.joints.pop(joint) filename = '{0}{1:02d}.trc'.format(name, failureNum) inpData = Data() inpData.set_from_trc(os.path.join('./trc', name, filename), lines='volleyball') for joint in list(inpData.joints.keys()): inpData.joints[nameExchanger[joint]] = inpData.joints.pop(joint) contexts = [['head', 'R_ear', 'L_ear'], ['R_hand', 'R_in_wrist', 'R_out_wrist'], ['L_hand', 'L_in_wrist', 'L_out_wrist'], ['R_out_elbow', 'R_in_elbow', 'R_backshoulder'], ['L_out_elbow', 'L_in_elbow', 'L_backshoulder'], ['sternum', 'R_frontshoulder', 'L_frontshoulder'], ['R_rib', 'R_ASIS'], ['L_rib', 'L_ASIS'], ['R_PSIS', 'L_PSIS']] # name change for i, context in enumerate(list(contexts)): for j, joint in enumerate(list(context)): contexts[i][j] = nameExchanger[joint] kinds = [ 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async2-visualization2', 'async2-visualization2', 'async2-visualization2' ] # independent DP_ = DP(refData, inpData, verbose=False, ignoreWarning=True, verboseNan=False) DP_.resultVisualization(kind='visualization2', fps=500, maximumGapTime=0.1) Xi, Yi = DP_.resultData() # sync DP_ = SyncContextDP(contexts=contexts, reference=refData, input=inpData, verbose=False, ignoreWarning=True, verboseNan=False) DP_.resultVisualization(kind='visualization2', fps=500, maximumGapTime=0.1) Xs, Ys = DP_.resultData() # async DP_ = AsyncContextDP(contexts=contexts, reference=refData, input=inpData, verbose=False, ignoreWarning=True, verboseNan=False) DP_.resultVisualization(kinds=kinds, kind='visualization2', fps=500, maximumGapTime=0.1) Xa, Ya = DP_.resultData() for context in contexts: xi, yi = {}, {} xs, ys = {}, {} xa, ya = {}, {} #x, y = {}, {} title = '' syncname = '' for joint in context: xi[joint], yi[joint] = Xi[joint], Yi[joint] xa[joint], ya[joint] = Xa[joint], Ya[joint] title += joint + '-' syncname += joint + ',' title = title[:-1] syncname = syncname[:-1] xs[syncname], ys[syncname] = Xs[joint], Ys[joint] resultDir = os.path.join(resultSuperDir, title) if not os.path.exists(resultDir): os.mkdir(resultDir) viewi = Visualization() viewi.show(x=xi, y=yi, xtime=refData.frame_max, ytime=inpData.frame_max, title=None, legend=True, correspondLine=False, savepath=os.path.join(resultDir, "independent.png")) views = Visualization() views.show(x=xs, y=ys, xtime=refData.frame_max, ytime=inpData.frame_max, title=None, legend=True, correspondLine=False, savepath=os.path.join(resultDir, "sync.png")) viewa = Visualization() viewa.show(x=xa, y=ya, xtime=refData.frame_max, ytime=inpData.frame_max, title=None, legend=True, correspondLine=False, savepath=os.path.join(resultDir, "async.png")) """
def implementDP(type, method): # read data csvfiles = type[2:] Dir = type[0] pitchType = type[1] name = Dir.split('/')[-2] resultSuperDir = os.path.join('./result/', name) if not os.path.exists(resultSuperDir): os.mkdir(resultSuperDir) #resultSuperDir = os.path.join(resultSuperDir, '{0}-corr'.format(pitchType)) resultSuperDir = os.path.join(resultSuperDir, '{0}-{1}'.format(pitchType, method)) if not os.path.exists(resultSuperDir): os.mkdir(resultSuperDir) reffile = referenceReader("{0}-{1}.csv".format(name, pitchType), Dir, superDir=name) refData = csvReader(csvfiles[csvfiles.index(reffile)], Dir) if 'corrcoef' in method: corrcoef = writecorrcoef(Dir, csvfiles, showcorrcoef=False, savecsvpath=os.path.join( resultSuperDir, 'correlation-coefficients.csv')) for i, csvfile in enumerate(csvfiles): sys.stdout.write("\rcalculating now... {0}/{1}".format( i, len(csvfiles))) sys.stdout.flush() if csvfile == reffile: continue inpData = csvReader(csvfile, Dir) DP_ = DP(refData, inpData, verbose=False, ignoreWarning=True, verboseNan=False) resultDir = os.path.join(resultSuperDir, csvfile[:-4]) if not os.path.exists(resultDir): os.mkdir(resultDir) if method == 'independent': DP_.calc(showresult=False, resultdir=resultDir, correspondLine=True) view = Visualization() X, Y = DP_.resultData() view.show(x=X, y=Y, xtime=refData.frame_max, ytime=inpData.frame_max, title='overlayed all matching costs', legend=True, correspondLine=False, savepath=resultDir + "/overlayed-all-matching-costs.png") elif method == 'corrcoef': DP_.calc_corrcoef(corrcoef, showresult=False, resultdir=resultDir, correspondLine=True) elif method == 'comp-ind-corrcoef': view = Visualization() DP_.calc(showresult=False) indeopendentX, indeopendentY = DP_.resultData() DP_.calc_corrcoef(corrcoef, showresult=False) corrcoefX, corrcoefY = DP_.resultData() for joint in refData.joints.keys(): if joint not in DP_.correspondents.keys(): continue X = {} Y = {} X['independent'] = indeopendentX[joint] Y['independent'] = indeopendentY[joint] X['correlation efficient'] = corrcoefX[joint] Y['correlation efficient'] = corrcoefY[joint] view.show(x=X, y=Y, xtime=refData.frame_max, ytime=inpData.frame_max, title=joint, legend=True, savepath=resultDir + "/{0}-R_{1}-I_{2}.png".format( joint, refData.name, inpData.name)) elif method == 'fixedInitial-independent': DP_.calcCorrespondInitial(showresult=False, resultdir=resultDir, correspondLine=True) view = Visualization() X, Y = DP_.resultData() view.show(x=X, y=Y, xtime=refData.frame_max, ytime=inpData.frame_max, title='overlayed all matching costs', legend=True, correspondLine=True, savepath=resultDir + "/overlayed-all-matching-costs.png") elif method == 'fixedInitial-independent-visualization': fps = 240 colors = DP_.resultVisualization(fps=fps, maximumGapTime=0.1, resultDir=resultDir) # DP_.input.show(fps=fps, colors=colors) DP_.input.save( path=resultDir + "/R_{0}-I_{1}.mp4".format(refData.name, inpData.name), fps=fps, colors=colors, saveonly=True) else: raise ValueError("{0} is invalid method".format(method)) print("\nfinished {0}-{1}".format(name, pitchType))
def implementDP(dir, refname, inpname, refini, reffin, inpini, inpfin): # read data name = os.path.basename(os.path.dirname(dir)) resultSuperDir = os.path.join('./compareDP/', name) if not os.path.exists(resultSuperDir): os.mkdir(resultSuperDir) # resultSuperDir = os.path.join(resultSuperDir, '{0}-corr'.format(pitchType)) resultSuperDir = os.path.join(resultSuperDir, 'r{0}-i{1}'.format(refname.split('.')[0], inpname.split('.')[0])) if not os.path.exists(resultSuperDir): os.mkdir(resultSuperDir) refData = csvReader(refname, dir) # rename joint for joint in list(refData.joints.keys()): refData.joints[joint.split(':')[-1]] = refData.joints.pop(joint) refData.cutFrame(ini=refini, fin=reffin, save=True, update=False) inpData = csvReader(inpname, dir) # rename joint for joint in list(inpData.joints.keys()): inpData.joints[joint.split(':')[-1]] = inpData.joints.pop(joint) inpData.cutFrame(ini=inpini, fin=inpfin, save=True, update=False) contexts = [['RFHD', 'LFHD'], ['RBHD', 'LBHD'], ['T10', 'RBAK'], ['CLAV', 'RSHO', 'LSHO'], ['RELB', 'RUPA', 'RFRM'], ['LELB', 'LUPA', 'LFRM'], ['RFIN', 'RWRA', 'RWRB'], ['LFIN', 'LWRA', 'LWRB'], ['LPSI', 'RPSI'], ['RTHI', 'RASI', 'RKNE'], ['LTHI', 'LASI', 'LKNE'], ['RANK', 'RTOE', 'RTIB'], ['LANK', 'LTOE', 'LTIB']] kinds = ['async2-visualization2', 'async2-visualization2', 'async2-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async2-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2'] # independent DP_ = DP(refData, inpData, verbose=False, ignoreWarning=True, verboseNan=False) DP_.resultVisualization(kind='visualization2', fps=500, maximumGapTime=0.1) Xi, Yi = DP_.resultData() # sync DP_ = SyncContextDP(contexts=contexts, reference=refData, input=inpData, verbose=False, ignoreWarning=True, verboseNan=False) DP_.resultVisualization(kind='visualization2', fps=500, maximumGapTime=0.1) Xs, Ys = DP_.resultData() # async DP_ = AsyncContextDP(contexts=contexts, reference=refData, input=inpData, verbose=False, ignoreWarning=True, verboseNan=False) DP_.resultVisualization(kinds=kinds, kind='visualization2', fps=500, maximumGapTime=0.1) Xa, Ya = DP_.resultData() for context in contexts: xi, yi = {}, {} xs, ys = {}, {} xa, ya = {}, {} #x, y = {}, {} title = '' syncname = '' for joint in context: xi[joint], yi[joint] = Xi[joint], Yi[joint] xa[joint], ya[joint] = Xa[joint], Ya[joint] title += joint + '-' syncname += joint + ',' title = title[:-1] syncname = syncname[:-1] xs[syncname], ys[syncname] = Xs[joint], Ys[joint] resultDir = os.path.join(resultSuperDir, title) if not os.path.exists(resultDir): os.mkdir(resultDir) viewi = Visualization() viewi.show(x=xi, y=yi, xtime=refData.frame_max, ytime=inpData.frame_max, title=None, legend=True, correspondLine=False, savepath=os.path.join(resultDir, "independent.png")) views = Visualization() views.show(x=xs, y=ys, xtime=refData.frame_max, ytime=inpData.frame_max, title=None, legend=True, correspondLine=False, savepath=os.path.join(resultDir, "sync.png")) viewa = Visualization() viewa.show(x=xa, y=ya, xtime=refData.frame_max, ytime=inpData.frame_max, title=None, legend=True, correspondLine=False, savepath=os.path.join(resultDir, "async.png")) """
def implementDP(name, serve, method, initFileNum, finFileNum): Dir = "./trc/" + name resultSuperDir = os.path.join('./result/', name) if not os.path.exists(resultSuperDir): os.mkdir(resultSuperDir) #resultSuperDir = os.path.join(resultSuperDir, 'normal-independent') resultSuperDir = os.path.join(resultSuperDir, '{0}-{1}'.format(serve, method)) if not os.path.exists(resultSuperDir): os.mkdir(resultSuperDir) #reffile = referenceReader("{0}-normal.csv".format(name), Dir, superDir=name) reffile = referenceReader("{0}-{1}.csv".format(name, serve), Dir, superDir=name) refData = Data() refData.set_from_trc(os.path.join(Dir, reffile), lines='volleyball') contexts = [['head', 'R_ear', 'L_ear'], ['R_hand', 'R_in_wrist', 'R_out_wrist'], ['L_hand', 'L_in_wrist', 'L_out_wrist'], ['R_out_elbow', 'R_in_elbow', 'R_backshoulder'], ['L_out_elbow', 'L_in_elbow', 'L_backshoulder'], ['sternum', 'R_frontshoulder', 'L_frontshoulder'], ['R_rib', 'R_ASIS'], ['L_rib', 'L_ASIS'], ['R_PSIS', 'L_PSIS']] kinds = [ 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async2-visualization2', 'async2-visualization2', 'async2-visualization2' ] """ kinds = ['async3-lined-asynm', 'async3-lined-asynm', 'async3-lined-asynm', 'async3-lined-asynm', 'async3-lined-asynm', 'async3-lined-asynm', 'async2-asynm', 'async2-asynm', 'async2-asynm'] """ #contexts = [['R_PSIS', 'L_PSIS']] #kinds = ['async2-visualization2'] #contexts = [['R_out_elbow', 'R_in_elbow', 'R_backshoulder']] #kinds = ['async3-visualization2'] for i in range(initFileNum, finFileNum + 1): sys.stdout.write("\rcalculating now... {0}/{1}".format( i - initFileNum, finFileNum + 1 - initFileNum)) sys.stdout.flush() filename = '{0}{1:02d}.trc'.format(name, i) if filename in reffile: continue inpData = Data() inpData.set_from_trc(os.path.join('./trc', name, filename), lines='volleyball') if 'async' in method: # async context dp DP_ = AsyncContextDP(contexts=contexts, reference=refData, input=inpData, verbose=False, ignoreWarning=True, verboseNan=False) else: DP_ = SyncContextDP(contexts=contexts, reference=refData, input=inpData, verbose=False, ignoreWarning=True, verboseNan=False) resultDir = os.path.join(resultSuperDir, filename[:-4]) if not os.path.exists(resultDir): os.mkdir(resultDir) if method == 'sync': DP_.synchronous() view = Visualization() X, Y = DP_.resultData() view.show(x=X, y=Y, xtime=refData.frame_max, ytime=inpData.frame_max, title='overlayed all matching costs', legend=True, correspondLine=False, savepath=resultDir + "/overlayed-all-matching-costs.png") elif method == 'sync-visualization': fps = 240 colors = DP_.resultVisualization(kind='visualization', fps=fps, maximumGapTime=0.1, resultDir=resultDir) DP_.input.show(fps=fps, colors=colors) DP_.input.save( path=resultDir + "/R_{0}-I_{1}.mp4".format(refData.name, inpData.name), fps=fps, colors=colors, saveonly=True) elif method == 'sync-visualization2': fps = 240 colors = DP_.resultVisualization(kind='visualization2', fps=fps, maximumGapTime=0.1, resultDir=resultDir) DP_.input.show(fps=fps, colors=colors) DP_.input.save( path=resultDir + "/R_{0}-I_{1}.mp4".format(refData.name, inpData.name), fps=fps, colors=colors, saveonly=True) elif method == 'async': DP_.asynchronous(kinds=kinds) view = Visualization() X, Y = DP_.resultData() view.show(x=X, y=Y, xtime=refData.frame_max, ytime=inpData.frame_max, title='overlayed all matching costs', legend=True, correspondLine=False, savepath=resultDir + "/overlayed-all-matching-costs.png") exit() elif method == 'async-visualization2': fps = 240 colors = DP_.resultVisualization(kinds=kinds, kind='visualization2', fps=fps, maximumGapTime=0.1, resultDir=resultDir) DP_.input.show(fps=fps, colors=colors) exit() DP_.input.save( path=resultDir + "/R_{0}-I_{1}.mp4".format(refData.name, inpData.name), fps=fps, colors=colors, saveonly=True) else: raise ValueError("{0} is invalid method".format(method)) print("\nfinished {0}-{1} in {2}".format(serve, method, name))
def implementDP(type, method): # read data csvfiles = type[2:] Dir = type[0] pitchType = type[1] name = Dir.split('/')[-2] resultSuperDir = os.path.join('./result/', name) if not os.path.exists(resultSuperDir): os.mkdir(resultSuperDir) #resultSuperDir = os.path.join(resultSuperDir, '{0}-corr'.format(pitchType)) resultSuperDir = os.path.join(resultSuperDir, '{0}-{1}'.format(pitchType, method)) if not os.path.exists(resultSuperDir): os.mkdir(resultSuperDir) reffile = referenceReader("{0}-{1}.csv".format(name, pitchType), Dir, superDir=name) refData = csvReader(csvfiles[csvfiles.index(reffile)], Dir) """ lines = [['LTOE', 'LANK'], ['LTIB', 'LANK'], ['LASI', 'LPSI'], # around ankle ['RTOE', 'RANK'], ['RTIB', 'RANK'], ['RASI', 'RPSI'], # " ['LASI', 'RASI'], ['LPSI', 'RPSI'], ['LHEE', 'LANK'], ['RHEE', 'RANK'], ['LHEE', 'LTOE'], ['RHEE', 'RTOE'], # around hip ['LHEE', 'LTIB'], ['RHEE', 'RTIB'], # connect ankle to knee ['LKNE', 'LTIB'], ['LKNE', 'LTHI'], ['LASI', 'LTHI'], ['LPSI', 'LTHI'], # connect knee to hip ['RKNE', 'RTIB'], ['RKNE', 'RTHI'], ['RASI', 'RTHI'], ['RPSI', 'RTHI'], # " ['LPSI', 'T10'], ['RPSI', 'T10'], ['LASI', 'STRN'], ['RASI', 'STRN'], # conncet lower and upper # upper ['LFHD', 'LBHD'], ['RFHD', 'RBHD'], ['LFHD', 'RFHD'], ['LBHD', 'RBHD'], # around head ['LBHD', 'C7'], ['RBHD', 'C7'], ['C7', 'CLAV'], ['CLAV', 'LSHO'], ['CLAV', 'RSHO'],# connect head to shoulder ['LSHO', 'LBAK'], ['RSHO', 'RBAK'], ['RBAK', 'LBAK'], # around shoulder ['LWRA', 'LFIN'], ['LWRA', 'LFIN'], ['LWRA', 'LWRB'], ['LWRA', 'LFRM'], ['LWRB', 'LFRM'],# around wrist ['RWRA', 'RFIN'], ['RWRA', 'RFIN'], ['RWRA', 'RWRB'], ['RWRA', 'RFRM'], ['RWRB', 'RFRM'], # " ['LELB', 'LRFM'], ['LELB', 'LUPA'], ['LELB', 'LFIN'], ['LUPA', 'LSHO'],# connect elbow to wrist, connect elbow to shoulder ['RELB', 'RRFM'], ['RELB', 'RUPA'], ['RELB', 'RFIN'], ['RUPA', 'RSHO'], # " ['LSHO', 'STRN'], ['RSHO', 'STRN'], ['LBAK', 'T10'], ['RBAK', 'T10'],# connect shoulder to torso ] """ contexts = [['RFHD', 'LFHD'], ['RBHD', 'LBHD'], ['T10', 'RBAK'], ['CLAV', 'RSHO', 'LSHO'], ['RELB', 'RUPA', 'RFRM'], ['LELB', 'LUPA', 'LFRM'], ['RFIN', 'RWRA', 'RWRB'], ['LFIN', 'LWRA', 'LWRB'], ['LPSI', 'RPSI'], ['RTHI', 'RASI', 'RKNE'], ['LTHI', 'LASI', 'LKNE'], ['RANK', 'RTOE', 'RTIB'], ['LANK', 'LTOE', 'LTIB']] tmp = [] for context in contexts: tmp_ = [] for joint in context: tmp_.append('Skeleton 02:{0}'.format(joint)) tmp.append(tmp_) contexts = tmp kinds = [ 'async2-visualization2', 'async2-visualization2', 'async2-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async2-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2', 'async3-visualization2' ] for i, csvfile in enumerate(csvfiles): sys.stdout.write("\rcalculating now... {0}/{1}".format( i, len(csvfiles))) sys.stdout.flush() if csvfile == reffile: continue inpData = csvReader(csvfile, Dir) if 'async' in method: # async context dp DP_ = AsyncContextDP(contexts=contexts, reference=refData, input=inpData, verbose=False, ignoreWarning=True, verboseNan=False) else: DP_ = SyncContextDP(contexts=contexts, reference=refData, input=inpData, verbose=False, ignoreWarning=True, verboseNan=False) resultDir = os.path.join(resultSuperDir, csvfile[:-4]) if not os.path.exists(resultDir): os.mkdir(resultDir) if method == 'independent': DP_.synchronous() view = Visualization() X, Y = DP_.resultData() view.show(x=X, y=Y, xtime=refData.frame_max, ytime=inpData.frame_max, title='overlayed all matching costs', legend=True, correspondLine=False, savepath=resultDir + "/overlayed-all-matching-costs.png") elif method == 'sync-visualization': fps = 240 colors = DP_.resultVisualization(kind='visualization', fps=fps, maximumGapTime=0.1, resultDir=resultDir) DP_.input.show(fps=fps, colors=colors) DP_.input.save( path=resultDir + "/R_{0}-I_{1}.mp4".format(refData.name, inpData.name), fps=fps, colors=colors, saveonly=True) elif method == 'sync-visualization2': fps = 240 colors = DP_.resultVisualization(kind='visualization2', fps=fps, maximumGapTime=0.1, resultDir=resultDir) DP_.input.show(fps=fps, colors=colors) DP_.input.save( path=resultDir + "/R_{0}-I_{1}.mp4".format(refData.name, inpData.name), fps=fps, colors=colors, saveonly=True) elif method == 'async': DP_.asynchronous(kinds=kinds) view = Visualization() X, Y = DP_.resultData() view.show(x=X, y=Y, xtime=refData.frame_max, ytime=inpData.frame_max, title='overlayed all matching costs', legend=True, correspondLine=False, savepath=resultDir + "/overlayed-all-matching-costs.png") exit() elif method == 'async-visualization2': fps = 240 colors = DP_.resultVisualization(kinds=kinds, kind='visualization2', fps=fps, maximumGapTime=0.1, resultDir=resultDir) DP_.input.show(fps=fps, colors=colors) exit() DP_.input.save( path=resultDir + "/R_{0}-I_{1}.mp4".format(refData.name, inpData.name), fps=fps, colors=colors, saveonly=True) else: raise ValueError("{0} is invalid method".format(method)) print("\nfinished {0}-{1}".format(name, pitchType))
def implementDP(name, serve, method, initFileNum, finFileNum): Dir = "./trc/" + name resultSuperDir = os.path.join('./result/', name) if not os.path.exists(resultSuperDir): os.mkdir(resultSuperDir) #resultSuperDir = os.path.join(resultSuperDir, 'normal-independent') resultSuperDir = os.path.join(resultSuperDir, '{0}-{1}'.format(serve, method)) if not os.path.exists(resultSuperDir): os.mkdir(resultSuperDir) #reffile = referenceReader("{0}-normal.csv".format(name), Dir, superDir=name) reffile = referenceReader("{0}-{1}.csv".format(name, serve), Dir, superDir=name) refData = Data() refData.set_from_trc(os.path.join(Dir, reffile), lines='volleyball') if 'corrcoef' in method: corrcoef = writecorrcoef(name, initFileNum, finFileNum, showcorrcoef=False, savescvpath=os.path.join( resultSuperDir, 'correlation-coefficients.csv')) for i in range(initFileNum, finFileNum + 1): sys.stdout.write("\rcalculating now... {0}/{1}".format( i - initFileNum, finFileNum + 1 - initFileNum)) sys.stdout.flush() filename = '{0}{1:02d}.trc'.format(name, i) if filename in reffile: continue inpData = Data() inpData.set_from_trc(os.path.join('./trc', name, filename), lines='volleyball') DP_ = DP(refData, inpData, verbose=False, ignoreWarning=True, verboseNan=False) resultDir = os.path.join(resultSuperDir, filename[:-4]) if not os.path.exists(resultDir): os.mkdir(resultDir) if method == 'independent': DP_.calc(showresult=False, resultdir=resultDir, correspondLine=True) view = Visualization() X, Y = DP_.resultData() view.show(x=X, y=Y, xtime=refData.frame_max, ytime=inpData.frame_max, title='overlayed all matching costs', legend=True, correspondLine=False, savepath=resultDir + "/overlayed-all-matching-costs.png") elif method == 'corrcoef': DP_.calc_corrcoef(corrcoef, showresult=False, resultdir=resultDir, correspondLine=True) elif method == 'comp-ind-corrcoef': view = Visualization() DP_.calc(showresult=False) indeopendentX, indeopendentY = DP_.resultData() DP_.calc_corrcoef(corrcoef, showresult=False) corrcoefX, corrcoefY = DP_.resultData() for joint in refData.joints.keys(): if joint not in DP_.correspondents.keys(): continue X = {} Y = {} X['independent'] = indeopendentX[joint] Y['independent'] = indeopendentY[joint] X['correlation efficient'] = corrcoefX[joint] Y['correlation efficient'] = corrcoefY[joint] view.show(x=X, y=Y, xtime=refData.frame_max, ytime=inpData.frame_max, title=joint, legend=True, savepath=resultDir + "/{0}-R_{1}-I_{2}.png".format( joint, refData.name, inpData.name)) elif method == 'fixedInitial-independent': DP_.calcCorrespondInitial(showresult=False, resultdir=resultDir, correspondLine=True) view = Visualization() X, Y = DP_.resultData() view.show(x=X, y=Y, xtime=refData.frame_max, ytime=inpData.frame_max, title='overlayed all matching costs', legend=True, correspondLine=True, savepath=resultDir + "/overlayed-all-matching-costs.png") elif method == 'fixedInitial-independent-visualization': fps = 240 colors = DP_.resultVisualization(kind='visualization', fps=fps, maximumGapTime=0.1, resultDir=resultDir) DP_.input.show(fps=fps, colors=colors) DP_.input.save( path=resultDir + "/R_{0}-I_{1}.mp4".format(refData.name, inpData.name), fps=fps, colors=colors, saveonly=True) elif method == 'fixedInitial-independent-visualization2': fps = 240 colors = DP_.resultVisualization(kind='visualization2', fps=fps, maximumGapTime=0.1, resultDir=resultDir) DP_.input.show(fps=fps, colors=colors) exit() DP_.input.save( path=resultDir + "/R_{0}-I_{1}.mp4".format(refData.name, inpData.name), fps=fps, colors=colors, saveonly=True) else: raise ValueError("{0} is invalid method".format(method)) print("\nfinished {0}-{1} in {2}".format(serve, method, name))