initial commit
This commit is contained in:
commit
c7175dd7ff
127 files changed
+13949
No files matched your search
@@ -0,0 +1,120 @@
|
||||
import os
|
||||
import json
|
||||
import pickle
|
||||
import numpy as np
|
||||
from pathlib import Path
|
||||
|
||||
import sys
|
||||
sys.path.insert(0, "/mnt/data/CODE/Audio2Expression")
|
||||
from common.landmark import landmark_normalize
|
||||
from common.animation import save_animation, save_animation_with_gt
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
path_data = Path('/mnt/data2/DATA/Obama/processing') # '../data/trinity/source'
|
||||
|
||||
|
||||
v_dir_videos = sorted(path_data.glob("*"))
|
||||
print(f"Have {len(v_dir_videos)} dir files")
|
||||
|
||||
# for each video
|
||||
for ipath_data in v_dir_videos:
|
||||
ivideo_name = ipath_data.stem
|
||||
|
||||
print(f"\n processing {ivideo_name} ... ")
|
||||
|
||||
ipath_info = ipath_data.joinpath("video/info.json")
|
||||
|
||||
ipath_ldmk_dlib = ipath_data.joinpath("landmk")
|
||||
ipath_ldmk_pfld = ipath_data.joinpath("landmk-PFLD")
|
||||
|
||||
|
||||
# load video info
|
||||
with open(str(ipath_info), "r") as f:
|
||||
info = json.load(f)
|
||||
|
||||
|
||||
fps = info["fps"]
|
||||
if len(info["active_frames"]) == 2:
|
||||
ibeg = info["active_frames"][0]
|
||||
iend = info["active_frames"][1]
|
||||
nframe_trim = iend - ibeg
|
||||
print(f"frame trim = {nframe_trim}, info['active_frames'] = {info['active_frames']}")
|
||||
else:
|
||||
print(f"ERROR: info['active_frames'] = {info['active_frames']}")
|
||||
continue
|
||||
|
||||
|
||||
# load landmark
|
||||
vldmk_dlib, vldmk_pfld = [], []
|
||||
pldmk_dlib, pldmk_pfld = None, None
|
||||
nContinue_dlib, nContinue_pfld = 0, 0
|
||||
|
||||
|
||||
for j in range(ibeg, iend):
|
||||
|
||||
# load Dlib
|
||||
jpath_ldmk_dlib = ipath_ldmk_dlib.joinpath(f"frame-{j:05d}.txt")
|
||||
jpath_ldmk_pfld = ipath_ldmk_pfld.joinpath(f"frame--{j:05d}.txt")
|
||||
|
||||
# add Dlib landmark
|
||||
if not jpath_ldmk_dlib.exists():
|
||||
print("ERROR: Missing the landmark of frame --> ", jpath_ldmk_dlib)
|
||||
if nContinue_dlib <= 2:
|
||||
data_ldmk = pldmk_dlib
|
||||
nContinue_dlib += 1
|
||||
else:
|
||||
nContinue_dlib += 1
|
||||
break
|
||||
else:
|
||||
data_ldmk = np.loadtxt(jpath_ldmk_dlib).astype(np.float)
|
||||
data_ldmk, _, _ = landmark_normalize(data_ldmk)
|
||||
|
||||
pldmk_dlib = data_ldmk
|
||||
nContinue_dlib = 0
|
||||
vldmk_dlib.append(data_ldmk)
|
||||
|
||||
# add PFLD landmark
|
||||
if not jpath_ldmk_pfld.exists():
|
||||
print("ERROR: Missing the landmark of frame --> ", jpath_ldmk_pfld)
|
||||
if nContinue_pfld <= 2:
|
||||
data_ldmk = pldmk_pfld
|
||||
nContinue_pfld += 1
|
||||
else:
|
||||
nContinue_pfld += 1
|
||||
break
|
||||
else:
|
||||
data_ldmk = np.loadtxt(jpath_ldmk_pfld).astype(np.float)
|
||||
data_ldmk, _, _ = landmark_normalize(data_ldmk)
|
||||
|
||||
pldmk_pfld = data_ldmk
|
||||
nContinue_pfld = 0
|
||||
vldmk_pfld.append(data_ldmk)
|
||||
|
||||
|
||||
# if j % 100 == 0:
|
||||
# print(f"the {j:05d}-th landmark")
|
||||
|
||||
# save
|
||||
vldmk_dlib = np.array(vldmk_dlib).reshape(1, -1, 68, 2) # (N, 68, 2)
|
||||
vldmk_pfld = np.array(vldmk_pfld).reshape(1, -1, 68, 2)
|
||||
print(f"vldmk_dlib shape = {vldmk_dlib.shape}, vldmk_pfld shape= {vldmk_pfld.shape}") # (nframe, 68, 2)
|
||||
|
||||
|
||||
if nContinue_pfld <= 2 and nContinue_dlib <= 2 and vldmk_dlib.shape[0] == (iend-ibeg):
|
||||
# np.save(ipath_save_feat, vldmk_dlib)
|
||||
|
||||
# show annotation
|
||||
save_animation_with_gt(vldmk_dlib, vldmk_pfld,
|
||||
path_save=Path(ipath_data),
|
||||
suffix=f'DLIB_PLDF',
|
||||
w=256, h=256, dpi=100)
|
||||
|
||||
# print(f"feat shape = {vldmk_dlib.shape}, save to -> {ipath_save_feat}") # (nframe, 68, 2)
|
||||
|
||||
else:
|
||||
print(f"ERROR: some landmark missing or length not same, length = {vldmk_dlib.shape}/{iend-ibeg}")
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user