Example #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)
Example #2
0
def csvReader(csvfile, dir):

    tmplists = []

    with open(dir + csvfile, "r") as f:
        reader = csv.reader(f)
        for row in reader:
            tmplists.append(row)

    time = len(tmplists) - 7
    data = Data(interpolate='linear')

    jointNames = []
    X = []
    Y = []
    Z = []

    index = 2
    while index < len(tmplists[6]):
        if tmplists[5][index] == 'Position':
            if tmplists[2][index] == 'Bone Marker' and tmplists[3][index].find('Unlabeled') < 0:
                x = np.array(
                    [tmplists[i][index] if tmplists[i][index] != '' else np.nan for i in
                     range(7, len(tmplists))],
                    dtype='float')
                y = np.array([tmplists[i][index + 1] if tmplists[i][index + 1] != '' else np.nan for i in
                              range(7, len(tmplists))], dtype='float')
                z = np.array([tmplists[i][index + 2] if tmplists[i][index + 2] != '' else np.nan for i in
                              range(7, len(tmplists))], dtype='float')
                X.append(x)
                Y.append(y)
                Z.append(z)
                jointNames.append(tmplists[3][index])
            index += 3
        elif tmplists[5][index] == 'Rotation':
            index += 4

    data.setvalues(csvfile, np.array(X), np.array(Y), np.array(Z), jointNames, dir=dir, lines='baseball')

    return data