interact / scripts /face_ict_to_arkit.py
leohocs's picture
Upload 9 files
05aeae1 verified
# This script converts the .npy which currently contains 55 blendshapes
# to ARKit space which has 51 blendshapes. It removes the 10 and 11th index
# and merges the 2nd and 3rd index together, and 6th and 7th index together.
import os
import numpy as np
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--input', '-i', type=str, default=os.path.join('..', 'face_ict'), help='Path to arkit npy file or folder')
parser.add_argument('--output', '-o', type=str, default=os.path.join('..', 'face_arkit_copy'), help='Folder path to store output npy sequence file')
args = parser.parse_args()
os.makedirs(args.output, exist_ok=True)
input_files = []
if os.path.isdir(args.input):
input_files = [os.path.join(args.input, f) for f in sorted(os.listdir(args.input)) if f.endswith('.npy')]
else:
input_files = [args.input]
for file_path in input_files:
vert_seq = np.load(file_path) # (N, 55)
part_1 = vert_seq[:, :2] # (N, 2)
merge_1 = vert_seq[:, 2:4].mean(axis=1).reshape(-1, 1) # (N, 1)
part_2 = vert_seq[:, 4:6] # (N, 2)
merge_2 = vert_seq[:, 6:8].mean(axis=1).reshape(-1, 1) # (N, 1)
part_3 = vert_seq[:, 8:10] # (N, 2)
part_4 = vert_seq[:, 12:] # (N, 43)
new_vert_seq = np.concatenate([part_1, merge_1, part_2, merge_2, part_3, part_4], axis=1) # (N, 51)
output_path = os.path.join(args.output, os.path.basename(file_path))
np.save(output_path, new_vert_seq)
print("Saving to", output_path)