Spaces:
Build error
Build error
zejunyang
commited on
Commit
·
537435d
1
Parent(s):
c8ab10f
update
Browse files- src/vid2vid.py +9 -6
src/vid2vid.py
CHANGED
|
@@ -23,7 +23,7 @@ from src.utils.util import get_fps, read_frames, save_videos_grid
|
|
| 23 |
|
| 24 |
from src.utils.mp_utils import LMKExtractor
|
| 25 |
from src.utils.draw_util import FaceMeshVisualizer
|
| 26 |
-
from src.utils.pose_util import project_points_with_trans,
|
| 27 |
from src.audio2vid import smooth_pose_seq
|
| 28 |
|
| 29 |
|
|
@@ -153,21 +153,24 @@ def video2video(ref_img, source_video, size=512, steps=25, length=150, seed=42):
|
|
| 153 |
min_bs_idx = np.argmin(bs_arr.sum(1))
|
| 154 |
|
| 155 |
# compute delta pose
|
| 156 |
-
trans_mat_inv_frame_0 = np.linalg.inv(trans_mat_arr[0])
|
| 157 |
pose_arr = np.zeros([trans_mat_arr.shape[0], 6])
|
| 158 |
|
| 159 |
for i in range(pose_arr.shape[0]):
|
| 160 |
-
|
| 161 |
-
euler_angles, translation_vector = matrix_to_euler_and_translation(pose_mat)
|
| 162 |
pose_arr[i, :3] = euler_angles
|
| 163 |
pose_arr[i, 3:6] = translation_vector
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
-
|
|
|
|
|
|
|
| 166 |
|
| 167 |
# face retarget
|
| 168 |
verts_arr = verts_arr - verts_arr[min_bs_idx] + face_result['lmks3d']
|
| 169 |
# project 3D mesh to 2D landmark
|
| 170 |
-
projected_vertices = project_points_with_trans(verts_arr,
|
| 171 |
|
| 172 |
pose_list = []
|
| 173 |
for i, verts in enumerate(projected_vertices):
|
|
|
|
| 23 |
|
| 24 |
from src.utils.mp_utils import LMKExtractor
|
| 25 |
from src.utils.draw_util import FaceMeshVisualizer
|
| 26 |
+
from src.utils.pose_util import project_points_with_trans, matrix_to_euler_and_translation, euler_and_translation_to_matrix
|
| 27 |
from src.audio2vid import smooth_pose_seq
|
| 28 |
|
| 29 |
|
|
|
|
| 153 |
min_bs_idx = np.argmin(bs_arr.sum(1))
|
| 154 |
|
| 155 |
# compute delta pose
|
|
|
|
| 156 |
pose_arr = np.zeros([trans_mat_arr.shape[0], 6])
|
| 157 |
|
| 158 |
for i in range(pose_arr.shape[0]):
|
| 159 |
+
euler_angles, translation_vector = matrix_to_euler_and_translation(trans_mat_arr[i]) # real pose of source
|
|
|
|
| 160 |
pose_arr[i, :3] = euler_angles
|
| 161 |
pose_arr[i, 3:6] = translation_vector
|
| 162 |
+
|
| 163 |
+
init_tran_vec = face_result['trans_mat'][:3, 3] # init translation of tgt
|
| 164 |
+
pose_arr[:, 3:6] = pose_arr[:, 3:6] - pose_arr[0, 3:6] + init_tran_vec # (relative translation of source) + (init translation of tgt)
|
| 165 |
|
| 166 |
+
pose_arr_smooth = smooth_pose_seq(pose_arr, window_size=3)
|
| 167 |
+
pose_mat_smooth = [euler_and_translation_to_matrix(pose_arr_smooth[i][:3], pose_arr_smooth[i][3:6]) for i in range(pose_arr_smooth.shape[0])]
|
| 168 |
+
pose_mat_smooth = np.array(pose_mat_smooth)
|
| 169 |
|
| 170 |
# face retarget
|
| 171 |
verts_arr = verts_arr - verts_arr[min_bs_idx] + face_result['lmks3d']
|
| 172 |
# project 3D mesh to 2D landmark
|
| 173 |
+
projected_vertices = project_points_with_trans(verts_arr, pose_mat_smooth, [frame_height, frame_width])
|
| 174 |
|
| 175 |
pose_list = []
|
| 176 |
for i, verts in enumerate(projected_vertices):
|