-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetfaces.py
More file actions
executable file
·38 lines (29 loc) · 1.4 KB
/
Copy pathgetfaces.py
File metadata and controls
executable file
·38 lines (29 loc) · 1.4 KB
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
#!/usr/bin/env python
from utils import ximages, xresize, xvideo, write_to
from facedetect.facedetect import xfaces
from bing import xbing, zbing
from argparse import ArgumentParser
from config import DEFAULT_ROOT, DEFAULT_FMT, IMG_FORMATS
DISPATCH = {
'folder': ximages,
'bing': xbing,
'webcam': xvideo,
'movie': xvideo
}
def main():
parser = ArgumentParser(description="Capture faces")
parser.add_argument('-o', '--output', default=DEFAULT_ROOT, type=str, help="Path to destination folder (must be writable)")
parser.add_argument('-m', '--method', choices=DISPATCH.keys(), default='folder', help="Type of source to get the faces from")
parser.add_argument('-n', '--nfaces', type=int, default=None, help="Number of faces to collect")
parser.add_argument('-f', '--format', type=str, default=DEFAULT_FMT, choices=IMG_FORMATS, help="Output image file format")
parser.add_argument('source', type=str, help="Single argument, e.g. folder name, search query, webcam URL, video path.")
args = parser.parse_args()
method = args.method
images = DISPATCH[method](args.source)
if args.nfaces is None and method == 'bing':
images = zbing # Safety measure - this one doesn't yield indefinitely
faces = xfaces(images)
resized = xresize(faces, size=(64, 64))
write_to(resized, args.output, format=args.format, limit=args.nfaces)
if __name__ == "__main__":
main()