-
Notifications
You must be signed in to change notification settings - Fork 4
/
enroll_profile_image.py
58 lines (42 loc) · 1.64 KB
/
enroll_profile_image.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
#!/bin/sh
import os, sys
from fnc.extractFeature import extractFeature
from multiprocessing import cpu_count, Pool
from scipy.io import savemat
from time import time
from tqdm import tqdm
from glob import glob
import argparse
arguments = {}
arguments["data_file"] = sys.argv[1]
arguments["temp_dir"] = "./templates/Profile_Iris/"
arguments["n_cores"] = cpu_count()
def pool_func(file):
template, mask, _ = extractFeature(file, use_multiprocess=False)
basename = os.path.basename(file)
out_file = os.path.join(arguments["temp_dir"], "%s.mat" % (basename))
savemat(out_file, mdict={'template': template, 'mask': mask})
return basename
def main():
# -----------------------------------------------------------------------------
# Execution
# -----------------------------------------------------------------------------
start = time()
# Check the existence of temp_dir
if not os.path.exists(arguments["temp_dir"]):
print("makedirs", arguments["temp_dir"])
os.makedirs(arguments["temp_dir"])
# Get list of files for enrolling template, just "xxx_1_x.jpg" files are selected
# files = glob(os.path.join(arguments["data_file"],
# "**/*/*_1_*.jpg"), recursive=True)
file = arguments["data_file"]
# print("Number of files for enrolling:", n_files)
# Parallel pools to enroll templates
# print("Start enrolling...")
# pools = Pool(processes=arguments["n_cores"])
# for _ in tqdm(pools.imap_unordered(pool_func, files), total=n_files):
# pass
pool_return = pool_func(file)
return pool_return
if __name__ == '__main__':
print(main())