Exemplo n.º 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)
Exemplo n.º 2
0
def writecorrcoef(Dir, csvfiles, showcorrcoef, savecsvpath):
    Datalists = []
    for csvfile in csvfiles:
        data = csvReader(csvfile, Dir)
        Datalists.append(data)
    return corrcoefMean(Datalists,
                        verbose=False,
                        showcorrcoef=showcorrcoef,
                        savecsvpath=savecsvpath)
Exemplo n.º 3
0
def main():
    with open('pitch-type.csv', 'r') as f:
        reader = csv.reader(f)
        for type in reader:
            # read data
            csvfiles = type[2:]

            # read all data and hold it to DataList
            for csvfile in csvfiles:
                data = csvReader(csvfile, type[0])
                data.save('__video/{0}.mp4'.format(csvfile[:-4]), fps=240, saveonly=True)
            exit()
Exemplo n.º 4
0
def main():
    with open('pitch-type.csv', 'r') as f:
        reader = csv.reader(f)
        for type in reader:
            # read data
            DataLists = []
            csvfiles = type[2:]
            Dir = type[0]
            name = Dir.split('/')[-2]
            # read all data and hold it to DataList
            for csvfile in csvfiles:
                data = csvReader(csvfile, type[0])
                DataLists.append(data)

            # detect reference
            referenceDetector(DataLists, name + '-' + type[1] + '.csv', superDir=name)
Exemplo n.º 5
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))
Exemplo n.º 6
0
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"))
        """
Exemplo n.º 7
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))