From be4752b619f020b074b325e7b9816ffc6ce36f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batuhan=20Berk=20Ba=C5=9Fo=C4=9Flu?= Date: Mon, 1 Feb 2021 19:51:23 -0500 Subject: [PATCH] Added the thief detection function. --- DBHelper.py | 9 ++++- Facial_Recognition_Inference.py | 12 +++++- UI/.idea/compiler.xml | 6 +++ UI/.idea/gradle.xml | 1 + UI/.idea/misc.xml | 2 +- Upload_Face.py | 5 +++ Upload_Thief.py | 37 ++++++++++++++++++ __pycache__/DBHelper.cpython-36.pyc | Bin 6177 -> 7276 bytes ...acial_Recognition_Inference.cpython-36.pyc | Bin 2616 -> 2616 bytes 9 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 UI/.idea/compiler.xml create mode 100644 Upload_Thief.py diff --git a/DBHelper.py b/DBHelper.py index a4a35ce7d..c6ac8e921 100644 --- a/DBHelper.py +++ b/DBHelper.py @@ -214,5 +214,12 @@ def remove_removal_data(): db.child("signal").child("3").remove() +# Uploads the data of specified thief into firebase. +def upload_thief_data(thief_id, date, time): + data = {"Date": date, "Time": time} + db.child("Thieves").child(thief_id).set(data) + + if __name__ == "__main__": - upload_data("User_3", "RandomFirst", "RandomLast", "Random@gmail.com", "0000000000") + upload_register_data("RandomFirst", "RandomLast", "Random@gmail.com", "0000000000") + upload_removal_data("RandomFirst", "RandomLast", "Random@gmail.com", "0000000000") diff --git a/Facial_Recognition_Inference.py b/Facial_Recognition_Inference.py index c4f2a7e8d..8721c48a4 100644 --- a/Facial_Recognition_Inference.py +++ b/Facial_Recognition_Inference.py @@ -3,6 +3,9 @@ import dlib import cv2 import numpy as np import DBHelper +import time +import Upload_Thief + def inference(): try: @@ -30,6 +33,7 @@ def inference(): x1 = x2 = y1 = y2 = 0 cond = False + t = 0 while DBHelper.get_power() == "on": t = time.time() @@ -97,10 +101,16 @@ def inference(): elif not cond: DBHelper.set_motor("off") DBHelper.set_alarm("on") + t += 1 + time.sleep(1) + if t == 120: + Upload_Thief.upload_thief_face() + DBHelper.set_power("off") DBHelper.set_alarm("off") DBHelper.set_motor("off") cv2.destroyAllWindows() + if __name__ == "__main__": - inference() \ No newline at end of file + inference() diff --git a/UI/.idea/compiler.xml b/UI/.idea/compiler.xml new file mode 100644 index 000000000..61a9130cd --- /dev/null +++ b/UI/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/UI/.idea/gradle.xml b/UI/.idea/gradle.xml index 5cd135a06..9bba60dad 100644 --- a/UI/.idea/gradle.xml +++ b/UI/.idea/gradle.xml @@ -14,6 +14,7 @@ diff --git a/UI/.idea/misc.xml b/UI/.idea/misc.xml index 37a750962..d5d35ec44 100644 --- a/UI/.idea/misc.xml +++ b/UI/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/Upload_Face.py b/Upload_Face.py index 2ee821b02..6f61f8023 100644 --- a/Upload_Face.py +++ b/Upload_Face.py @@ -24,9 +24,14 @@ def upload_your_face(firstname, lastname, email, phone): print("Success.") except: DBHelper.upload_data("User_1", firstname, lastname, email, phone) + print("Face registration start...") Facial_Recognition_Registration.register_your_face("User_1") + print("Data saved! Starting enrollment...") + Facial_Recognition_Enrollment.enroll_face_dataset() + print("Face registration completed!") for i in range(50): DBHelper.upload_user_photo("User_1/" + str(i) + ".jpg") + print("Success.") if __name__ == "__main__": diff --git a/Upload_Thief.py b/Upload_Thief.py new file mode 100644 index 000000000..c7299de03 --- /dev/null +++ b/Upload_Thief.py @@ -0,0 +1,37 @@ +import DBHelper +import Facial_Recognition_Registration +import Facial_Recognition_Enrollment +from datetime import datetime + + +def upload_thief_face(): + # Determines thief ID before adding the data to the database. + # Thief ID is determined from number of user dataset in database + # Later on it starts face recognition system and uploads it into the database based on the given thief ID. + thieves = DBHelper.db.child("Thieves").get() + try: + count = 1 + for thief in thieves.each(): + count += 1 + Facial_Recognition_Registration.register_your_face("Thief_" + str(count)) + Facial_Recognition_Enrollment.enroll_face_dataset() + for i in range(50): + DBHelper.upload_thief_photo("Thief_" + str(count) + "/" + str(i) + ".jpg") + date = datetime.now().strftime("%d/%m/%Y") + time = datetime.now().strftime("%H:%M:%S") + DBHelper.upload_thief_data("Thief_" + str(count), date, time) + print("An intruder is recorded.") + except: + DBHelper.upload_thief_data("Thief_1", date, time) + Facial_Recognition_Registration.register_your_face("Thief_1") + Facial_Recognition_Enrollment.enroll_face_dataset() + for i in range(50): + DBHelper.upload_thief_photo("Thief_1/" + str(i) + ".jpg") + date = datetime.now().strftime("%d/%m/%Y") + time = datetime.now().strftime("%H:%M:%S") + DBHelper.upload_thief_data("Thief_" + str(count), date, time) + print("An intruder is recorded.") + + +if __name__ == "__main__": + upload_thief_face() diff --git a/__pycache__/DBHelper.cpython-36.pyc b/__pycache__/DBHelper.cpython-36.pyc index 1da299891841964ffe685f7ff81b48ed356b9034..521118df9ddfc50bdd6d05dd0ae6bd27fd9ee4df 100644 GIT binary patch delta 482 zcmZ2z@Ww*fn3tDpgF0VAjuZpKV+JI^1!Ow_adE*$WmU$26qgj&7KSL56t@(2Ag!9> zk>UxY)l$4tyn(cOicg9!kk&}?OYsNNnyFeT0ohCw7>jaJxl#gCf>MH0LQ+DTSs58p z7=sx!!!~Cy@`+9s5p-iTo*XS`IoVE#T`o7jEHNiOEwiY&Brh>Hbvwv*79hdED92dj zFj-L0owLXu$gSe^Nt~P@s4!VeNJK>>J+&mhC>5eNClR7`FN#)2kXEK5`^jsBEEENi z)u-krX6775QS1a$>@RGJs<dqp%Ag~85FMNxefq?!pxFfbOmPA(SnWz?R0Q0%63kpobu j$Pq+1fe2?1;Q}IDCr=kQU`(2PLOhJ0m4giqS-2Phjw5@F delta 106 zcmaE3vCu%-n3tE!NR=<4OpJlyF#{6d0Murr|U__#mW`Y$tc=#1^;j8M7}+-)a56KpGI1nvFaiL;GzaYf delta 38 ucmdlXvO|Q^n3tDp-D=*1u8o{3tc*6B^;j8M7&$f@a56KpGIJzzFaiL(y$8tv