def calculateErrorMetricsSingleFrame(file1, warmup1, file2, warmup2, frame): data1 = readBVH(file1) data2 = readBVH(file2) if (len(data1) - 2 * warmup1 != len(data2) - 2 * warmup2): return ([], []) mat = [] for i in range(warmup1, len(data1) - warmup1): vec = [] for j in range(len(data1[i])): vec.append(data1[i][j] - data2[i + warmup2 - warmup1][j]) mat.append(vec) L1 = [0.0] * len(mat[0]) L2 = [0.0] * len(mat[0]) for j in range(len(mat[frame])): L1[j] = math.fabs(mat[frame][j]) L2[j] = mat[i][j] * mat[frame][j] return (L1, L2)
def calculateErrorMetrics(file1, warmup1, file2, warmup2): data1 = readBVH(file1) data2 = readBVH(file2) if (len(data1) - 2 * warmup1 != len(data2) - 2 * warmup2): return ([], []) mat = [] for i in range(warmup1, len(data1) - warmup1): vec = [] for j in range(len(data1[i])): vec.append(data1[i][j] - data2[i + warmup2 - warmup1][j]) mat.append(vec) L1 = 0.0 L2 = 0.0 for i in range(len(mat)): for j in range(len(mat[i])): L1 += math.fabs(mat[i][j]) L2 += (mat[i][j] * mat[i][j]) L1 = L1 / (len(mat) * len(mat[0])) L2 = L2 / (len(mat) * len(mat[0])) return (L1, L2)
def calculateErrorMetricsSumChannel(file1, warmup1, file2, warmup2): data1 = readBVH(file1) data2 = readBVH(file2) if (len(data1) - 2 * warmup1 != len(data2) - 2 * warmup2): return ([], []) mat = [] for i in range(warmup1, len(data1) - warmup1): vec = [] for j in range(len(data1[i])): vec.append(data1[i][j] - data2[i + warmup2 - warmup1][j]) mat.append(vec) L1 = [0.0] * len(mat) L2 = [0.0] * len(mat) for i in range(len(mat)): for j in range(6, len(mat[i])): L1[i] += math.fabs(mat[i][j]) L2[i] += (mat[i][j] * mat[i][j]) for i in range(len(L1)): L1[i] = L1[i] / (len(mat[0]) - 6) L2[i] = L2[i] / (len(mat[0]) - 6) return (L1, L2)
def read_files(dir, subjects): files = [] for subject in subjects: files += [ join(join(dir, subject), tmp) for tmp in listdir(join(dir, subject)) ] logger.logger.info("Files to be read %d", len(files)) data = [] for file in files: data.append(readBVH(file)) logger.logger.info("Read %d files", len(files)) return data
def calculateErrorMetricsSumFrame(file1, warmup1, file2, warmup2): data1 = readBVH(file1) data2 = readBVH(file2) if (len(data1) - 2 * warmup1 != len(data2) - 2 * warmup2): print(len(data1)) print(len(data2)) print("Incorrect offset or file out of sync") return ([], []) mat = [] for i in range(warmup1, len(data1) - warmup1): vec = [] for j in range(len(data1[i])): vec.append(data1[i][j] - data2[i + warmup2 - warmup1][j]) mat.append(vec) L1 = [0.0] * len(mat[0]) L2 = [0.0] * len(mat[0]) for i in range(len(mat)): for j in range(len(mat[i])): L1[j] += math.fabs(mat[i][j]) L2[j] += (mat[i][j] * mat[i][j]) for i in range(len(L1)): L1[i] = L1[i] / (len(mat)) L2[i] = L2[i] / (len(mat)) return (L1, L2)
import bvh23d import bvhHandler as bh import argparse parser = argparse.ArgumentParser() parser.add_argument("-fn", "--filename", required=True) args = parser.parse_args() filename = args.filename header = bvh23d.readHeader("BVHHeader.txt") tree = bvh23d.Tree(header) frames = bh.readBVH(filename) frames_new = [] for i in range(0, len(frames)): tree.set_dof_values(frames[i]) tree.set_transformations_values() ret = tree.get_position() #output format for point cloud viewer # for reti in ret: # print(str(reti[0])+" "+str(reti[1])+" "+str(reti[2])+" "+"1 1 1") frames_new.append(ret) print(frames_new)
############################################################################ # List all files in id subdirs = os.listdir(input_dir) files = [] for subdir in subdirs: files += [(subdir, tmp) for tmp in os.listdir(join(input_dir, subdir))] print(files) ############################################################################ BVHHeader = "../Lib/BVHHeader96.txt" header = bvh23d.readHeader(BVHHeader) tree = bvh23d.Tree(header) for k in range(len(files)): frames = bh.readBVH(join(input_dir, files[k][0], files[k][1])) frames_new = [] pts = [] for i in range(0, len(frames)): tree.set_dof_values(frames[i]) tree.set_transformations_values() frame = [] pos = tree.get_position() for tup in pos: frame += list(tup) pts.append(list(tup)) frames_new.append(frame[3:]) if (not isdir(join(output_dir, files[k][0]))): os.mkdir(join(output_dir, files[k][0])) np.savetxt(join(output_dir, files[k][0], files[k][1]),