2021-01-23 01:39:48 +00:00
|
|
|
import DBHelper
|
2021-01-25 02:15:54 +00:00
|
|
|
import shutil
|
2021-02-10 16:07:59 +00:00
|
|
|
from joblib import Parallel, delayed
|
|
|
|
import multiprocessing
|
|
|
|
import os
|
2021-01-23 01:39:48 +00:00
|
|
|
|
2021-02-15 17:27:35 +00:00
|
|
|
import Facial_Recognition_Enrollment
|
|
|
|
|
2021-01-25 02:15:54 +00:00
|
|
|
|
|
|
|
def remove_your_face(firstname, lastname, email, phone):
|
2021-01-23 01:55:35 +00:00
|
|
|
users = DBHelper.db.child("Users").get()
|
|
|
|
try:
|
|
|
|
count = 0
|
2021-01-25 02:15:54 +00:00
|
|
|
count2 = 0
|
2021-01-23 01:55:35 +00:00
|
|
|
for user in users.each():
|
|
|
|
count += 1
|
2021-02-10 16:07:59 +00:00
|
|
|
print("The specified user will be removed...")
|
2021-01-25 02:15:54 +00:00
|
|
|
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(
|
2021-02-04 22:41:59 +00:00
|
|
|
"User_" + str(count2)) == email and DBHelper.get_phone("User_" + str(count2)) == phone:
|
2021-02-10 16:07:59 +00:00
|
|
|
Parallel(n_jobs=multiprocessing.cpu_count())(
|
2021-04-10 22:44:45 +00:00
|
|
|
delayed(remove_parallel_user_photos)(i, count2) for i in range(10))
|
2021-01-25 02:15:54 +00:00
|
|
|
DBHelper.remove_data("User_" + str(count2))
|
2021-02-10 16:07:59 +00:00
|
|
|
shutil.rmtree("Facial_images/face_rec/train/User_" + str(count2))
|
2021-01-25 02:15:54 +00:00
|
|
|
print("Successfully removed the User.")
|
|
|
|
break
|
2021-02-10 16:07:59 +00:00
|
|
|
print("Reorganizing the Users...")
|
2021-01-25 02:15:54 +00:00
|
|
|
if count2 != count and count - count2 - 1 != 0:
|
2021-02-10 15:09:59 +00:00
|
|
|
for x in range(count - count2):
|
2021-02-10 16:07:59 +00:00
|
|
|
if not os.path.isdir("Facial_images/face_rec/train/User_" + str(count2)):
|
|
|
|
os.makedirs("Facial_images/face_rec/train/User_" + str(count2))
|
|
|
|
Parallel(n_jobs=multiprocessing.cpu_count())(
|
2021-04-10 22:44:45 +00:00
|
|
|
delayed(update_parallel_user_photos)(i, count2) for i in range(10))
|
2021-02-10 15:09:59 +00:00
|
|
|
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)))
|
2021-01-25 02:15:54 +00:00
|
|
|
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:
|
2021-02-10 16:07:59 +00:00
|
|
|
if not os.path.isdir("Facial_images/face_rec/train/User_" + str(count2)):
|
|
|
|
os.makedirs("Facial_images/face_rec/train/User_" + str(count2))
|
|
|
|
Parallel(n_jobs=multiprocessing.cpu_count())(
|
2021-04-10 22:44:45 +00:00
|
|
|
delayed(update_parallel_user_photos)(i, count2) for i in range(10))
|
2021-02-10 15:09:59 +00:00
|
|
|
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)))
|
2021-01-25 02:15:54 +00:00
|
|
|
DBHelper.remove_data("User_" + str(count))
|
|
|
|
shutil.rmtree("Facial_images/face_rec/train/User_" + str(count))
|
2021-02-15 17:27:35 +00:00
|
|
|
print("Data saved! Starting enrollment...")
|
|
|
|
Facial_Recognition_Enrollment.enroll_face_dataset()
|
|
|
|
print("Face removal completed!")
|
2021-01-25 02:15:54 +00:00
|
|
|
print("Success.")
|
2021-01-23 01:55:35 +00:00
|
|
|
except:
|
2021-01-25 02:15:54 +00:00
|
|
|
print("No Users exist for User Removal.")
|
|
|
|
|
|
|
|
|
2021-02-10 16:07:59 +00:00
|
|
|
def remove_parallel_user_photos(i, count2):
|
|
|
|
DBHelper.delete_user_photo("User_" + str(count2) + "/" + str(i) + ".jpg")
|
|
|
|
|
|
|
|
|
|
|
|
def update_parallel_user_photos(i, count2):
|
|
|
|
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")
|
2021-03-21 17:37:41 +00:00
|
|
|
DBHelper.delete_user_photo("User_" + str(count2 + 1) + "/" + str(i) + ".jpg")
|
|
|
|
|
|
|
|
|
|
|
|
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)
|