def writecorrcoef(name, initFileNum, finFileNum, showcorrcoef, savescvpath): Datalists = [] Dir = "./trc/" + name for i in range(initFileNum, finFileNum + 1): filename = name + '{0:02d}.trc'.format(i) data = Data() data.set_from_trc(os.path.join(Dir, filename), lines='volleyball') Datalists.append(data) return corrcoefMean(Datalists, verbose=False, showcorrcoef=showcorrcoef, savecsvpath=savescvpath)
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")) """
from dp.dp import DP from dp.data import Data from dp.utils import referenceDetector Datalists = [] for i in range(1, 7 + 1): data = Data() data.set_from_trc('./trc/IMAMURA/IMAMURA{0:02d}.trc'.format(i), lines='volleyball') Datalists.append(data) referenceDetector(Datalists, 'IMAMURA-normal.csv', superDir='IMAMURA', verbose=False, verboseNan=False) Datalists = [] for i in range(8, 34 + 1): data = Data() data.set_from_trc('./trc/IMAMURA/IMAMURA{0:02d}.trc'.format(i), lines='volleyball') Datalists.append(data) referenceDetector(Datalists, 'IMAMURA-strong.csv', superDir='IMAMURA', verbose=False, verboseNan=False) Datalists = [] for i in range(35, 36 + 1): data = Data()
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(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))