YUNABI/FACE_RECOG
0
1'''
2from deepface import DeepFace
3
4# Function to extract face embedding from an image
5def extract_face_embedding(image_path):
6 # Extracting embeddings using DeepFace
7 embeddings = DeepFace.represent(image_path, model_name="VGG-Face", enforce_detection=False)
8 return embeddings
9
10# Example usage: Capture the embedding of a person's image
11image_path = "C:\\Users\\shrad\\OneDrive\\Documents\\WhatsApp Image 2024-11-25 at 21.42.59_a7cbb9e4.jpg" # Change this to the image you want to use
12embedding = extract_face_embedding(image_path)
13
14# Print the extracted embedding
15print(embedding)
16'''
17
18
19import json
20from deepface import DeepFace
21
22# Function to extract face embedding from an image
23def extract_face_embedding(image_path):
24 # Extract embeddings using DeepFace with the VGG-Face model
25 embeddings = DeepFace.represent(image_path, model_name="VGG-Face", enforce_detection=False)
26 return embeddings
27
28# Function to save all embeddings to a JSON file
29def save_all_embeddings_to_file(embeddings_dict, filename="all_embeddings.json"):
30 # Save the embeddings dictionary into a JSON file
31 with open(filename, "w") as json_file:
32 json.dump(embeddings_dict, json_file, indent=4)
33
34# Function to process multiple images and save embeddings to a single file
35def process_and_save_images(image_paths):
36 # Create an empty dictionary to store embeddings
37 embeddings_dict = {}
38
39 # Process each image and store its embeddings in the dictionary
40 for image_path in image_paths:
41 embeddings = extract_face_embedding(image_path)
42 embeddings_dict[image_path] = embeddings
43
44 # Save the embeddings dictionary to a JSON file
45 save_all_embeddings_to_file(embeddings_dict)
46
47# Example image paths (replace with actual paths to your images)
48image_paths = [
49 "C:\\Users\\shrad\\OneDrive\\Pictures\\Screenshots\\Screenshot 2024-12-03 214111.png",
50 "C:\\Users\\shrad\\OneDrive\\Pictures\\Screenshots\\Screenshot 2024-12-03 214116.png",
51 "C:\\Users\\shrad\\OneDrive\\Pictures\\Screenshots\\Screenshot 2024-12-03 214122.png",
52 "C:\\Users\\shrad\\OneDrive\\Pictures\\Screenshots\\Screenshot 2024-12-03 214130.png",
53 "C:\\Users\\shrad\\OneDrive\\Pictures\\Screenshots\\Screenshot 2024-12-03 214136.png",
54 "C:\\Users\\shrad\\OneDrive\\Pictures\\Screenshots\\Screenshot 2024-12-03 214141.png",
55 "C:\\Users\\shrad\\OneDrive\\Pictures\\Screenshots\\Screenshot 2024-12-03 214151.png",
56 "C:\\Users\\shrad\\OneDrive\\Pictures\\Screenshots\\Screenshot 2024-12-03 214155.png",
57 "C:\\Users\\shrad\\OneDrive\\Pictures\\Screenshots\\Screenshot 2024-12-03 214200.png",
58 "C:\\Users\\shrad\\OneDrive\\Pictures\\Screenshots\\Screenshot 2024-12-03 214211.png"
59]
60
61# Process the images and save all embeddings in a single JSON file
62process_and_save_images(image_paths)
63
64print("All embeddings saved successfully!")
65 