-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
79 lines (70 loc) · 2.64 KB
/
main.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
71
72
73
74
75
76
77
78
79
import mydetective
import argparse
parser = argparse.ArgumentParser(description='Input video files.')
parser.add_argument('video', metavar='V', type=str,
help='a video to analyze')
parser.add_argument('-K', type=int,
help='the number of clusters')
parser.add_argument('--interval', default=1, type=int,
help='time interval (sec) (default: 1)')
parser.add_argument('--metadata', type=str,
help='path of metadata file if exists')
parser.add_argument('--debugging', dest='debugging', action='store_true')
args = parser.parse_args()
module = "main"
def print_divider():
print ("=================================================")
def print_msg(msg):
print("[{}]: {}".format(module, msg))
def switch_module(module_name):
global module
module = module_name
print_divider()
# 1. Collector
switch_module("Collector")
print_msg("Start collecting faces")
if args.metadata:
metadata_file_path = args.metadata
else:
metadata_file_path = mydetective.collect(args.video, interval_sec = args.interval)
print_msg("{} created".format(metadata_file_path))
print_divider()
# 2. Identifier
switch_module("Identifier")
print_msg("Start clustering faces")
if args.K:
K = mydetective.cluster(metadata_file_path, K=args.K, debugging=args.debugging)
else:
K = mydetective.cluster(metadata_file_path, debugging=args.debugging)
print_msg("{} characters detected".format(K))
print_divider()
# 3. Character Analyzer
switch_module("Character Analyzer")
print_msg("Start analyzing characters")
overview_path, clip_path = mydetective.character_analyzer(metadata_file_path)
print_msg("{} created".format(overview_path))
print_msg("{} created".format(clip_path))
overview = mydetective.parse_overview_file(overview_path)
clip = mydetective.parse_clip_file_to_dict(clip_path)
ranking = 1
for char_id, features in overview:
print_msg("Ranking #{}: Character {}".format(ranking, char_id))
for feature in features:
print_msg("- {}: {}".format(feature, features[feature]))
print_msg("- clips: {}".format(clip[char_id]))
ranking += 1
print_divider()
# 4. Relationship Analyzer
switch_module("Relationship Analyzer")
print_msg("Start analyzing relationship between characters")
relationship = mydetective.sorted_relationship(metadata_file_path)
for key, value in relationship:
a, b = key
print_msg ("- ({},{}): {}".format(a, b, value))
print_divider()
# 4. Emotional Changes Analyzer
switch_module("Emotional Changes Analyzer")
print_msg("Start analyzing emotional changes of a character")
emotions = mydetective.characters_emotion(metadata_file_path, 1)
print (emotions)
print_divider()