def swith_identity(front_lmark = None, rt = None): denormed_lamrk = np.load(front_lmark) rt = np.load(rt) lmark_length = denormed_lamrk.shape[0] rotated = np.zeros((lmark_length, 68 , 3)) for i in range(denormed_lamrk.shape[0]): rotated[i] = util.reverse_rt(denormed_lamrk[i], rt[i]) np.save(front_lmark[:-4] + '__composed.npy', rotated)
def swith_identity(id='lisa2'): src_lmark_path = '/home/cxu-serve/p1/common/demo/00025_aligned_front.npy' tar_lmark_path = '/home/cxu-serve/p1/common/demo/' + id + '_original_front.npy' srt_rt_path = src_lmark_path.replace('front', 'rt') rt = np.load(srt_rt_path) lmark_length = rt.shape[0] src_lmark = np.load(src_lmark_path) tar_lmark = np.load(tar_lmark_path)[0] openrates = [] for i in range(src_lmark.shape[0]): openrates.append(openrate(src_lmark[i])) openrates = np.asarray(openrates) min_index = np.argmin(openrates) print(min_index) current_tempolate = src_lmark[min_index].copy() diff = current_tempolate[:, :2] - tar_lmark[:, :2] denormed_lamrk = src_lmark.copy() denormed_lamrk[:, :48, :2] = src_lmark[:, :48, :2] - diff[:48] rotated = np.zeros((denormed_lamrk.shape[0], 68, 3)) for i in range(denormed_lamrk.shape[0]): rotated[i] = util.reverse_rt(denormed_lamrk[i], rt[i]) np.save('/home/cxu-serve/p1/common/demo/00025__' + id + '__rotated.npy', rotated) np.save('/home/cxu-serve/p1/common/demo/00025__' + id + '__front.npy', denormed_lamrk)
def swith_identity_obama(obamaid='00025_aligned'): # file:///home/cxu-serve/p1/common/voxceleb2/unzip/test_video/id04094/2sjuXzB2I1M/00025.mp4 # src_lmark_path = '/home/cxu-serve/p1/common/voxceleb2/unzip/test_video/id00817/HUmfsvegMRo/00175_aligned_front.npy' src_lmark_path = '/home/cxu-serve/p1/common/Obama/video/3_3__front2.npy' # tar_lmark_path = '/home/cxu-serve/p1/common/demo/' + id + '_original_front.npy' tar_lmark_path = '/home/cxu-serve/p1/common/demo/00025__lisa2__rotated.npy' tar_front_lmark_path = '/home/cxu-serve/p1/common/demo/00025__lisa2__front.npy' srt_rt_path = '/home/cxu-serve/p1/common/demo/00025_aligned_rt.npy' print(srt_rt_path) rt = np.load(srt_rt_path) # rt = np.vstack([rt,rt[::-1,:],rt,rt[::-1,:],rt,rt[::-1,:],rt,rt[::-1,:],rt,rt[::-1,:],rt,rt[::-1,:]]) # np.save('/home/cxu-serve/p1/common/demo/3_3__rt2.npy', rt) print(rt.shape) src_lmark = np.load(src_lmark_path) tar_lmark = np.load(tar_lmark_path) # tar_lmark = np.vstack([tar_lmark,tar_lmark[::-1,:,:],tar_lmark,tar_lmark[::-1,:,:],tar_lmark,tar_lmark[::-1,:,:],tar_lmark,tar_lmark[::-1,:,:],tar_lmark,tar_lmark[::-1,:,:],tar_lmark,tar_lmark[::-1,:,:]]) # np.save('/home/cxu-serve/p1/common/demo/3_3__original2.npy', tar_lmark) lmark_length = min(src_lmark.shape[0], tar_lmark.shape[0]) find_rt = [] for t in range(0, lmark_length): find_rt.append(sum(np.absolute(rt[t, :3]))) find_rt = np.asarray(find_rt) tar_front_lmark = np.load(tar_front_lmark_path) # tar_front_lmark = np.vstack([tar_front_lmark,tar_front_lmark[::-1,:,:],tar_front_lmark,tar_front_lmark[::-1,:,:],tar_front_lmark,tar_front_lmark[::-1,:,:],tar_front_lmark,tar_front_lmark[::-1,:,:],tar_front_lmark,tar_front_lmark[::-1,:,:],tar_front_lmark,tar_front_lmark[::-1,:,:]]) # np.save('/home/cxu-serve/p1/common/demo/3_3__front2.npy', tar_front_lmark) min_indexs = np.argsort(find_rt)[:100] for indx in min_indexs: if abs(openrate(tar_lmark[indx])) < 2: min_index = indx tempolate_openrate = openrate(tar_front_lmark[indx]) break current_tempolate = tar_front_lmark[min_index].copy() for i in range(lmark_length): if abs(openrate(src_lmark[i]) - tempolate_openrate) < 0.1: src_id = i break print(min_index, src_id) diff = current_tempolate[:, :2] - src_lmark[src_id, :, :2] denormed_lamrk = tar_front_lmark[:lmark_length].copy() denormed_lamrk[:, 48:, :2] = src_lmark[:, 48:, :2] # + diff[48:] rotated = np.zeros((lmark_length, 68, 3)) for i in range(denormed_lamrk.shape[0]): rotated[i] = util.reverse_rt(denormed_lamrk[i], rt[i]) np.save('/home/cxu-serve/p1/common/demo/demo_' + obamaid + '__rotated.npy', rotated) np.save('/home/cxu-serve/p1/common/demo/demo_' + obamaid + '__front.npy', denormed_lamrk)