2021-01-25 02:15:54 +00:00
|
|
|
import os
|
|
|
|
import DBHelper
|
2021-02-10 03:07:56 +00:00
|
|
|
from joblib import Parallel, delayed
|
|
|
|
import multiprocessing
|
2021-01-25 02:15:54 +00:00
|
|
|
|
2021-02-15 17:27:35 +00:00
|
|
|
import Facial_Recognition_Enrollment
|
|
|
|
|
2021-01-25 02:15:54 +00:00
|
|
|
|
|
|
|
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))
|
2021-02-10 03:07:56 +00:00
|
|
|
Parallel(n_jobs=multiprocessing.cpu_count())(
|
|
|
|
delayed(download_parallel_user_photos)(i, count) for i in range(50))
|
2021-02-15 17:33:49 +00:00
|
|
|
print("User data is checked.")
|
2021-01-25 02:15:54 +00:00
|
|
|
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))
|
2021-02-10 03:07:56 +00:00
|
|
|
Parallel(n_jobs=multiprocessing.cpu_count())(
|
|
|
|
delayed(download_parallel_thief_photos)(i, count) for i in range(50))
|
2021-02-15 17:33:49 +00:00
|
|
|
print("Thief data is checked.")
|
2021-01-25 02:15:54 +00:00
|
|
|
except:
|
|
|
|
print("No Thieves are registered.")
|
2021-02-15 17:27:35 +00:00
|
|
|
print("Data saved! Starting enrollment...")
|
|
|
|
Facial_Recognition_Enrollment.enroll_face_dataset()
|
|
|
|
print("Success.")
|
2021-01-25 02:15:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
update()
|
2021-02-10 03:07:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
def download_parallel_user_photos(i, count):
|
|
|
|
DBHelper.download_user_photo("User_" + str(count) + "/" + str(i) + ".jpg")
|
|
|
|
|
|
|
|
|
|
|
|
def download_parallel_thief_photos(i, count):
|
|
|
|
DBHelper.download_thief_photo("Thief_" + str(count) + "/" + str(i) + ".jpg")
|