champ_preprocess / batch_smooth.py
yoyozs11's picture
Upload folder using huggingface_hub
cd47a59 verified
Raw
History Blame Contribute Delete
2.11 kB
import os
import subprocess
def main():
base_dir = r"D:\Users\roy\CV_final_project\champ-master"
driving_videos_dir = os.path.join(base_dir, "driving_videos")
blender_exe = r"D:\Program Files (x86)\blender-3.6.0-windows-x64\blender.exe"
script_path = os.path.join("scripts", "data_processors", "smpl", "smooth_smpls.py")
if not os.path.exists(driving_videos_dir):
print(f"錯誤:找不到資料夾 {driving_videos_dir}")
return
# 取得所有的影片資料夾名稱
video_names = [d for d in os.listdir(driving_videos_dir) if os.path.isdir(os.path.join(driving_videos_dir, d))]
video_names.sort()
print(f"總共找到 {len(video_names)} 支影片需要進行 3D 骨架平滑處理...")
for video_name in video_names:
# 使用相對路徑,因為 cwd 設定為 base_dir
smpls_npz_path = os.path.join("driving_videos", video_name, "smpl_results", "smpls_group.npz")
# 檢查該影片的動作捕捉檔 (npz) 是否存在
full_npz_path = os.path.join(base_dir, smpls_npz_path)
if not os.path.exists(full_npz_path):
print(f"[{video_name}] 找不到動作捕捉檔案 (跳過): {smpls_npz_path}")
continue
print(f"\n========================================")
print(f"正在平滑化影片骨架: {video_name}")
print(f"========================================")
# 構建 Blender 執行指令
cmd = [
blender_exe,
"--background",
"--python", script_path,
"--", # 分隔符,告知 Blender 後面是給 python 腳本的參數
"--smpls_group_path", smpls_npz_path,
"--smoothed_result_path", smpls_npz_path # 直接覆蓋原始檔案
]
result = subprocess.run(cmd, cwd=base_dir)
if result.returncode != 0:
print(f"[{video_name}] 執行 Blender 時發生錯誤!")
else:
print(f"[{video_name}] 平滑化完成!\n")
if __name__ == "__main__":
main()