diff --git a/DBHelper.py b/DBHelper.py index c6ac8e921..f7a47dac8 100644 --- a/DBHelper.py +++ b/DBHelper.py @@ -78,7 +78,7 @@ def upload_user_photo(user_id): # Uploads the photos of thief, input should be something like "example.jpg" def upload_thief_photo(thief_id): - storage.child("Photos_of_Thieves/" + thief_id).put("Facial_images/face_rec/train/" + thief_id) + storage.child("Photos_of_Thieves/" + thief_id).put("Photos_of_Thieves/" + thief_id) # Downloads the specified user's photos, input should be something like "example.jpg" @@ -221,5 +221,4 @@ def upload_thief_data(thief_id, date, time): if __name__ == "__main__": - upload_register_data("RandomFirst", "RandomLast", "Random@gmail.com", "0000000000") - upload_removal_data("RandomFirst", "RandomLast", "Random@gmail.com", "0000000000") + upload_data("User_3", "RandomFirst", "RandomLast", "Random@gmail.com", "0000000000") diff --git a/Facial_Recognition_Inference.py b/Facial_Recognition_Inference.py index 4980c8310..f83c2f164 100644 --- a/Facial_Recognition_Inference.py +++ b/Facial_Recognition_Inference.py @@ -33,6 +33,7 @@ def inference(): x1 = x2 = y1 = y2 = 0 cond = False + thief = False thief_time = 0 label = 'unknown' @@ -100,19 +101,19 @@ def inference(): DBHelper.set_motor("on") DBHelper.set_alarm("off") thief_time = 0 - time.sleep(1) elif not cond: DBHelper.set_motor("off") DBHelper.set_alarm("on") thief_time += 1 - time.sleep(1) - if thief_time == 120: - Upload_Thief.upload_thief_face() + if thief_time == 10: + thief = True DBHelper.set_power("off") DBHelper.set_alarm("off") DBHelper.set_motor("off") cv2.destroyAllWindows() + if thief: + Upload_Thief.upload_thief_face() if __name__ == "__main__": diff --git a/Facial_Recognition_Thief_Registration.py b/Facial_Recognition_Thief_Registration.py new file mode 100644 index 000000000..89c916f07 --- /dev/null +++ b/Facial_Recognition_Thief_Registration.py @@ -0,0 +1,39 @@ +import sys +import os +import math +import cv2 + + +def register_your_face(label): + num_cap = 50 + + path = sys.path[0] + '/Photos_of_Thieves/' + label + + folder = os.path.exists(path) + + if not folder: + os.makedirs(path) + + cap = cv2.VideoCapture(0) + c = 0 + while c < num_cap: + ret, frame = cap.read() + + cv2.imshow("capture", frame) + + cv2.imwrite(path + '/' + str(c) + '.jpg', frame) + + c = c + 1 + cv2.waitKey(500) + + cap.release() + cv2.destroyAllWindows() + + +if __name__ == "__main__": + print("Face registration start...") + print() + label = input('Pleas enter your Name/Label: ') + register_your_face(label) + print("Data is successfully saved.") + print() diff --git a/Facial_images/face_rec/train/User_2/a.jpg b/Facial_images/face_rec/train/User_2/a.jpg deleted file mode 100644 index ba3ef8144..000000000 Binary files a/Facial_images/face_rec/train/User_2/a.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/b.jpg b/Facial_images/face_rec/train/User_2/b.jpg deleted file mode 100644 index c9aa4c3c1..000000000 Binary files a/Facial_images/face_rec/train/User_2/b.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/c.jpg b/Facial_images/face_rec/train/User_2/c.jpg deleted file mode 100644 index 2cf8ab1ae..000000000 Binary files a/Facial_images/face_rec/train/User_2/c.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/d.jpg b/Facial_images/face_rec/train/User_2/d.jpg deleted file mode 100644 index 334e2ce69..000000000 Binary files a/Facial_images/face_rec/train/User_2/d.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/e.jpg b/Facial_images/face_rec/train/User_2/e.jpg deleted file mode 100644 index 84daf5540..000000000 Binary files a/Facial_images/face_rec/train/User_2/e.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/f.jpg b/Facial_images/face_rec/train/User_2/f.jpg deleted file mode 100644 index deafb4b65..000000000 Binary files a/Facial_images/face_rec/train/User_2/f.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/g.jpg b/Facial_images/face_rec/train/User_2/g.jpg deleted file mode 100644 index ce463871a..000000000 Binary files a/Facial_images/face_rec/train/User_2/g.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/h.jpg b/Facial_images/face_rec/train/User_2/h.jpg deleted file mode 100644 index 31b8ec1c4..000000000 Binary files a/Facial_images/face_rec/train/User_2/h.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/i.jpg b/Facial_images/face_rec/train/User_2/i.jpg deleted file mode 100644 index 8c90548bc..000000000 Binary files a/Facial_images/face_rec/train/User_2/i.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/j.jpg b/Facial_images/face_rec/train/User_2/j.jpg deleted file mode 100644 index 7fc14b47c..000000000 Binary files a/Facial_images/face_rec/train/User_2/j.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/k.jpg b/Facial_images/face_rec/train/User_2/k.jpg deleted file mode 100644 index 9c1154324..000000000 Binary files a/Facial_images/face_rec/train/User_2/k.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/l.jpg b/Facial_images/face_rec/train/User_2/l.jpg deleted file mode 100644 index 0c9800004..000000000 Binary files a/Facial_images/face_rec/train/User_2/l.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/m.jpg b/Facial_images/face_rec/train/User_2/m.jpg deleted file mode 100644 index 2e5e8ee13..000000000 Binary files a/Facial_images/face_rec/train/User_2/m.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/n.jpg b/Facial_images/face_rec/train/User_2/n.jpg deleted file mode 100644 index c9390ec52..000000000 Binary files a/Facial_images/face_rec/train/User_2/n.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/o.jpg b/Facial_images/face_rec/train/User_2/o.jpg deleted file mode 100644 index 984e6bda4..000000000 Binary files a/Facial_images/face_rec/train/User_2/o.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/p.jpg b/Facial_images/face_rec/train/User_2/p.jpg deleted file mode 100644 index 1c98f0aef..000000000 Binary files a/Facial_images/face_rec/train/User_2/p.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/q.jpg b/Facial_images/face_rec/train/User_2/q.jpg deleted file mode 100644 index 9c53040cd..000000000 Binary files a/Facial_images/face_rec/train/User_2/q.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/r.jpg b/Facial_images/face_rec/train/User_2/r.jpg deleted file mode 100644 index ba3ff8c4f..000000000 Binary files a/Facial_images/face_rec/train/User_2/r.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/s.jpg b/Facial_images/face_rec/train/User_2/s.jpg deleted file mode 100644 index 21aaa7375..000000000 Binary files a/Facial_images/face_rec/train/User_2/s.jpg and /dev/null differ diff --git a/Facial_images/face_rec/train/User_2/t.jpg b/Facial_images/face_rec/train/User_2/t.jpg deleted file mode 100644 index d7e97ba2e..000000000 Binary files a/Facial_images/face_rec/train/User_2/t.jpg and /dev/null differ diff --git a/Facial_models/descriptors.npy b/Facial_models/descriptors.npy index a680107dd..c7072951c 100644 Binary files a/Facial_models/descriptors.npy and b/Facial_models/descriptors.npy differ diff --git a/Facial_models/index.pkl b/Facial_models/index.pkl index c1c617c73..09dbea0f4 100644 Binary files a/Facial_models/index.pkl and b/Facial_models/index.pkl differ diff --git a/Main.py b/Main.py index e6e27256b..699a88d66 100644 --- a/Main.py +++ b/Main.py @@ -5,10 +5,10 @@ import Remove_Face import Check_Up if __name__ == "__main__": + Check_Up.update() print("Starting the Program.") while True: if DBHelper.get_power() == "on": - Check_Up.update() Start_Engine.start() if None not in (DBHelper.get_register_firstname(), @@ -17,14 +17,12 @@ if __name__ == "__main__": DBHelper.get_register_phone()): Upload_Face.upload_your_face(DBHelper.get_register_firstname(), DBHelper.get_register_lastname(), DBHelper.get_register_email(), DBHelper.get_register_phone()) - Check_Up.update() DBHelper.remove_register_data() if None not in (DBHelper.get_removal_firstname(), DBHelper.get_removal_lastname(), DBHelper.get_removal_email(), DBHelper.get_removal_phone()): - Check_Up.update() Remove_Face.remove_your_face(DBHelper.get_removal_firstname(), DBHelper.get_removal_lastname(), DBHelper.get_removal_email(), DBHelper.get_removal_phone()) DBHelper.remove_removal_data() diff --git a/Remove_Face.py b/Remove_Face.py index f867b94b5..53c89d42e 100644 --- a/Remove_Face.py +++ b/Remove_Face.py @@ -1,6 +1,7 @@ import DBHelper import os import shutil +import Facial_Recognition_Enrollment def remove_your_face(firstname, lastname, email, phone): @@ -15,7 +16,7 @@ def remove_your_face(firstname, lastname, email, phone): count2 += 1 if DBHelper.get_firstname("User_" + str(count2)) == firstname and DBHelper.get_lastname( "User_" + str(count2)) == lastname and DBHelper.get_email( - "User_" + str(count2)) == email and DBHelper.get_phone("User_" + str(count2)) == phone: + "User_" + str(count2)) == email and DBHelper.get_phone("User_" + str(count2)) == phone: DBHelper.remove_data("User_" + str(count2)) for i in range(50): DBHelper.delete_user_photo("User_" + str(count2) + "/" + str(i) + ".jpg") @@ -52,6 +53,7 @@ def remove_your_face(firstname, lastname, email, phone): DBHelper.delete_user_photo("User_" + str(count2 + 1) + "/" + str(i) + ".jpg") DBHelper.remove_data("User_" + str(count)) shutil.rmtree("Facial_images/face_rec/train/User_" + str(count)) + Facial_Recognition_Enrollment.enroll_face_dataset() print("Success.") except: print("No Users exist for User Removal.") diff --git a/Upload_Thief.py b/Upload_Thief.py index c7299de03..30780857d 100644 --- a/Upload_Thief.py +++ b/Upload_Thief.py @@ -1,6 +1,5 @@ import DBHelper -import Facial_Recognition_Registration -import Facial_Recognition_Enrollment +import Facial_Recognition_Thief_Registration from datetime import datetime @@ -13,8 +12,7 @@ def upload_thief_face(): count = 1 for thief in thieves.each(): count += 1 - Facial_Recognition_Registration.register_your_face("Thief_" + str(count)) - Facial_Recognition_Enrollment.enroll_face_dataset() + Facial_Recognition_Thief_Registration.register_your_face("Thief_" + str(count)) for i in range(50): DBHelper.upload_thief_photo("Thief_" + str(count) + "/" + str(i) + ".jpg") date = datetime.now().strftime("%d/%m/%Y") @@ -22,14 +20,12 @@ def upload_thief_face(): 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() + Facial_Recognition_Thief_Registration.register_your_face("Thief_1") 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) + DBHelper.upload_thief_data("Thief_1", date, time) print("An intruder is recorded.") diff --git a/__pycache__/Check_Up.cpython-36.pyc b/__pycache__/Check_Up.cpython-36.pyc index debb5e55a..1e0d4a5f6 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 9235f72a8..a47cf3c28 100644 Binary files a/__pycache__/DBHelper.cpython-36.pyc and b/__pycache__/DBHelper.cpython-36.pyc differ diff --git a/__pycache__/Facial_Recognition_Inference.cpython-36.pyc b/__pycache__/Facial_Recognition_Inference.cpython-36.pyc index f008329ff..2ef854103 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_Thief_Registration.cpython-36.pyc b/__pycache__/Facial_Recognition_Thief_Registration.cpython-36.pyc new file mode 100644 index 000000000..12cef5918 Binary files /dev/null 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 990a8a199..e941a1d4b 100644 Binary files a/__pycache__/Remove_Face.cpython-36.pyc and b/__pycache__/Remove_Face.cpython-36.pyc differ diff --git a/__pycache__/Upload_Thief.cpython-36.pyc b/__pycache__/Upload_Thief.cpython-36.pyc index 768b62595..94b0a4ef9 100644 Binary files a/__pycache__/Upload_Thief.cpython-36.pyc and b/__pycache__/Upload_Thief.cpython-36.pyc differ