Beispiel #1
0
def main():
    with open('pitch-type.csv', 'r') as f:
        reader = csv.reader(f)
        for type in reader:
            # read data
            AlignedDataLists = []  # [csvfile index][joint index][time][dim]
            csvfiles = type[2:]
            Dir = type[0]
            name = Dir.split('/')[-2]
            # read all data and hold it to DataList
            refpath = referenceReader(name + '-' + type[1] + '.csv',
                                      Dir,
                                      superDir=name)
            #print(refpath)

            refData = csvReader(refpath, type[0])
            #refData.show()
            #exit()
            for csvfile in csvfiles:
                if csvfile == refpath:
                    continue

                inpData = csvReader(csvfile, Dir)
                DP_ = DP(refData, inpData, verbose=False, ignoreWarning=True)
                DP_.calc()
                # aligned

                alignedData = DP_.aligned()
                AlignedDataLists.append(np.array(list(alignedData.values())))
            AlignedDataLists = np.array(AlignedDataLists)
            #print(AlignedDataLists.shape) (9, 39, 1587, 3)
            # calculate mean
            mean = np.mean(AlignedDataLists, axis=0)  #(39, 1587, 3)
            meanData = Data(interpolate='linear')
            meanData.setvalues('mean movement',
                               x=mean[:, :, 0],
                               y=mean[:, :, 1],
                               z=mean[:, :, 2],
                               jointNames=list(refData.joints.keys()))

            variance = np.var(AlignedDataLists, axis=0)  #(39, 1587, 3)
            std = np.std(AlignedDataLists, axis=0)
            colors = std2color(std)
            #meanData.show(colors=colors)

            # save file and bone
            meanData.save(os.path.join(
                'result', name, '{0}-{1}-mean.MP4'.format(name, type[1])),
                          fps=240,
                          colors=colors,
                          saveonly=True)
Beispiel #2
0
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))
Beispiel #3
0
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))
Beispiel #4
0
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))
Beispiel #5
0
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))