Added User Removal Function, Seperated Engine Start and Check Up components and fixed some errors.
This commit is contained in:
parent
3488e691b1
commit
e4ffc1b241
7 changed files with 164 additions and 37 deletions
36
Check_Up.py
Normal file
36
Check_Up.py
Normal file
|
@ -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()
|
47
DBHelper.py
47
DBHelper.py
|
@ -169,5 +169,50 @@ def remove_register_data():
|
||||||
db.child("signal").child("2").remove()
|
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__":
|
if __name__ == "__main__":
|
||||||
upload_register_data("RandomFirst", "RandomLast", "Random@gmail.com", "0000000000")
|
upload_data("User_3", "RandomFirst", "RandomLast", "Random@gmail.com", "0000000000")
|
||||||
|
|
13
Main.py
13
Main.py
|
@ -1,11 +1,14 @@
|
||||||
import DBHelper
|
import DBHelper
|
||||||
import Start_Engine
|
import Start_Engine
|
||||||
import Upload_Face
|
import Upload_Face
|
||||||
|
import Remove_Face
|
||||||
|
import Check_Up
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Starting the Program.")
|
print("Starting the Program.")
|
||||||
while True:
|
while True:
|
||||||
if DBHelper.get_power() == "on":
|
if DBHelper.get_power() == "on":
|
||||||
|
Check_Up.update()
|
||||||
Start_Engine.start()
|
Start_Engine.start()
|
||||||
|
|
||||||
if None not in (DBHelper.get_register_firstname(),
|
if None not in (DBHelper.get_register_firstname(),
|
||||||
|
@ -14,4 +17,14 @@ if __name__ == "__main__":
|
||||||
DBHelper.get_register_phone()):
|
DBHelper.get_register_phone()):
|
||||||
Upload_Face.upload_your_face(DBHelper.get_register_firstname(), DBHelper.get_register_lastname(),
|
Upload_Face.upload_your_face(DBHelper.get_register_firstname(), DBHelper.get_register_lastname(),
|
||||||
DBHelper.get_register_email(), DBHelper.get_register_phone())
|
DBHelper.get_register_email(), DBHelper.get_register_phone())
|
||||||
|
Check_Up.update()
|
||||||
DBHelper.remove_register_data()
|
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()
|
||||||
|
|
|
@ -1,14 +1,65 @@
|
||||||
import DBHelper
|
import DBHelper
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
def remove_your_face():
|
|
||||||
|
def remove_your_face(firstname, lastname, email, phone):
|
||||||
users = DBHelper.db.child("Users").get()
|
users = DBHelper.db.child("Users").get()
|
||||||
try:
|
try:
|
||||||
count = 0
|
count = 0
|
||||||
|
count2 = 0
|
||||||
for user in users.each():
|
for user in users.each():
|
||||||
count += 1
|
count += 1
|
||||||
DBHelper.upload_data("User_" + str(count), firstname, lastname, email, phone)
|
print("Removing the specified User...")
|
||||||
Facial_Recognition_Registration.register_your_face("User_" + str(count))
|
for user in users.each():
|
||||||
for i in range(20):
|
count2 += 1
|
||||||
DBHelper.upload_user_photo("User_" + str(count) + "/" + str(i) + ".jpg")
|
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:
|
except:
|
||||||
print("No Users are registered.")
|
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)
|
||||||
|
|
|
@ -8,6 +8,7 @@ def upload_your_face(firstname, lastname, email, phone):
|
||||||
# User ID is determined from number of user dataset in database
|
# 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.
|
# 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()
|
users = DBHelper.db.child("Users").get()
|
||||||
|
print("Registering the User information...")
|
||||||
try:
|
try:
|
||||||
count = 1
|
count = 1
|
||||||
for user in users.each():
|
for user in users.each():
|
||||||
|
@ -18,12 +19,13 @@ def upload_your_face(firstname, lastname, email, phone):
|
||||||
print("Data saved! Starting enrollment...")
|
print("Data saved! Starting enrollment...")
|
||||||
Facial_Recognition_Enrollment.enroll_face_dataset()
|
Facial_Recognition_Enrollment.enroll_face_dataset()
|
||||||
print("Face registration completed!")
|
print("Face registration completed!")
|
||||||
for i in range(20):
|
for i in range(50):
|
||||||
DBHelper.upload_user_photo("User_" + str(count) + "/" + str(i) + ".jpg")
|
DBHelper.upload_user_photo("User_" + str(count) + "/" + str(i) + ".jpg")
|
||||||
|
print("Success.")
|
||||||
except:
|
except:
|
||||||
DBHelper.upload_data("User_1", firstname, lastname, email, phone)
|
DBHelper.upload_data("User_1", firstname, lastname, email, phone)
|
||||||
Facial_Recognition_Registration.register_your_face("User_1")
|
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")
|
DBHelper.upload_user_photo("User_1/" + str(i) + ".jpg")
|
||||||
|
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -1,38 +1,18 @@
|
||||||
import os
|
|
||||||
import DBHelper
|
import DBHelper
|
||||||
import Facial_Recognition_Inference
|
import Facial_Recognition_Inference
|
||||||
|
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
# Downloads all the user and thief photos from database to the project folder first or updates them.
|
# It checks if a user is registered then starts the Facial Recognition Software.
|
||||||
# Then it starts Facial Recognition Software.
|
|
||||||
users = DBHelper.db.child("Users").get()
|
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
|
count = 0
|
||||||
print("Checking and updating Thief photos...")
|
for user in users.each():
|
||||||
try:
|
count += 1
|
||||||
for thief in thieves.each():
|
if count != 0:
|
||||||
count += 1
|
print("Starting the Face Recognition Software...")
|
||||||
if not os.path.isdir("Photos_of_Thieves/Thief_" + str(count)):
|
Facial_Recognition_Inference.inference()
|
||||||
os.makedirs("Photos_of_Thieves/Thief_" + str(count))
|
else:
|
||||||
for i in range(20):
|
print("No Users exist for Facial Recognition Software.")
|
||||||
DBHelper.download_thief_photo("Thief_" + str(count) + "/" + str(i) + ".jpg")
|
|
||||||
print("Success.")
|
|
||||||
except:
|
|
||||||
print("No Thieves are registered.")
|
|
||||||
Facial_Recognition_Inference.inference()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue