-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdetect.py
executable file
·53 lines (36 loc) · 1008 Bytes
/
detect.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
#!/usr/bin/env python2
import os
import sys
import pickle
from time import time
import cv2
import numpy as np
np.set_printoptions(precision=2)
from encode import detect
def face_detection(file, step=1, video=False, save=False):
cap = cv2.VideoCapture(file)
_, frame = cap.read()
file = 'viz/' + str(int(time())) + '.avi'
fourcc = cv2.cv.CV_FOURCC(*'XVID')
out = cv2.VideoWriter(file, fourcc, 20.0, (frame.shape[1], frame.shape[0]))
faces_dir = 'viz/' + str(int(time())) + '/'
os.makedirs(faces_dir)
idx = 0
while True:
running, frame = cap.read()
if not running:
break
idx += 1
if idx%step != 0:
continue
frame, faces = detect(frame)
if video: out.write(frame)
if save:
for i, face in enumerate(faces):
cv2.imwrite('{}/{}_{}.jpg'.format(faces_dir, str(int(time())), i), face)
print("-- Processed {} frame --".format(idx))
def main():
file = sys.argv[1]
face_detection(file, step=5, video=True, save=True)
if __name__ == '__main__':
main()