-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfacerecog.py
74 lines (50 loc) · 1.52 KB
/
facerecog.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
import numpy as np
import cv2
import config
import face
import time
import os
import lock
video_capture = cv2.VideoCapture(0)
if __name__ == '__main__':
camera = config.get_camera()
i=1;
flag=True;
count = 0
while i:
# Capture frame-by-frame
ret, frame = video_capture.read()
#Minimizing the two upper active windows at runtime.
if count == 0 or count == 1:
os.system('xdotool windowminimize $(xdotool getactivewindow)')
count = count+1
gray = cv2.cvtColor(frame, cv2. COLOR_BGR2GRAY)
cv2.imshow('Video', frame)
if cv2.waitKey(1) & flag==True:
result =face.detect_single(gray)
if result is None:
print 'No face!'
lock.lock()
if result is not None:
x, y, w, h = result
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
crop = face.resize(face.crop(gray, x, y, w, h))
facecrop = gray[y:y + h, x:x + w]
print 'Image captured successfully!'
if result is None:
print 'Could not detect single face!'
else:
print 'Analysing image....'
model = cv2.createEigenFaceRecognizer()
model.load(config.TRAINING_FILE)
label, confidence = model.predict(crop)
print 'Predicted {0} face with confidence {1} (lower is more confident).'.format(
'POSITIVE' if label == config.POSITIVE_LABEL else 'NEGATIVE',
confidence)
if label == config.POSITIVE_LABEL and confidence < config.POSITIVE_THRESHOLD:
print 'Hello Owner'
else:
print 'RISK'
lock.lock()
time.sleep(5)
os.system('python facerecog.py')