-
Notifications
You must be signed in to change notification settings - Fork 1
/
computeIDTF.py
64 lines (51 loc) · 1.79 KB
/
computeIDTF.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
# extract IDT features
import numpy as np
import subprocess, os
import sys
"""
Wrapper library for the IDTF executable.
Implements methods to extract IDTFs.
Seperate methods for extracting IDTF and computing Fisher Vectors.
Example usage:
python computeIDTF.py VID_DIR video_list.txt output_directory
"""
# Path to the video repository
UCF101_DIR = "/home/zhenyang/Workspace/data/UCF101"
# Improved Dense Trajectories binary
dtBin = './DenseTrackStab'
# ...
COMPUTE_FV = 'python ./computeFVstream.py'
def extract(video_file, output_file):
"""
Extracts the IDTFs and stores them in outputBase file.
"""
if not os.path.exists(video_file):
print '%s does not exist!' % video_file
return False
if os.path.exists(output_file):
print '%s IDT Feature exists, skip!' % video_file
return False
command = '%s -f %s -o %s' % (dtBin, video_file, output_file, )
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True)
while proc.poll() is None:
line = proc.stdout.readline()
print(line)
return True
if __name__ == '__main__':
# Useage: python computeIDTF.py VID_DIR video_list.txt output_directory
VID_DIR = sys.argv[1]
video_list = sys.argv[2]
IDT_DIR = sys.argv[3]
try:
f = open(video_list, 'r')
videos = f.readlines()
f.close()
videos = [video.rstrip() for video in videos]
for i in range(0, len(videos)):
output_file = os.path.join(IDT_DIR,os.path.splitext(videos[i])[0]+".bin")
video_file = os.path.join(VID_DIR,videos[i])
print "generating IDTF for %s" % (videos[i],)
extract(video_file, output_file)
print "completed."
except IOError:
sys.exit(0)