Upload files to 'Events/src'

This commit is contained in:
2023-08-29 06:05:56 +00:00
bovenliggende 1866d5678e
commit 4cdbec6f68
2 gewijzigde bestanden met toevoegingen van 557 en 540 verwijderingen
+492 -492
Bestand weergeven
@@ -1,493 +1,493 @@
import requests import requests
import time import time
import multiprocessing import multiprocessing
from PIL import Image from PIL import Image
from functools import partial from functools import partial
import queue import queue
import pickle import pickle
import time import time
import numpy as np import numpy as np
import face_recognition import face_recognition
import os import os
from flask import Flask, render_template, request, redirect, send_file from flask import Flask, render_template, request, redirect, send_file
# import shutil # import shutil
import cv2 import cv2
import datetime import datetime
from flask import request from flask import request
# Gallery = "D:/share/biz/mt/Copy_Gallery/" + str(seconds).replace("]", "").replace("[", "").replace("'", "") # Gallery = "D:/share/biz/mt/Copy_Gallery/" + str(seconds).replace("]", "").replace("[", "").replace("'", "")
# People = 'D:/share/biz/mt/People/' + str(seconds).replace("]", "").replace("[", "").replace("'", "") + "/" # People = 'D:/share/biz/mt/People/' + str(seconds).replace("]", "").replace("[", "").replace("'", "") + "/"
app = Flask(__name__) app = Flask(__name__)
@app.route('/', methods=["GET", "POST"]) @app.route('/', methods=["GET", "POST"])
def home(): def home():
return "EVENT APP RUNNING.............." return "EVENT APP RUNNING.............."
def download(eventid): def download(eventid):
print("process started with event id = "+str(eventid)) print("process started with event id = "+str(eventid))
Gallery = "/home/ubuntu/AI/Events/Gallery/" + eventid+ "/" Gallery = "/home/ubuntu/AI/Events/Gallery/" + eventid+ "/"
People = "/home/ubuntu/AI/Events/guestimage/"+ eventid + "/" People = "/home/ubuntu/AI/Events/guestimage/"+ eventid + "/"
def saveEncodings(encs, names, fname="encodings.pickle"): def saveEncodings(encs, names, fname="encodings.pickle"):
""" """
Save encodings in a pickle file to be used in future. Save encodings in a pickle file to be used in future.
Parameters Parameters
---------- ----------
encs : List of np arrays encs : List of np arrays
List of face encodings. List of face encodings.
names : List of strings names : List of strings
List of names for each face encoding. List of names for each face encoding.
fname : String, optional fname : String, optional
Name/Location for pickle file. The default is "encodings.pickle". Name/Location for pickle file. The default is "encodings.pickle".
Returns Returns
------- -------
None. None.
""" """
data = [] data = []
d = [{"name": nm, "encoding": enc} for (nm, enc) in zip(names, encs)] d = [{"name": nm, "encoding": enc} for (nm, enc) in zip(names, encs)]
data.extend(d) data.extend(d)
encodingsFile = fname encodingsFile = fname
# dump the facial encodings data to disk # dump the facial encodings data to disk
print("[INFO] serializing encodings...") print("[INFO] serializing encodings...")
f = open(encodingsFile, "wb") f = open(encodingsFile, "wb")
f.write(pickle.dumps(data)) f.write(pickle.dumps(data))
f.close() f.close()
# Function to read encodings # Function to read encodings
def readEncodingsPickle(fname): def readEncodingsPickle(fname):
""" """
Read Pickle file. Read Pickle file.
Parameters Parameters
---------- ----------
fname : String fname : String
Name of pickle file.(Full location) Name of pickle file.(Full location)
Returns Returns
------- -------
encodings : list of np arrays encodings : list of np arrays
list of all saved encodings list of all saved encodings
names : List of Strings names : List of Strings
List of all saved names List of all saved names
""" """
data = pickle.loads(open(fname, "rb").read()) data = pickle.loads(open(fname, "rb").read())
data = np.array(data) data = np.array(data)
encodings = [d["encoding"] for d in data] encodings = [d["encoding"] for d in data]
names = [d["name"] for d in data] names = [d["name"] for d in data]
return encodings, names return encodings, names
# Function to create encodings and get face locations # Function to create encodings and get face locations
def createEncodings(image): def createEncodings(image):
print("encoding..") print("encoding..")
#print('Detecting_face...........') #print('Detecting_face...........')
""" """
Create face encodings for a given image and also return face locations in the given image. Create face encodings for a given image and also return face locations in the given image.
Parameters Parameters
---------- ----------
image : cv2 mat image : cv2 mat
Image you want to detect faces from. Image you want to detect faces from.
Returns Returns
------- -------
known_encodings : list of np array known_encodings : list of np array
List of face encodings in a given image List of face encodings in a given image
face_locations : list of tuples face_locations : list of tuples
list of tuples for face locations in a given image list of tuples for face locations in a given image
""" """
# Find face locations for all faces in an image # Find face locations for all faces in an image
face_locations = face_recognition.face_locations(image) face_locations = face_recognition.face_locations(image)
# Create encodings for all faces in an image # Create encodings for all faces in an image
known_encodings = face_recognition.face_encodings(image, known_face_locations=face_locations) known_encodings = face_recognition.face_encodings(image, known_face_locations=face_locations)
return known_encodings, face_locations return known_encodings, face_locations
# Function to compare encodings # Function to compare encodings
def compareFaceEncodings(unknown_encoding, known_encodings, known_names): def compareFaceEncodings(unknown_encoding, known_encodings, known_names):
""" """
Compares face encodings to check if 2 faces are same or not. Compares face encodings to check if 2 faces are same or not.
Parameters Parameters
---------- ----------
unknown_encoding : np array unknown_encoding : np array
Face encoding of unknown people. Face encoding of unknown people.
known_encodings : np array known_encodings : np array
Face encodings of known people. Face encodings of known people.
known_names : list of strings known_names : list of strings
Names of known people Names of known people
Returns Returns
------- -------
acceptBool : Bool acceptBool : Bool
face matched or not face matched or not
duplicateName : String duplicateName : String
Name of matched face Name of matched face
distance : Float distance : Float
Distance between 2 faces Distance between 2 faces
""" """
duplicateName = "" duplicateName = ""
distance = 0.0 distance = 0.0
matches = face_recognition.compare_faces(known_encodings, unknown_encoding, tolerance=0.47) matches = face_recognition.compare_faces(known_encodings, unknown_encoding, tolerance=0.47)
face_distances = face_recognition.face_distance(known_encodings, unknown_encoding) face_distances = face_recognition.face_distance(known_encodings, unknown_encoding)
best_match_index = np.argmin(face_distances) best_match_index = np.argmin(face_distances)
distance = face_distances[best_match_index] distance = face_distances[best_match_index]
if matches[best_match_index]: if matches[best_match_index]:
acceptBool = True acceptBool = True
duplicateName = known_names[best_match_index] duplicateName = known_names[best_match_index]
else: else:
acceptBool = False acceptBool = False
duplicateName = "" duplicateName = ""
return acceptBool, duplicateName, distance return acceptBool, duplicateName, distance
p = [] p = []
def f_CSVwrite(): def f_CSVwrite():
import pandas as pd import pandas as pd
q = pd.DataFrame(p) q = pd.DataFrame(p)
#print(q) #print(q)
m = q m = q
# print(m) # print(m)
# x.drop(x.columns[Unnam], axis=1, inplace=True) # x.drop(x.columns[Unnam], axis=1, inplace=True)
df = m.groupby([0], as_index=False).count() df = m.groupby([0], as_index=False).count()
z = df[0].str.split('/', expand=True) z = df[0].str.split('/', expand=True)
z.to_csv('zzzzzzzzzzzzz.csv',index=False) z.to_csv('zzzzzzzzzzzzz.csv',index=False)
import pandas as pd import pandas as pd
df2 = pd.read_csv('zzzzzzzzzzzzz.csv') df2 = pd.read_csv('zzzzzzzzzzzzz.csv')
df2.rename({df2.columns[-1]: 'test'}, axis=1, inplace=True) df2.rename({df2.columns[-1]: 'test'}, axis=1, inplace=True)
df2.rename({df2.columns[-2]: 'Matched'}, axis=1, inplace=True) df2.rename({df2.columns[-2]: 'Matched'}, axis=1, inplace=True)
df2 = df2[['Matched', 'test']] df2 = df2[['Matched', 'test']]
import pandas as pd import pandas as pd
import os import os
c = [] c = []
for root, dirs, files in os.walk(Gallery, for root, dirs, files in os.walk(Gallery,
topdown=False): topdown=False):
for name in files: for name in files:
# print(name) # print(name)
L = os.path.join(root, name) L = os.path.join(root, name)
c.append(L) c.append(L)
df = pd.DataFrame(c) df = pd.DataFrame(c)
df1 = df[0].str.split("/", expand=True) df1 = df[0].str.split("/", expand=True)
#df1.rename({df1.columns[-2]: 'abc'}, axis=1, inplace=True) #df1.rename({df1.columns[-2]: 'abc'}, axis=1, inplace=True)
# print('this is df1') # print('this is df1')
# print(df1) # print(df1)
df1.rename({df1.columns[-1]: 'test'}, axis=1, inplace=True) df1.rename({df1.columns[-1]: 'test'}, axis=1, inplace=True)
merge = pd.merge(df2, df1, on='test', how='left') merge = pd.merge(df2, df1, on='test', how='left')
merge.rename({merge.columns[-1]: 'EventName'}, axis=1, inplace=True) merge.rename({merge.columns[-1]: 'EventName'}, axis=1, inplace=True)
# merge.to_csv('merge.csv') # merge.to_csv('merge.csv')
mergesplit = merge.loc[:, 'test'].str.split(".", expand=True) mergesplit = merge.loc[:, 'test'].str.split(".", expand=True)
mergesplit.rename({mergesplit.columns[-2]: 'ImageName'}, axis=1, inplace=True) mergesplit.rename({mergesplit.columns[-2]: 'ImageName'}, axis=1, inplace=True)
mergesplit = mergesplit.loc[:, 'ImageName'] mergesplit = mergesplit.loc[:, 'ImageName']
#merge.rename({merge.columns[-1]: 'Matched'}, axis=1, inplace=True) #merge.rename({merge.columns[-1]: 'Matched'}, axis=1, inplace=True)
#merge['EventName'] = merge['abc'] #merge['EventName'] = merge['abc']
merge['Imagepath'] = "\\_files\\1\\Gallery\\" + merge['EventName'] + '\\' + + merge['test'] merge['Imagepath'] = "\\_files\\1\\Gallery\\" + merge['EventName'] + '\\' + + merge['test']
frames = [merge, mergesplit] frames = [merge, mergesplit]
r = pd.concat(frames, axis=1, join='inner') r = pd.concat(frames, axis=1, join='inner')
df2 = r.dropna(subset=['Matched']) df2 = r.dropna(subset=['Matched'])
#df2['Matched'] = df2['Matched'].astype(str) #df2['Matched'] = df2['Matched'].astype(str)
#df2['Matched'] = df2['Matched'].astype(int) #df2['Matched'] = df2['Matched'].astype(int)
column_list = ['Matched', 'Imagepath', 'ImageName', 'EventName'] column_list = ['Matched', 'Imagepath', 'ImageName', 'EventName']
df2[column_list].to_csv('events.csv', index=False) df2[column_list].to_csv('events.csv', index=False)
df2[column_list].to_json('events.json', orient="records") df2[column_list].to_json('events.json', orient="records")
# import requests # import requests
# import json # import json
# with open('events.json', 'r') as json_file: # with open('events.json', 'r') as json_file:
# json_load = json.load(json_file) # json_load = json.load(json_file)
# url = "https://eventxstreamnew.bizgaze.com:5443/apis/v4/bizgaze/integrations/events/createpredictedimage" # url = "https://eventxstreamnew.bizgaze.com:5443/apis/v4/bizgaze/integrations/events/createpredictedimage"
# #url = "https://eventxstreamnew.bizgaze.com:5443/apis/v4/bizgaze/integrations/json/eventwisepredicts" # #url = "https://eventxstreamnew.bizgaze.com:5443/apis/v4/bizgaze/integrations/json/eventwisepredicts"
# payload = json.dumps(json_load).replace("]", "").replace("[", "") # payload = json.dumps(json_load).replace("]", "").replace("[", "")
# print(payload) # print(payload)
# headers = { # headers = {
# 'Authorization': 'stat bcc78ad858354e759249c1770957fede', # 'Authorization': 'stat bcc78ad858354e759249c1770957fede',
# 'Content-Type': 'application/json' # 'Content-Type': 'application/json'
# } # }
# response = requests.request("POST", url, headers=headers, data=payload) # response = requests.request("POST", url, headers=headers, data=payload)
# print("Ongoing process with event id = "+str(eventid)) # print("Ongoing process with event id = "+str(eventid))
# print("##############################################################") # print("##############################################################")
# print(response.text) # print(response.text)
p.clear() p.clear()
# Save Image to new directory # Save Image to new directory
def saveImageToDirectory(image, name, imageName): def saveImageToDirectory(image, name, imageName):
""" """
Saves images to directory. Saves images to directory.
Parameters Parameters
---------- ----------
image : cv2 mat image : cv2 mat
Image you want to save. Image you want to save.
name : String name : String
Directory where you want the image to be saved. Directory where you want the image to be saved.
imageName : String imageName : String
Name of image. Name of image.
Returns Returns
------- -------
None. None.
""" """
path = "./output/" + name path = "./output/" + name
path1 = "./output/" + name path1 = "./output/" + name
if os.path.exists(path): if os.path.exists(path):
pass pass
else: else:
os.mkdir(path) os.mkdir(path)
cv2.imwrite(path + "/" + imageName, image) cv2.imwrite(path + "/" + imageName, image)
x = [] x = []
c = (path1 + "/" + imageName) c = (path1 + "/" + imageName)
x.append(c) x.append(c)
p.append(x) p.append(x)
f_CSVwrite() f_CSVwrite()
# Function for creating encodings for known people # Function for creating encodings for known people
def processKnownPeopleImages(path=People, saveLocation="./known_encodings.pickle"): def processKnownPeopleImages(path=People, saveLocation="./known_encodings.pickle"):
print(People) print(People)
""" """
Process images of known people and create face encodings to compare in future. Process images of known people and create face encodings to compare in future.
Eaach image should have just 1 face in it. Eaach image should have just 1 face in it.
Parameters Parameters
---------- ----------
path : STRING, optional path : STRING, optional
Path for known people dataset. The default is "C:/inetpub/vhosts/port82/wwwroot/_files/People". Path for known people dataset. The default is "C:/inetpub/vhosts/port82/wwwroot/_files/People".
It should be noted that each image in this dataset should contain only 1 face. It should be noted that each image in this dataset should contain only 1 face.
saveLocation : STRING, optional saveLocation : STRING, optional
Path for storing encodings for known people dataset. The default is "./known_encodings.pickle in current directory". Path for storing encodings for known people dataset. The default is "./known_encodings.pickle in current directory".
Returns Returns
------- -------
None. None.
""" """
known_encodings = [] known_encodings = []
known_names = [] known_names = []
for img in os.listdir(path): for img in os.listdir(path):
imgPath = path + img imgPath = path + img
# Read image # Read image
image = cv2.imread(imgPath) image = cv2.imread(imgPath)
name = img.rsplit('.')[0] name = img.rsplit('.')[0]
# Resize # Resize
image = cv2.resize(image, (0, 0), fx=0.6, fy=0.6, interpolation=cv2.INTER_LINEAR) image = cv2.resize(image, (0, 0), fx=0.6, fy=0.6, interpolation=cv2.INTER_LINEAR)
# Get locations and encodings # Get locations and encodings
encs, locs = createEncodings(image) encs, locs = createEncodings(image)
try: try:
known_encodings.append(encs[0]) known_encodings.append(encs[0])
except IndexError: except IndexError:
os.remove(People+img) os.remove(People+img)
known_names.append(name) known_names.append(name)
for loc in locs: for loc in locs:
top, right, bottom, left = loc top, right, bottom, left = loc
# Show Image # Show Image
#cv2.rectangle(image, (left, top), (right, bottom), color=(255, 0, 0), thickness=2) #cv2.rectangle(image, (left, top), (right, bottom), color=(255, 0, 0), thickness=2)
# cv2.imshow("Image", image) # cv2.imshow("Image", image)
# cv2.waitKey(1) # cv2.waitKey(1)
#cv2.destroyAllWindows() #cv2.destroyAllWindows()
saveEncodings(known_encodings, known_names, saveLocation) saveEncodings(known_encodings, known_names, saveLocation)
# Function for processing dataset images # Function for processing dataset images
def processDatasetImages(saveLocation="./Gallery_encodings.pickle"): def processDatasetImages(saveLocation="./Gallery_encodings.pickle"):
""" """
Process image in dataset from where you want to separate images. Process image in dataset from where you want to separate images.
It separates the images into directories of known people, groups and any unknown people images. It separates the images into directories of known people, groups and any unknown people images.
Parameters Parameters
---------- ----------
path : STRING, optional path : STRING, optional
Path for known people dataset. The default is "D:/port1004/port1004/wwwroot/_files/People". Path for known people dataset. The default is "D:/port1004/port1004/wwwroot/_files/People".
It should be noted that each image in this dataset should contain only 1 face. It should be noted that each image in this dataset should contain only 1 face.
saveLocation : STRING, optional saveLocation : STRING, optional
Path for storing encodings for known people dataset. The default is "./known_encodings.pickle in current directory". Path for storing encodings for known people dataset. The default is "./known_encodings.pickle in current directory".
Returns Returns
------- -------
None. None.
""" """
# Read pickle file for known people to compare faces from # Read pickle file for known people to compare faces from
people_encodings, names = readEncodingsPickle("./known_encodings.pickle") people_encodings, names = readEncodingsPickle("./known_encodings.pickle")
for root, dirs, files in os.walk(Gallery, topdown=False): for root, dirs, files in os.walk(Gallery, topdown=False):
for name in files: for name in files:
s = os.path.join(root, name) s = os.path.join(root, name)
#print(p) #print(p)
# imgPath = path + img # imgPath = path + img
# Read image # Read image
image = cv2.imread(s) image = cv2.imread(s)
orig = image.copy() orig = image.copy()
# Resize # Resize
image = cv2.resize(image, (0, 0), fx=0.6, fy=0.6, interpolation=cv2.INTER_LINEAR) image = cv2.resize(image, (0, 0), fx=0.6, fy=0.6, interpolation=cv2.INTER_LINEAR)
# Get locations and encodings # Get locations and encodings
encs, locs = createEncodings(image) encs, locs = createEncodings(image)
# Save image to a group image folder if more than one face is in image # Save image to a group image folder if more than one face is in image
# if len(locs) > 1: # if len(locs) > 1:
# saveImageToDirectory(orig, "Group", img) # saveImageToDirectory(orig, "Group", img)
# Processing image for each face # Processing image for each face
i = 0 i = 0
knownFlag = 0 knownFlag = 0
for loc in locs: for loc in locs:
top, right, bottom, left = loc top, right, bottom, left = loc
unknown_encoding = encs[i] unknown_encoding = encs[i]
i += 1 i += 1
acceptBool, duplicateName, distance = compareFaceEncodings(unknown_encoding, people_encodings, names) acceptBool, duplicateName, distance = compareFaceEncodings(unknown_encoding, people_encodings, names)
if acceptBool: if acceptBool:
saveImageToDirectory(orig, duplicateName,name) saveImageToDirectory(orig, duplicateName,name)
knownFlag = 1 knownFlag = 1
if knownFlag == 1: if knownFlag == 1:
print("Match Found") print("Match Found")
else: else:
saveImageToDirectory(orig, "0",name) saveImageToDirectory(orig, "0",name)
# Show Image # Show Image
# cv2.rectangle(image, (left, top), (right, bottom), color=(255, 0, 0), thickness=2) # cv2.rectangle(image, (left, top), (right, bottom), color=(255, 0, 0), thickness=2)
# # cv2.imshow("Image", image) # # cv2.imshow("Image", image)
# cv2.waitKey(1) # cv2.waitKey(1)
# cv2.destroyAllWindows() # cv2.destroyAllWindows()
def main(): def main():
""" """
Main Function. Main Function.
Returns Returns
------- -------
None. None.
""" """
processKnownPeopleImages() processKnownPeopleImages()
processDatasetImages() processDatasetImages()
# import pandas as pd # import pandas as pd
# q = pd.DataFrame(p) # q = pd.DataFrame(p)
# df1 = q # df1 = q
# print(df1) # print(df1)
# # df1.to_csv('m.csv') # # df1.to_csv('m.csv')
# import pandas as pd # import pandas as pd
# import os # import os
# c = [] # c = []
# for root, dirs, files in os.walk(Gallery, topdown=False): # for root, dirs, files in os.walk(Gallery, topdown=False):
# for name in files: # for name in files:
# L = os.path.join(root, name) # L = os.path.join(root, name)
# c.append(L) # c.append(L)
# df2 = pd.DataFrame(c) # df2 = pd.DataFrame(c)
# # df.to_csv('oswalk.csv') # # df.to_csv('oswalk.csv')
# import pandas as pd # import pandas as pd
# # df1 = pd.read_csv('m.csv') # # df1 = pd.read_csv('m.csv')
# # df2 = pd.read_csv('oswalk.csv') # # df2 = pd.read_csv('oswalk.csv')
# df1 = df1[0].str.split('/', expand=True) # df1 = df1[0].str.split('/', expand=True)
# df1.rename({df1.columns[-2]: 'Matched'}, axis=1, inplace=True) # df1.rename({df1.columns[-2]: 'Matched'}, axis=1, inplace=True)
# df1.rename({df1.columns[-1]: 'test'}, axis=1, inplace=True) # df1.rename({df1.columns[-1]: 'test'}, axis=1, inplace=True)
# df2 = df2[0].str.split("\\", expand=True) # df2 = df2[0].str.split("\\", expand=True)
# df2.rename({df2.columns[-1]: 'test'}, axis=1, inplace=True) # df2.rename({df2.columns[-1]: 'test'}, axis=1, inplace=True)
# df2.rename({df2.columns[-2]: 'Eventname'}, axis=1, inplace=True) # df2.rename({df2.columns[-2]: 'Eventname'}, axis=1, inplace=True)
# merge = pd.merge(df2, df1, on='test', how='left') # merge = pd.merge(df2, df1, on='test', how='left')
# mergesplit = merge.loc[:, 'test'].str.split(".", expand=True) # mergesplit = merge.loc[:, 'test'].str.split(".", expand=True)
# mergesplit.rename({mergesplit.columns[-2]: 'ImageName'}, axis=1, inplace=True) # mergesplit.rename({mergesplit.columns[-2]: 'ImageName'}, axis=1, inplace=True)
# mergesplit = mergesplit.loc[:, 'ImageName'] # mergesplit = mergesplit.loc[:, 'ImageName']
# merge['Imagepath'] = "/_files/1/Gallery/" + merge['Eventname'] + '/' + merge['test'] # merge['Imagepath'] = "/_files/1/Gallery/" + merge['Eventname'] + '/' + merge['test']
# frames = [merge, mergesplit] # frames = [merge, mergesplit]
# r = pd.concat(frames, axis=1, join='inner') # r = pd.concat(frames, axis=1, join='inner')
# first_column = r.pop('Matched') # first_column = r.pop('Matched')
# r.insert(0, 'Matched', first_column) # r.insert(0, 'Matched', first_column)
# second_column = r.pop('Imagepath') # second_column = r.pop('Imagepath')
# r.insert(1, 'Imagepath', second_column) # r.insert(1, 'Imagepath', second_column)
# third_column = r.pop('ImageName') # third_column = r.pop('ImageName')
# r.insert(2, 'ImageName', third_column) # r.insert(2, 'ImageName', third_column)
# fourth_column = r.pop('Eventname') # fourth_column = r.pop('Eventname')
# r.insert(3, 'Eventname', fourth_column) # r.insert(3, 'Eventname', fourth_column)
# r = r.iloc[:, 0:4] # r = r.iloc[:, 0:4]
# r.sort_values(by=['Matched'], inplace=True) # r.sort_values(by=['Matched'], inplace=True)
# print(r) # print(r)
# r.to_csv('path.csv', index=False) # r.to_csv('path.csv', index=False)
# r.to_json(r'matched.json', orient="records") # r.to_json(r'matched.json', orient="records")
print("process Ended with event id = "+str(eventid)) print("process Ended with event id = "+str(eventid))
main() main()
@app.route('/eventwise', methods=["GET", "POST"]) @app.route('/eventwise', methods=["GET", "POST"])
def eventwise(): def eventwise():
if __name__ == "__main__": if __name__ == "__main__":
url_list=[] url_list=[]
Dataset= request.args.get('Dataset') Dataset= request.args.get('Dataset')
# id = "100013660000125" # id = "100013660000125"
url_list.append(Dataset) url_list.append(Dataset)
# multiprocessing # multiprocessing
with multiprocessing.Pool(processes=10) as pool: with multiprocessing.Pool(processes=10) as pool:
results = pool.map(download,url_list) results = pool.map(download,url_list)
pool.close() pool.close()
return "none" return "Done"
if __name__ == "__main__": if __name__ == "__main__":
app.run(host="0.0.0.0",port=8081) app.run(host="0.0.0.0",port=8081)
+65 -48
Bestand weergeven
@@ -8,8 +8,8 @@ import cv2
app = Flask(__name__) app = Flask(__name__)
app.config["IMAGE_UPLOADS"] = "C:/Users/Bizgaze/PycharmProjects/face_recogniction/People" app.config["IMAGE_UPLOADS"] = "C:/Users/Bizgaze/PycharmProjects/face_recogniction/People"
datasetPath = "./Gallery/" datasetPath = "/opt/bizgaze/events.bizgaze.app/wwwroot/_files/1/Gallery/"
peoplePath = "./guestimage/" peoplePath = "/opt/bizgaze/events.bizgaze.app/wwwroot/_files/People/"
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])
def home(): def home():
return render_template('index.html') return render_template('index.html')
@@ -44,7 +44,9 @@ def upload():
@app.route('/predict', methods=["GET", "POST"]) @app.route('/predict', methods=["GET", "POST"])
def predict(): def predict():
print('starting')
def saveEncodings(encs, names, fname="encodings.pickle"): def saveEncodings(encs, names, fname="encodings.pickle"):
print('encoding')
""" """
Save encodings in a pickle file to be used in future. Save encodings in a pickle file to be used in future.
@@ -153,7 +155,7 @@ def predict():
""" """
duplicateName = "" duplicateName = ""
distance = 0.0 distance = 0.0
matches = face_recognition.compare_faces(known_encodings, unknown_encoding, tolerance=0.5) matches = face_recognition.compare_faces(known_encodings, unknown_encoding, tolerance=0.47)
face_distances = face_recognition.face_distance(known_encodings, unknown_encoding) face_distances = face_recognition.face_distance(known_encodings, unknown_encoding)
best_match_index = np.argmin(face_distances) best_match_index = np.argmin(face_distances)
distance = face_distances[best_match_index] distance = face_distances[best_match_index]
@@ -324,9 +326,9 @@ def predict():
processKnownPeopleImages() processKnownPeopleImages()
processDatasetImages() processDatasetImages()
shutil.make_archive('./Images', 'zip','./output') # shutil.make_archive('./Images', 'zip','./output')
p='./Images.zip' # p='./Images.zip'
return send_file(p,as_attachment=True) # return send_file(p,as_attachment=True)
# import pandas as pd # import pandas as pd
@@ -343,52 +345,65 @@ def predict():
##############################csv creation code ############################## ##############################csv creation code ##############################
# import pandas as pd import pandas as pd
# q = pd.DataFrame(p) q = pd.DataFrame(p)
# m = q m = q
# print(m) #print(m)
# # x.drop(x.columns[Unnam], axis=1, inplace=True) # x.drop(x.columns[Unnam], axis=1, inplace=True)
# df = m.groupby([0], as_index=False).count() df = m.groupby([0], as_index=False).count()
# z = df[0].str.split('/', expand=True) first_column_name = df.columns[0]
# z['ImagePath'] = z[3] # Rename the first column
df.rename(columns={first_column_name: 'col'}, inplace=True)
#print(df)
z = df['col'].str.split('/', expand=True)
# result = z.drop([0,1,3], axis=1) z['ImagePath'] = z[3]
# result.rename({result.columns[-1]: 'test'}, axis=1, inplace=True)
# # print(result)
# result.to_csv('results1.csv')
# import pandas as pd
# import os
# c = []
# for root, dirs, files in os.walk("./Dataset", topdown=False):
# for name in files:
# # print(name)
# L = os.path.join(root, name)
# c.append(L)
# df = pd.DataFrame(c)
# df1 = df[0].str.split("/", expand=True) result = z.drop([0,1,3], axis=1)
# df1.rename({df1.columns[-2]: 'abc'}, axis=1, inplace=True) result.rename({result.columns[-1]: 'test'}, axis=1, inplace=True)
# print('this is df1') # print(result)
# print(df1) result.to_csv('results1.csv')
# df1.rename({df1.columns[-1]: 'test'}, axis=1, inplace=True) import pandas as pd
# merge = pd.merge(df1, result, on='test', how='left') import os
# merge.to_csv('merge.csv') c = []
# mergesplit = merge.loc[:,'test'].str.split(".", expand=True) for root, dirs, files in os.walk(datasetPath, topdown=False):
# mergesplit.rename({mergesplit.columns[-2]: 'ImageName'}, axis=1, inplace=True) for name in files:
# mergesplit = mergesplit.loc[:,'ImageName' ] # print(name)
L = os.path.join(root, name)
c.append(L)
df = pd.DataFrame(c)
#print('seconfdf')
first_column_name = df.columns[0]
# merge.rename({merge.columns[-1]: 'Matched'}, axis=1, inplace=True) # Rename the first column
# merge['EventName'] = merge['abc'] df.rename(columns={first_column_name: 'col'}, inplace=True)
# merge['Imagepath']="/_files/1/Gallery/"+merge['EventName']+'/'+ + merge['test'] print(df)
df1 = df['col'].str.split("/", expand=True)
df1.rename({df1.columns[-2]: 'abc'}, axis=1, inplace=True)
#print('this is df1')
#print(df1)
df1.rename({df1.columns[-1]: 'test'}, axis=1, inplace=True)
merge = pd.merge(df1, result, on='test', how='left')
merge.to_csv('merge.csv')
mergesplit = merge.loc[:,'test'].str.split(".", expand=True)
mergesplit.rename({mergesplit.columns[-2]: 'ImageName'}, axis=1, inplace=True)
mergesplit = mergesplit.loc[:,'ImageName' ]
# frames = [merge, mergesplit] merge.rename({merge.columns[-1]: 'Matched'}, axis=1, inplace=True)
merge['EventName'] = merge['abc']
merge['Imagepath']="/_files/1/Gallery/"+merge['EventName']+'/'+ + merge['test']
# r = pd.concat(frames, axis=1, join='inner') frames = [merge, mergesplit]
# r=r.iloc[:,3:]
# print(r) r = pd.concat(frames, axis=1, join='inner')
# r.to_csv('path.csv', index=False) r=r.iloc[:,3:]
# r.to_json(r'./matched.json', orient="records") #print(r)
r.to_csv('path.csv', index=False)
#r.to_json(r'./matched.json', orient="records")
column_list = ['Matched','Imagepath', 'ImageName', 'EventName']
r[column_list].to_json('matched.json', orient="records")
############################################################################################# #############################################################################################
@@ -477,8 +492,10 @@ def predict():
main() main()
# return render_template('index.html') # return render_template('index.html')
p = './matched.json'
return send_file(p,as_attachment=True)
return 'ALL IMAGES MATCHED' # return 'ALL IMAGES MATCHED'
@app.route('/json') @app.route('/json')
@@ -488,6 +505,6 @@ def json():
if __name__ == "__main__": if __name__ == "__main__":
app.run(host="0.0.0.0",port=8081,debug=True) app.run(host="0.0.0.0",port=8081)