diff --git a/data/face/enrollment_data/Mary/Family1-Daughter3.jpg b/data/face/enrollment_data/Mary/Family1-Daughter3.jpg new file mode 100644 index 0000000..974faf3 --- /dev/null +++ b/data/face/enrollment_data/Mary/Family1-Daughter3.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e997410b13cf07ff8bd98dc620acad7d8c98ee85701405526619a58967edcd33 +size 18559 diff --git a/data/face/enrollment_data/Bill/Family1-Dad3.jpg b/data/face/new_face_image.jpg similarity index 100% rename from data/face/enrollment_data/Bill/Family1-Dad3.jpg rename to data/face/new_face_image.jpg diff --git a/notebooks/build_person_directory.ipynb b/notebooks/build_person_directory.ipynb index 4840de4..aec576f 100644 --- a/notebooks/build_person_directory.ipynb +++ b/notebooks/build_person_directory.ipynb @@ -98,6 +98,9 @@ "client.create_person_directory(person_directory_id)\n", "logging.info(f\"Created person directory with ID: {person_directory_id}\")\n", "\n", + "# Initialize persons list\n", + "persons: list = []\n", + "\n", "# Iterate through all subfolders in the folder_path\n", "for subfolder_name in os.listdir(folder_path):\n", " subfolder_path = os.path.join(folder_path, subfolder_name)\n", @@ -107,6 +110,12 @@ " person = client.add_person(person_directory_id, tags={\"name\": person_name})\n", " logging.info(f\"Created person {person_name} with person_id: {person['personId']}\")\n", " if person:\n", + " # Initialize person entry in persons list\n", + " person_entry = {\n", + " 'personId': person['personId'],\n", + " 'name': person_name,\n", + " 'faceIds': []\n", + " }\n", " # Iterate through all images in the subfolder\n", " for filename in os.listdir(subfolder_path):\n", " if filename.lower().endswith(('.png', '.jpg', '.jpeg')):\n", @@ -116,11 +125,19 @@ " # Add a face to the Person Directory and associate it to the added person\n", " face = client.add_face(person_directory_id, image_data, person['personId'])\n", " if face:\n", + " # Add face ID to the person's faceIds list\n", + " person_entry['faceIds'].append(face['faceId'])\n", " logging.info(f\"Added face from {filename} with face_id: {face['faceId']} to person_id: {person['personId']}\")\n", " else:\n", " logging.warning(f\"Failed to add face from {filename} to person_id: {person['personId']}\")\n", "\n", - "logging.info(\"Done\")" + " # Add person entry to persons list\n", + " persons.append(person_entry)\n", + "\n", + "logging.info(\"Done\")\n", + "logging.info(f\"Created {len(persons)} persons:\")\n", + "for person in persons:\n", + " logging.info(f\"Person: {person['name']} (ID: {person['personId']}) with {len(person['faceIds'])} faces\")" ] }, { @@ -170,8 +187,9 @@ "metadata": {}, "outputs": [], "source": [ - "new_face_image_path = \"new_face_image_path\" # The path to the face image you want to add.\n", - "existing_person_id = \"existing_person_id\" # The unique ID of the person to whom the face should be associated.\n", + "person_bill = next(person for person in persons if person['name'] == 'Bill')\n", + "new_face_image_path = \"../data/face/new_face_image.jpg\" # The path to the face image you want to add.\n", + "existing_person_id = person_bill['personId'] # The unique ID of the person to whom the face should be associated.\n", "\n", "# Convert the new face image to base64\n", "image_data = AzureContentUnderstandingFaceClient.read_file_to_base64(new_face_image_path)\n", @@ -200,8 +218,8 @@ "metadata": {}, "outputs": [], "source": [ - "existing_person_id = \"existing_person_id\" # The unique ID of the person to whom the face should be associated.\n", - "existing_face_id_list = [\"existing_face_id_1\", \"existing_face_id_2\"] # The list of face IDs to be associated.\n", + "existing_person_id = person_bill['personId'] # The unique ID of the person to whom the face should be associated.\n", + "existing_face_id_list = person_bill['faceIds'] # The list of face IDs to be associated.\n", "\n", "# Associate the existing face IDs with the existing person\n", "client.update_person(person_directory_id, existing_person_id, face_ids=existing_face_id_list)" @@ -223,7 +241,8 @@ "metadata": {}, "outputs": [], "source": [ - "existing_face_id = \"existing_face_id\" # The unique ID of the face.\n", + "person_mary = next(person for person in persons if person['name'] == 'Mary')\n", + "existing_face_id = person_mary['faceIds'][0] # The unique ID of the face.\n", "\n", "# Remove the association of the existing face ID from the person\n", "client.update_face(person_directory_id, existing_face_id, person_id=\"\") # The person_id is set to \"\" to remove the association\n", @@ -231,7 +250,8 @@ "logging.info(client.get_face(person_directory_id, existing_face_id)) # This will return the face information without the person association\n", "\n", "# Associate the existing face ID with a person\n", - "existing_person_id = \"existing_person_id\" # The unique ID of the person to be associated with the face.\n", + "person_jordan = next(person for person in persons if person['name'] == 'Jordan')\n", + "existing_person_id = person_jordan['personId'] # The unique ID of the person to be associated with the face.\n", "client.update_face(person_directory_id, existing_face_id, person_id=existing_person_id)\n", "logging.info(f\"Associated face_id: {existing_face_id} with person_id: {existing_person_id}\")\n", "logging.info(client.get_face(person_directory_id, existing_face_id)) # This will return the face information with the new person association" @@ -266,7 +286,7 @@ "logging.info(client.get_person_directory(person_directory_id)) # This will return the updated person directory information\n", "\n", "# Update the tags for an individual person\n", - "existing_person_id = \"existing_person_id\" # The unique ID of the person to update.\n", + "existing_person_id = person_bill['personId'] # The unique ID of the person to update.\n", "person_tags = {\"role\": \"tester\", \"department\": \"engineering\", \"name\": \"\"} # This will remove the name tag from the person.\n", "\n", "client.update_person(\n", @@ -294,7 +314,7 @@ "metadata": {}, "outputs": [], "source": [ - "existing_face_id = \"existing_face_id\" # The unique ID of the face to delete.\n", + "existing_face_id = person_mary['faceIds'][0] # The unique ID of the face to delete.\n", "\n", "client.delete_face(person_directory_id, existing_face_id)\n", "logging.info(f\"Deleted face with face_id: {existing_face_id}\")" @@ -317,7 +337,7 @@ "metadata": {}, "outputs": [], "source": [ - "existing_person_id = \"existing_person_id\" # The unique ID of the person to delete.\n", + "existing_person_id = person_mary['personId'] # The unique ID of the person to delete.\n", "\n", "client.delete_person(person_directory_id, existing_person_id)\n", "logging.info(f\"Deleted person with person_id: {existing_person_id}\")" @@ -340,7 +360,7 @@ "metadata": {}, "outputs": [], "source": [ - "existing_person_id = \"existing_person_id\" # The unique ID of the person to delete.\n", + "existing_person_id = person_bill['personId'] # The unique ID of the person to delete.\n", "\n", "# Get the list of face IDs associated with the person\n", "response = client.get_person(person_directory_id, existing_person_id)\n", @@ -373,7 +393,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.12" + "version": "3.13.7" } }, "nbformat": 4,