diff --git a/Check_Up.py b/Check_Up.py new file mode 100644 index 000000000..2a2fc36c2 --- /dev/null +++ b/Check_Up.py @@ -0,0 +1,36 @@ +import os +import DBHelper + + +def update(): + # Downloads all the user and thief photos from database to the project folder first or updates them. + users = DBHelper.db.child("Users").get() + thieves = DBHelper.db.child("Thieves").get() + print("Checking and updating User photos...") + try: + count = 0 + for user in users.each(): + count += 1 + if not os.path.isdir("Facial_images/face_rec/train/User_" + str(count)): + os.makedirs("Facial_images/face_rec/train/User_" + str(count)) + for i in range(50): + DBHelper.download_user_photo("User_" + str(count) + "/" + str(i) + ".jpg") + print("Success.") + except: + print("No Users are registered.") + count = 0 + print("Checking and updating Thief photos...") + try: + for thief in thieves.each(): + count += 1 + if not os.path.isdir("Photos_of_Thieves/Thief_" + str(count)): + os.makedirs("Photos_of_Thieves/Thief_" + str(count)) + for i in range(50): + DBHelper.download_thief_photo("Thief_" + str(count) + "/" + str(i) + ".jpg") + print("Success.") + except: + print("No Thieves are registered.") + + +if __name__ == "__main__": + update() diff --git a/DBHelper.py b/DBHelper.py index 13a86c75e..a4a35ce7d 100644 --- a/DBHelper.py +++ b/DBHelper.py @@ -169,5 +169,50 @@ def remove_register_data(): db.child("signal").child("2").remove() +# Downloads user photo to the specified folder. +def download_user_photo_other(user_id, other_id): + storage.child("Photos_of_Users/" + user_id).download("Facial_images/face_rec/train/" + other_id) + + +# Downloads thief photo to the specified folder. +def download_thief_photo_other(thief_id, other_id): + storage.child("Photos_of_Thieves/" + thief_id).download("Photos_of_Thieves/" + other_id) + + +# Returns the first name or else an empty string. +def get_removal_firstname(): + firstname = db.child("signal").child("3").child("First Name").get().val() + return firstname + + +# Returns the last name or else an empty string. +def get_removal_lastname(): + lastname = db.child("signal").child("3").child("Last Name").get().val() + return lastname + + +# Returns the e-mail or else an empty string. +def get_removal_email(): + email = db.child("signal").child("3").child("E-Mail").get().val() + return email + + +# Returns the phone or else an empty string. +def get_removal_phone(): + phone = db.child("signal").child("3").child("Phone").get().val() + return phone + + +# Uploads the data of user input into firebase. +def upload_removal_data(firstname, lastname, email, phone): + data = {"First Name": firstname, "Last Name": lastname, "E-Mail": email, "Phone": phone} + db.child("signal").child("3").set(data) + + +# Removes the inputs. +def remove_removal_data(): + db.child("signal").child("3").remove() + + if __name__ == "__main__": - upload_register_data("RandomFirst", "RandomLast", "Random@gmail.com", "0000000000") + upload_data("User_3", "RandomFirst", "RandomLast", "Random@gmail.com", "0000000000") diff --git a/Main.py b/Main.py index c798e47f7..e6e27256b 100644 --- a/Main.py +++ b/Main.py @@ -1,11 +1,14 @@ import DBHelper import Start_Engine import Upload_Face +import Remove_Face +import Check_Up if __name__ == "__main__": 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(), @@ -14,4 +17,14 @@ 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 b9da6fd43..f867b94b5 100644 --- a/Remove_Face.py +++ b/Remove_Face.py @@ -1,14 +1,65 @@ import DBHelper +import os +import shutil -def remove_your_face(): + +def remove_your_face(firstname, lastname, email, phone): users = DBHelper.db.child("Users").get() try: count = 0 + count2 = 0 for user in users.each(): count += 1 - DBHelper.upload_data("User_" + str(count), firstname, lastname, email, phone) - Facial_Recognition_Registration.register_your_face("User_" + str(count)) - for i in range(20): - DBHelper.upload_user_photo("User_" + str(count) + "/" + str(i) + ".jpg") + print("Removing the specified User...") + for user in users.each(): + 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: + DBHelper.remove_data("User_" + str(count2)) + for i in range(50): + DBHelper.delete_user_photo("User_" + str(count2) + "/" + str(i) + ".jpg") + print("Successfully removed the User.") + break + print("Reorganizing the Users... (This may take long time.)") + if count2 != count and count - count2 - 1 != 0: + for x in range(count - count2 - 1): + DBHelper.upload_data("User_" + str(count2), DBHelper.get_firstname("User_" + str(count2 + 1)), + DBHelper.get_lastname("User_" + str(count2 + 1)), + DBHelper.get_email("User_" + str(count2 + 1)), + DBHelper.get_phone("User_" + str(count2 + 1))) + if not os.path.isdir("Facial_images/face_rec/train/User_" + str(count2)): + os.makedirs("Facial_images/face_rec/train/User_" + str(count2)) + for i in range(50): + DBHelper.download_user_photo_other("User_" + str(count2 + 1) + "/" + str(i) + ".jpg", + "User_" + str(count2) + "/" + str(i) + ".jpg") + DBHelper.upload_user_photo("User_" + str(count2) + "/" + str(i) + ".jpg") + DBHelper.delete_user_photo("User_" + str(count2 + 1) + "/" + str(i) + ".jpg") + count2 += 1 + DBHelper.remove_data("User_" + str(count)) + shutil.rmtree("Facial_images/face_rec/train/User_" + str(count)) + elif count2 != count and count - count2 - 1 == 0: + DBHelper.upload_data("User_" + str(count2), DBHelper.get_firstname("User_" + str(count2 + 1)), + DBHelper.get_lastname("User_" + str(count2 + 1)), + DBHelper.get_email("User_" + str(count2 + 1)), + DBHelper.get_phone("User_" + str(count2 + 1))) + if not os.path.isdir("Facial_images/face_rec/train/User_" + str(count2)): + os.makedirs("Facial_images/face_rec/train/User_" + str(count2)) + for i in range(50): + DBHelper.download_user_photo_other("User_" + str(count2 + 1) + "/" + str(i) + ".jpg", + "User_" + str(count2) + "/" + str(i) + ".jpg") + DBHelper.upload_user_photo("User_" + str(count2) + "/" + str(i) + ".jpg") + 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)) + print("Success.") except: - print("No Users are registered.") \ No newline at end of file + print("No Users exist for User Removal.") + + +if __name__ == "__main__": + f = input('Enter your First Name:') + l = input('Enter your Last Name:') + e = input('Enter your E-Mail:') + p = input('Enter your Phone:') + remove_your_face(f, l, e, p) diff --git a/Upload_Face.py b/Upload_Face.py index c670385ba..2ee821b02 100644 --- a/Upload_Face.py +++ b/Upload_Face.py @@ -8,6 +8,7 @@ def upload_your_face(firstname, lastname, email, phone): # User 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 user ID. users = DBHelper.db.child("Users").get() + print("Registering the User information...") try: count = 1 for user in users.each(): @@ -18,12 +19,13 @@ def upload_your_face(firstname, lastname, email, phone): print("Data saved! Starting enrollment...") Facial_Recognition_Enrollment.enroll_face_dataset() print("Face registration completed!") - for i in range(20): + for i in range(50): DBHelper.upload_user_photo("User_" + str(count) + "/" + str(i) + ".jpg") + print("Success.") except: DBHelper.upload_data("User_1", firstname, lastname, email, phone) Facial_Recognition_Registration.register_your_face("User_1") - for i in range(20): + for i in range(50): DBHelper.upload_user_photo("User_1/" + str(i) + ".jpg") diff --git a/__pycache__/DBHelper.cpython-36.pyc b/__pycache__/DBHelper.cpython-36.pyc index 8e7fd07be..1da299891 100644 Binary files a/__pycache__/DBHelper.cpython-36.pyc and b/__pycache__/DBHelper.cpython-36.pyc differ diff --git a/start_engine.py b/start_engine.py index f2fcb4606..e34164a39 100644 --- a/start_engine.py +++ b/start_engine.py @@ -1,38 +1,18 @@ -import os import DBHelper import Facial_Recognition_Inference def start(): - # Downloads all the user and thief photos from database to the project folder first or updates them. - # Then it starts Facial Recognition Software. + # It checks if a user is registered then starts the Facial Recognition Software. users = DBHelper.db.child("Users").get() - thieves = DBHelper.db.child("Thieves").get() - print("Checking and updating User photos...") - try: - count = 0 - for user in users.each(): - count += 1 - if not os.path.isdir("Facial_images/face_rec/train/User_" + str(count)): - os.makedirs("Facial_images/face_rec/train/User_" + str(count)) - for i in range(20): - DBHelper.download_user_photo("User_" + str(count) + "/" + str(i) + ".jpg") - print("Success.") - except: - print("No Users are registered.") count = 0 - print("Checking and updating Thief photos...") - try: - for thief in thieves.each(): - count += 1 - if not os.path.isdir("Photos_of_Thieves/Thief_" + str(count)): - os.makedirs("Photos_of_Thieves/Thief_" + str(count)) - for i in range(20): - DBHelper.download_thief_photo("Thief_" + str(count) + "/" + str(i) + ".jpg") - print("Success.") - except: - print("No Thieves are registered.") - Facial_Recognition_Inference.inference() + for user in users.each(): + count += 1 + if count != 0: + print("Starting the Face Recognition Software...") + Facial_Recognition_Inference.inference() + else: + print("No Users exist for Facial Recognition Software.") if __name__ == "__main__":