Integrated Facial Software to Database and Main Program.
This commit is contained in:
parent
9f7adf2762
commit
e1f6e307fa
6 changed files with 117 additions and 110 deletions
|
@ -9,6 +9,7 @@ try:
|
|||
except ImportError:
|
||||
import _pickle as cPickle # Python3.
|
||||
|
||||
|
||||
def enroll_face_dataset():
|
||||
pwd = sys.path[0]
|
||||
PREDICTOR_PATH = pwd + '/Facial_models/shape_predictor_68_face_landmarks.dat'
|
||||
|
@ -18,7 +19,6 @@ def enroll_face_dataset():
|
|||
shapePredictor = dlib.shape_predictor(PREDICTOR_PATH)
|
||||
faceRecognizer = dlib.face_recognition_model_v1(FACE_RECOGNITION_MODEL_PATH)
|
||||
|
||||
|
||||
faceDatasetFolder = pwd + '/Facial_images/face_rec/train/'
|
||||
|
||||
subfolders = []
|
||||
|
@ -27,7 +27,6 @@ def enroll_face_dataset():
|
|||
if os.path.isdir(xpath):
|
||||
subfolders.append(xpath)
|
||||
|
||||
|
||||
nameLabelMap = {}
|
||||
labels = []
|
||||
imagePaths = []
|
||||
|
@ -58,12 +57,10 @@ def enroll_face_dataset():
|
|||
|
||||
faceDescriptor = faceRecognizer.compute_face_descriptor(img, shape)
|
||||
|
||||
|
||||
faceDescriptorList = [x for x in faceDescriptor]
|
||||
faceDescriptorNdarray = np.asarray(faceDescriptorList, dtype=np.float64)
|
||||
faceDescriptorNdarray = faceDescriptorNdarray[np.newaxis, :]
|
||||
|
||||
|
||||
if faceDescriptors is None:
|
||||
faceDescriptors = faceDescriptorNdarray
|
||||
else:
|
||||
|
|
|
@ -2,13 +2,13 @@ import os,sys,time
|
|||
import dlib
|
||||
import cv2
|
||||
import numpy as np
|
||||
import DBHelper
|
||||
|
||||
try:
|
||||
import cPickle # Python 2
|
||||
except ImportError:
|
||||
import _pickle as cPickle # Python 3
|
||||
|
||||
|
||||
pwd = sys.path[0]
|
||||
PREDICTOR_PATH = pwd + '/Facial_models/shape_predictor_68_face_landmarks.dat'
|
||||
FACE_RECOGNITION_MODEL_PATH = pwd + '/Facial_models/dlib_face_recognition_resnet_model_v1.dat'
|
||||
|
@ -23,13 +23,14 @@ faceRecognizer = dlib.face_recognition_model_v1(FACE_RECOGNITION_MODEL_PATH)
|
|||
index = np.load(pwd + '/Facial_models/index.pkl', allow_pickle=True)
|
||||
faceDescriptorsEnrolled = np.load(pwd + '/Facial_models/descriptors.npy')
|
||||
|
||||
|
||||
cam = cv2.VideoCapture(1)
|
||||
cam = cv2.VideoCapture(0)
|
||||
count = 0
|
||||
|
||||
x1 = x2 = y1 = y2 = 0
|
||||
|
||||
while True:
|
||||
cond = False
|
||||
|
||||
while DBHelper.get_power() == "on":
|
||||
t = time.time()
|
||||
success, im = cam.read()
|
||||
|
||||
|
@ -37,7 +38,6 @@ while True:
|
|||
print('cannot capture input from camera')
|
||||
break
|
||||
|
||||
|
||||
if (count % SKIP_FRAMES) == 0:
|
||||
|
||||
img = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
|
||||
|
@ -67,15 +67,15 @@ while True:
|
|||
argmin = np.argmin(distances) # index
|
||||
minDistance = distances[argmin] # minimum distance
|
||||
|
||||
|
||||
if minDistance <= THRESHOLD:
|
||||
label = index[argmin]
|
||||
label = DBHelper.get_firstname(index[argmin]) + "_" + DBHelper.get_lastname(index[argmin])
|
||||
cond = True
|
||||
else:
|
||||
label = 'unknown'
|
||||
cond = False
|
||||
|
||||
# print("time taken = {:.3f} seconds".format(time.time() - t))
|
||||
|
||||
|
||||
cv2.rectangle(im, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
||||
font_face = cv2.FONT_HERSHEY_SIMPLEX
|
||||
font_scale = 0.8
|
||||
|
@ -83,7 +83,6 @@ while True:
|
|||
printLabel = '{} {:0.4f}'.format(label, minDistance)
|
||||
cv2.putText(im, printLabel, (int(x1), int(y1)), font_face, font_scale, text_color, thickness=2)
|
||||
|
||||
|
||||
cv2.imshow('img', im)
|
||||
|
||||
k = cv2.waitKey(1) & 0xff
|
||||
|
@ -91,4 +90,13 @@ while True:
|
|||
break
|
||||
|
||||
count += 1
|
||||
if cond:
|
||||
DBHelper.set_motor("on")
|
||||
DBHelper.set_alarm("off")
|
||||
elif not cond:
|
||||
DBHelper.set_motor("off")
|
||||
DBHelper.set_alarm("on")
|
||||
|
||||
DBHelper.set_alarm("off")
|
||||
DBHelper.set_motor("off")
|
||||
cv2.destroyAllWindows()
|
||||
|
|
|
@ -4,6 +4,7 @@ import math
|
|||
import cv2
|
||||
import Facial_Recognition_Enrollment
|
||||
|
||||
|
||||
def register_your_face(label):
|
||||
num_cap = 50
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import DBHelper
|
||||
import Facial_Recognition_Registration
|
||||
import Facial_Recognition_Enrollment
|
||||
|
||||
|
||||
def upload_your_face(firstname, lastname, email, phone):
|
||||
|
@ -13,6 +14,7 @@ def upload_your_face(firstname, lastname, email, phone):
|
|||
count += 1
|
||||
DBHelper.upload_data("User_" + str(count), firstname, lastname, email, phone)
|
||||
Facial_Recognition_Registration.register_your_face("User_" + str(count))
|
||||
Facial_Recognition_Enrollment.enroll_face_dataset()
|
||||
for i in range(20):
|
||||
DBHelper.upload_user_photo("User_" + str(count) + "/" + str(i) + ".jpg")
|
||||
except:
|
||||
|
|
Binary file not shown.
|
@ -1,6 +1,6 @@
|
|||
import os
|
||||
import DBHelper
|
||||
import Facial_Recognition_Wrapper
|
||||
import Facial_Recognition_Inference
|
||||
|
||||
|
||||
def start():
|
||||
|
@ -32,8 +32,7 @@ def start():
|
|||
print("Success.")
|
||||
except:
|
||||
print("No Thieves are registered.")
|
||||
Facial_Recognition_Wrapper.training_recognizer("LBPH")
|
||||
Facial_Recognition_Wrapper.face_recognition_inference("LBPH")
|
||||
Facial_Recognition_Inference
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in a new issue