Jun-24-2019, 07:38 AM
Hi,
I have below python code for face_recognition.basically it is comparing two images and providing match or not.I am getting output in json format as below.How to parse this json output to normal text or storing into a variable and display the out like thanks in advance for your response
present output:
{
"Not matched": [],
"Matched": [
[
"anil1_kZJfP0k.JPG",
{
"Matching Percentage": "68.59"
}
]
]
}
Expected output:
instead of all the brackets simple text output like:
response ={matched}
matching percentage ={68%}
I have below python code for face_recognition.basically it is comparing two images and providing match or not.I am getting output in json format as below.How to parse this json output to normal text or storing into a variable and display the out like thanks in advance for your response
present output:
{
"Not matched": [],
"Matched": [
[
"anil1_kZJfP0k.JPG",
{
"Matching Percentage": "68.59"
}
]
]
}
Expected output:
instead of all the brackets simple text output like:
response ={matched}
matching percentage ={68%}
import face_recognition import os def match(lis, img): images = lis image_to_be_matched = face_recognition.load_image_file(img) # encoded the loaded image into a feature vector image_to_be_matched_encoded = face_recognition.face_encodings( image_to_be_matched)[0] # iterate over each image resp = {"Matched": [], "Not matched": []} for image in images: print(images) #image = os.path.join(path, image) current_image = face_recognition.load_image_file(image) # encode the loaded image into a feature vector current_image_encoded = face_recognition.face_encodings(current_image)[0] # match your image with the image and check if it matches result = face_recognition.compare_faces( [image_to_be_matched_encoded], current_image_encoded) # check if it was a match face_distances = face_recognition.face_distance([image_to_be_matched_encoded], current_image_encoded) if result[0] == True: resp["Matched"].append([os.path.basename(image), {'Matching Percentage': str((1-face_distances[0])*100)[:5]}]) else: resp["Not matched"].append([os.path.basename(image), {'Matching Percentage': str((1-face_distances[0])*100)[:5]}]) for image in images: os.remove(image) os.remove(img) print(resp) return resp