diff --git a/Facial_Recognition_Inference.py b/Facial_Recognition_Inference.py index c0f8a5da9..faf75f8c3 100644 --- a/Facial_Recognition_Inference.py +++ b/Facial_Recognition_Inference.py @@ -17,9 +17,7 @@ def inference(): FACE_RECOGNITION_MODEL_PATH = pwd + '/Facial_models/dlib_face_recognition_resnet_model_v1.dat' SKIP_FRAMES = 1 - MAXIMUM_TIME = 10 THRESHOLD = 0.4 - DEMO_SHOW = False faceDetector = dlib.get_frontal_face_detector() shapePredictor = dlib.shape_predictor(PREDICTOR_PATH) @@ -28,7 +26,7 @@ def inference(): 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 @@ -38,8 +36,6 @@ def inference(): label = 'unknown' start = time.time() - label_counter = {} - while DBHelper.get_power() == "on": success, im = cam.read() @@ -78,60 +74,38 @@ def inference(): if minDistance <= THRESHOLD: label = DBHelper.get_firstname(index[argmin]) + "_" + DBHelper.get_lastname(index[argmin]) - #cond = True + cond = True else: label = 'unknown' - #cond = False - - if label in label_counter.keys(): - label_counter[label] += 1 - else: - label_counter[label] = 1 + cond = False # print("time taken = {:.3f} seconds".format(time.time() - t)) - if DEMO_SHOW: - cv2.rectangle(im, (x1, y1), (x2, y2), (0, 255, 0), 2) - font_face = cv2.FONT_HERSHEY_SIMPLEX - font_scale = 0.8 - text_color = (0, 255, 0) - printLabel = '{} {:0.4f}'.format(label, minDistance) - cv2.putText(im, printLabel, (int(x1), int(y1)), font_face, font_scale, text_color, thickness=2) - if DEMO_SHOW: - cv2.imshow('img', im) + cv2.rectangle(im, (x1, y1), (x2, y2), (0, 255, 0), 2) + font_face = cv2.FONT_HERSHEY_SIMPLEX + font_scale = 0.8 + text_color = (0, 255, 0) + 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 if k == 27: break count += 1 - - if(count == MAXIMUM_TIME): - break - - print("The statics of 10 frames: ", label_counter) - - output_label =sorted(label_counter,key=lambda x:label_counter[x])[-1] - - print("Final results: ", output_label) - - if output_label == 'unknown': - cond = False - else: - cond = True - - if cond: - DBHelper.set_motor("on") - DBHelper.set_alarm("off") - start = time.time() - elif not cond: - DBHelper.set_motor("off") - DBHelper.set_alarm("on") - end = time.time() - if end - start >= 30: - thief = True - DBHelper.set_power("off") - + if cond: + DBHelper.set_motor("on") + DBHelper.set_alarm("off") + start = time.time() + elif not cond: + DBHelper.set_motor("off") + DBHelper.set_alarm("on") + end = time.time() + if end - start >= 30: + thief = True + DBHelper.set_power("off") DBHelper.set_alarm("off") DBHelper.set_motor("off") @@ -141,4 +115,4 @@ def inference(): if __name__ == "__main__": - inference() + inference() \ No newline at end of file diff --git a/__pycache__/Check_Up.cpython-36.pyc b/__pycache__/Check_Up.cpython-36.pyc index 3814bc3c3..4ffe1183b 100644 Binary files a/__pycache__/Check_Up.cpython-36.pyc and b/__pycache__/Check_Up.cpython-36.pyc differ diff --git a/__pycache__/DBHelper.cpython-36.pyc b/__pycache__/DBHelper.cpython-36.pyc index 350d70b8f..f5b7c0b97 100644 Binary files a/__pycache__/DBHelper.cpython-36.pyc and b/__pycache__/DBHelper.cpython-36.pyc differ diff --git a/__pycache__/Facial_Recognition_Enrollment.cpython-36.pyc b/__pycache__/Facial_Recognition_Enrollment.cpython-36.pyc index d95b222b1..96c284198 100644 Binary files a/__pycache__/Facial_Recognition_Enrollment.cpython-36.pyc and b/__pycache__/Facial_Recognition_Enrollment.cpython-36.pyc differ diff --git a/__pycache__/Facial_Recognition_Inference.cpython-36.pyc b/__pycache__/Facial_Recognition_Inference.cpython-36.pyc index f85c67a60..a927dcb75 100644 Binary files a/__pycache__/Facial_Recognition_Inference.cpython-36.pyc and b/__pycache__/Facial_Recognition_Inference.cpython-36.pyc differ diff --git a/__pycache__/Facial_Recognition_Registration.cpython-36.pyc b/__pycache__/Facial_Recognition_Registration.cpython-36.pyc index b281b0028..ab39d7b6e 100644 Binary files a/__pycache__/Facial_Recognition_Registration.cpython-36.pyc and b/__pycache__/Facial_Recognition_Registration.cpython-36.pyc differ diff --git a/__pycache__/Facial_Recognition_Thief_Registration.cpython-36.pyc b/__pycache__/Facial_Recognition_Thief_Registration.cpython-36.pyc index e0ca168cd..4eed309b6 100644 Binary files a/__pycache__/Facial_Recognition_Thief_Registration.cpython-36.pyc and b/__pycache__/Facial_Recognition_Thief_Registration.cpython-36.pyc differ diff --git a/__pycache__/Remove_Face.cpython-36.pyc b/__pycache__/Remove_Face.cpython-36.pyc index 9490aabee..ab416f57b 100644 Binary files a/__pycache__/Remove_Face.cpython-36.pyc and b/__pycache__/Remove_Face.cpython-36.pyc differ diff --git a/__pycache__/Upload_Face.cpython-36.pyc b/__pycache__/Upload_Face.cpython-36.pyc index bfbb28c3b..0e23f3fe0 100644 Binary files a/__pycache__/Upload_Face.cpython-36.pyc and b/__pycache__/Upload_Face.cpython-36.pyc differ diff --git a/__pycache__/Upload_Thief.cpython-36.pyc b/__pycache__/Upload_Thief.cpython-36.pyc index aaa0b2345..cd370a8da 100644 Binary files a/__pycache__/Upload_Thief.cpython-36.pyc and b/__pycache__/Upload_Thief.cpython-36.pyc differ