-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmeerkat.py
More file actions
68 lines (59 loc) · 2.25 KB
/
meerkat.py
File metadata and controls
68 lines (59 loc) · 2.25 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
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
import cv2
#from newface_test import findface
import pickle
import time
import face_recognition
import imutils
import socket
cascPath = "C:/Users/ganes/AppData/Local/Programs/Python/Python36/Lib/site-packages/cv2/data/haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascPath)
x,y = 0,0
video_capture = cv2.VideoCapture(0)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('192.168.137.28',6000))
print("[INFO] loading encodings...")
data = pickle.loads(open("new_encodings.pickle", "rb").read())
while True:
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.CASCADE_SCALE_IMAGE
)
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.imshow('Video', frame)
key = cv2.waitKey(1) & 0xFF
if key == ord('q'):
print("Quitting...")
break
elif key == ord(' '):
print("Detecting contours...")
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
boxes = face_recognition.face_locations(rgb, model = "hog")
encodings = face_recognition.face_encodings(rgb, boxes)
names = []
for encoding in encodings:
matches = face_recognition.compare_faces(data["encodings"], encoding)
name = "Unknown"
if True in matches:
matchedIdxs = [i for (i, b) in enumerate(matches) if b]
counts = {}
for i in matchedIdxs:
name = data["names"][i]
counts[name] = counts.get(name, 0) + 1
name = max(counts, key= counts.get)
names.append(name)
if len(names) == 0:
print("No face detected! Please try again.")
else:
#cv2.putText(frame, str(names), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 255, 0), 2)
for stud_name in names:
print("Welcome to class, " + stud_name[0].upper()+stud_name[1:] + ".")
sock.send((stud_name[0].upper()+stud_name[1:] + "\n").encode())
video_capture.release()
cv2.destroyAllWindows()