This repository has been archived by the owner on Sep 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
228 additions
and
170 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from pkg_resources import resource_filename | ||
|
||
|
||
def pose_predictor_model_location(): | ||
return resource_filename(__name__, "models/shape_predictor_68_face_landmarks.dat") | ||
return resource_filename(__name__, | ||
"shape_predictor_68_face_landmarks.dat") | ||
|
||
|
||
def pose_predictor_five_point_model_location(): | ||
return resource_filename(__name__, "models/shape_predictor_5_face_landmarks.dat") | ||
return resource_filename(__name__, | ||
"shape_predictor_5_face_landmarks.dat") | ||
|
||
|
||
def face_recognition_model_location(): | ||
return resource_filename(__name__, "models/dlib_face_recognition_resnet_model_v1.dat") | ||
return resource_filename(__name__, | ||
"dlib_face_recognition_resnet_model_v1.dat" | ||
) | ||
|
||
|
||
def cnn_face_detector_model_location(): | ||
return resource_filename(__name__, "models/mmod_human_face_detector.dat") | ||
return resource_filename(__name__, | ||
"mmod_human_face_detector.dat") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,116 @@ | ||
import dlib | ||
import os | ||
import sys | ||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
import cv2 | ||
import takeref | ||
from Api import facerecog | ||
# Take the reference picture to compare all along the exam. | ||
takeref.takepicture() | ||
|
||
detector = dlib.get_frontal_face_detector() | ||
cap = cv2.VideoCapture(0) | ||
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 800) | ||
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 600) | ||
# cap.set(cv2.CAP_PROP_FPS, 10) | ||
|
||
color_green = (0, 255, 0) | ||
color_red = (0, 0, 255) | ||
color_white = (255, 255, 255) | ||
line_width = 3 | ||
font = cv2.FONT_HERSHEY_SIMPLEX | ||
bottomLeftText = (10, 50) | ||
fontScale = 1 | ||
mire = [200, 130, 450, 400] | ||
photo = True | ||
while photo: | ||
_, img = cap.read() | ||
pic = img | ||
cv2.rectangle(img, (mire[0], mire[1]), | ||
(mire[2], mire[3]), color_red, line_width * 2) | ||
|
||
cv2.putText(img, 'Alignez votre tete au carre rouge', bottomLeftText, | ||
font, fontScale, color_white, line_width) | ||
|
||
dets = detector(img) | ||
for det in dets: | ||
pos = [det.left(), det.top(), det.right(), det.bottom()] | ||
cv2.rectangle(img, (det.left(), det.top()), | ||
(det.right(), det.bottom()), color_green, line_width) | ||
|
||
print(pos[0], mire[0], pos[1], mire[1], | ||
pos[2], mire[2], pos[3], mire[3]) | ||
if (pos[0] > mire[0] & pos[1] > mire[1] | ||
& pos[2] < mire[2] & pos[3] < mire[3]): | ||
cv2.imwrite("test.png", pic) | ||
photo = False | ||
|
||
cv2.imshow('my webcam', img) | ||
key = cv2.waitKey(100) | ||
video_capture = cv2.VideoCapture(0) | ||
|
||
# Load a sample picture and learn how to recognize it. | ||
|
||
# ################################################################# | ||
# TO DO , FETCH une image du serveur au lieux de celles en local### | ||
# ################################################################# | ||
test_image = facerecog.load_image_file("faces/etudiant.png") | ||
|
||
test_face_encoding = facerecog.face_encodings(test_image)[0] | ||
|
||
# Create arrays of known face encodings and their names | ||
known_face_encodings = [ | ||
test_face_encoding | ||
] | ||
|
||
known_face_names = [ | ||
"etudiant" | ||
] | ||
|
||
# Initialize some variables | ||
face_locations = [] | ||
face_encodings = [] | ||
face_names = [] | ||
|
||
warning_disapear = 0 | ||
warning_unknown = 0 | ||
while True: | ||
# Grab a single frame of video | ||
_, frame = video_capture.read() | ||
frame = cv2.flip(frame, 1) | ||
# Resize frame of video to 1/4 size for faster face recognition processing | ||
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) | ||
|
||
# Convert the image from BGR color (which OpenCV uses) to RGB color | ||
# (which facerecog uses) | ||
rgb_small_frame = small_frame[:, :, ::-1] | ||
|
||
# Find all the faces and face encodings in the current frame of video | ||
face_locations = facerecog.face_locations(rgb_small_frame) | ||
face_encodings = facerecog.face_encodings( | ||
rgb_small_frame, face_locations) | ||
|
||
# if not face_locations: | ||
# warning_disapear += 1 | ||
|
||
face_names = [] | ||
for face_encoding in face_encodings: | ||
# See if the face is a match for the known face(s) | ||
matches = facerecog.compare_faces( | ||
known_face_encodings, face_encoding) | ||
name = "Unknown" | ||
# If a match was found in known_face_encodings, | ||
# just use the first one. | ||
if True in matches: | ||
first_match_index = matches.index(True) | ||
name = known_face_names[first_match_index] | ||
|
||
face_names.append(name) | ||
|
||
print(face_names) | ||
if "etudiant" not in face_names: | ||
warning_disapear += 1 | ||
else: | ||
print("reset disapear") | ||
warning_disapear = 0 | ||
|
||
if "Unknown" in face_names: | ||
warning_unknown += 1 | ||
|
||
if face_names == ["etudiant"]: | ||
print("reset unknown") | ||
warning_unknown = 0 | ||
|
||
if warning_disapear > 50: | ||
print("Oukilé ?") | ||
if warning_unknown > 50: | ||
print("konépa") | ||
# Display the results | ||
for (top, right, bottom, left), name in zip(face_locations, face_names): | ||
# Scale back up face locations since the frame we detected in was | ||
# scaled to 1/4 size | ||
top *= 4 | ||
right *= 4 | ||
bottom *= 4 | ||
left *= 4 | ||
|
||
# Draw a box around the face | ||
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2) | ||
|
||
# Draw a label with a name below the face | ||
cv2.rectangle(frame, (left, bottom - 35), | ||
(right, bottom), (0, 0, 255), cv2.FILLED) | ||
font = cv2.FONT_HERSHEY_DUPLEX | ||
cv2.putText(frame, name, (left + 6, bottom - 6), | ||
font, 1.0, (255, 255, 255), 1) | ||
|
||
# Display the resulting image | ||
cv2.imshow('Video', frame) | ||
cv2.waitKey(100) | ||
# Hit 'q' on the keyboard to quit! | ||
if cv2.waitKey(1) & 0xFF == ord('q') or cv2.waitKey(1) & 0xFF == 27: | ||
break | ||
|
||
# Release handle to the webcam | ||
video_capture.release() | ||
cv2.destroyAllWindows() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.