-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_OpenFace.py
72 lines (50 loc) · 2.38 KB
/
main_OpenFace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import subprocess
import time
import datetime
"""
Full Pipeline - OpenFace
NOTE: Before running this, you need to have already installed OpenFace and put the binary at the appropriate path.
If you're on Windows, use this link: https://github.com/TadasBaltrusaitis/OpenFace/wiki/Windows-Installation
"""
# Set the parameters
PAT_NOW = "S09"
VIDEO_DIRECTORY = os.path.abspath(f'/home/klab/NAS/OutpatientVideos_PatientOnly/{PAT_NOW}/')
OUTPUT_DIRECTORY = os.path.abspath(f'/home/klab/NAS/Analysis/outputs_OpenFace_PatientOnly/{PAT_NOW}/')
JUST_AU = False
AU_STATIC = False
# Get the list of all videos in the given directory
all_videos = [vid for vid in os.listdir(VIDEO_DIRECTORY) if vid[0:1] != '.']
# For timing estimation
valid_videos = [vid for vid in all_videos if os.path.isfile(os.path.join(VIDEO_DIRECTORY, vid))]
unprocessed_videos = [vid for vid in valid_videos if not(os.path.exists(os.path.join(OUTPUT_DIRECTORY, vid[:-4] + '.csv') ))]
num_vids = len(unprocessed_videos)
start_time = time.time()
# Loop through all videos
for i in all_videos:
save_file = os.path.join(OUTPUT_DIRECTORY, i[:-4] + '.csv')
txt_path = os.path.join(OUTPUT_DIRECTORY, i[:-4] + '_of_details.txt')
video_path = os.path.join(VIDEO_DIRECTORY, i)
if os.path.exists(save_file):
print(f'Skipping Video {i}: Output File Already Exists!')
elif os.path.isfile(video_path):
if JUST_AU:
cmd = f'/home/klab/Desktop/OpenFace/build/bin/FeatureExtraction -f "{video_path}" -out_dir "{OUTPUT_DIRECTORY}" -aus'
else:
cmd = f'/home/klab/Desktop/OpenFace/build/bin/FeatureExtraction -f "{video_path}" -out_dir "{OUTPUT_DIRECTORY}" -aus -2Dfp -3Dfp -pdmparams -pose -gaze'
if AU_STATIC:
cmd = cmd + ' -au_static'
subprocess.run(cmd, shell=True)
# Remove unnecessary txt file if it exists
if os.path.exists(txt_path):
os.remove(txt_path)
# Time estimation
elapsed_time = time.time() - start_time
iterations_left = num_vids - unprocessed_videos.index(i) - 1
time_per_iteration = elapsed_time / (unprocessed_videos.index(i) + 1)
time_left = time_per_iteration * iterations_left
time_left_formatted = str(datetime.timedelta(seconds=int(time_left)))
# print an update on the progress
print("Approximately", time_left_formatted, "left to complete the operation")
else:
print(f'WARNING: Got path {video_path}, which is not a valid video file!')