Update sequence_utils.py
Browse files- sequence_utils.py +25 -26
sequence_utils.py
CHANGED
|
@@ -1,26 +1,25 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import cv2
|
| 3 |
-
import torch
|
| 4 |
-
from imageio_ffmpeg import get_ffmpeg_exe
|
| 5 |
-
|
| 6 |
-
def extract_kps_sequence_from_video(
|
| 7 |
-
face_analysis_app,
|
| 8 |
-
video_path, audio_save_path,
|
| 9 |
-
kps_sequence_save_path):
|
| 10 |
-
os.system(f'{get_ffmpeg_exe()} -i "{video_path}" -y -vn "{audio_save_path}"')
|
| 11 |
-
|
| 12 |
-
kps_sequence = []
|
| 13 |
-
video_capture = cv2.VideoCapture(video_path)
|
| 14 |
-
frame_idx = 0
|
| 15 |
-
while video_capture.isOpened():
|
| 16 |
-
ret, frame = video_capture.read()
|
| 17 |
-
if not ret:
|
| 18 |
-
break
|
| 19 |
-
faces = face_analysis_app.get(frame)
|
| 20 |
-
assert len(faces) == 1, f'There are {len(faces)} faces in the {frame_idx}-th frame. Only one face is supported.'
|
| 21 |
-
|
| 22 |
-
kps = faces[0].kps[:3]
|
| 23 |
-
kps_sequence.append(kps)
|
| 24 |
-
frame_idx += 1
|
| 25 |
-
torch.save(kps_sequence, kps_sequence_save_path)
|
| 26 |
-
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import cv2
|
| 3 |
+
import torch
|
| 4 |
+
from imageio_ffmpeg import get_ffmpeg_exe
|
| 5 |
+
|
| 6 |
+
def extract_kps_sequence_from_video(
|
| 7 |
+
face_analysis_app,
|
| 8 |
+
video_path, audio_save_path,
|
| 9 |
+
kps_sequence_save_path):
|
| 10 |
+
os.system(f'{get_ffmpeg_exe()} -i "{video_path}" -y -vn "{audio_save_path}"')
|
| 11 |
+
|
| 12 |
+
kps_sequence = []
|
| 13 |
+
video_capture = cv2.VideoCapture(video_path)
|
| 14 |
+
frame_idx = 0
|
| 15 |
+
while video_capture.isOpened():
|
| 16 |
+
ret, frame = video_capture.read()
|
| 17 |
+
if not ret:
|
| 18 |
+
break
|
| 19 |
+
faces = face_analysis_app.get(frame)
|
| 20 |
+
assert len(faces) == 1, f'There are {len(faces)} faces in the {frame_idx}-th frame. Only one face is supported.'
|
| 21 |
+
|
| 22 |
+
kps = faces[0].kps[:3]
|
| 23 |
+
kps_sequence.append(kps)
|
| 24 |
+
frame_idx += 1
|
| 25 |
+
torch.save(kps_sequence, kps_sequence_save_path)
|
|
|