diff --git a/python/Face/FaceQuickstart-single.py b/python/Face/FaceQuickstart-single.py index 9859c63d..67a28721 100644 --- a/python/Face/FaceQuickstart-single.py +++ b/python/Face/FaceQuickstart-single.py @@ -1,19 +1,17 @@ # -import asyncio -import io import os import sys import time import uuid -import requests -from urllib.parse import urlparse -from io import BytesIO -# To install this module, run: -# python -m pip install Pillow -from PIL import Image, ImageDraw -from azure.cognitiveservices.vision.face import FaceClient -from msrest.authentication import CognitiveServicesCredentials -from azure.cognitiveservices.vision.face.models import TrainingStatusType, Person, QualityForRecognition + +from azure.core.credentials import AzureKeyCredential +from azure.ai.vision.face import FaceAdministrationClient, FaceClient +from azure.ai.vision.face.models import ( + FaceAttributeTypeRecognition04, + FaceDetectionModel, + FaceRecognitionModel, + QualityForRecognition, +) # This key will serve all examples in this document. @@ -22,139 +20,173 @@ # This endpoint will be used in all examples in this quickstart. ENDPOINT = os.environ["VISION_ENDPOINT"] -# Base url for the Verify and Facelist/Large Facelist operations -IMAGE_BASE_URL = 'https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/' - # Used in the Person Group Operations and Delete Person Group examples. # You can call list_person_groups to print a list of preexisting PersonGroups. # SOURCE_PERSON_GROUP_ID should be all lowercase and alphanumeric. For example, 'mygroupname' (dashes are OK). -PERSON_GROUP_ID = str(uuid.uuid4()) # assign a random ID (or name it anything) - -# Used for the Delete Person Group example. -TARGET_PERSON_GROUP_ID = str(uuid.uuid4()) # assign a random ID (or name it anything) - -# Create an authenticated FaceClient. -face_client = FaceClient(ENDPOINT, CognitiveServicesCredentials(KEY)) - -''' -Create the PersonGroup -''' -# Create empty Person Group. Person Group ID must be lower case, alphanumeric, and/or with '-', '_'. -print('Person group:', PERSON_GROUP_ID) -face_client.person_group.create(person_group_id=PERSON_GROUP_ID, name=PERSON_GROUP_ID, recognition_model='recognition_04') - -# Define woman friend -woman = face_client.person_group_person.create(PERSON_GROUP_ID, name="Woman") -# Define man friend -man = face_client.person_group_person.create(PERSON_GROUP_ID, name="Man") -# Define child friend -child = face_client.person_group_person.create(PERSON_GROUP_ID, name="Child") - -''' -Detect faces and register them to each person -''' -# Find all jpeg images of friends in working directory (TBD pull from web instead) -woman_images = ["https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Mom1.jpg", "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Mom2.jpg"] -man_images = ["https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Dad1.jpg", "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Dad2.jpg"] -child_images = ["https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Son1.jpg", "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Son2.jpg"] - -# Add to woman person -for image in woman_images: - # Check if the image is of sufficent quality for recognition. - sufficientQuality = True - detected_faces = face_client.face.detect_with_url(url=image, detection_model='detection_03', recognition_model='recognition_04', return_face_attributes=['qualityForRecognition']) - for face in detected_faces: - if face.face_attributes.quality_for_recognition != QualityForRecognition.high: - sufficientQuality = False - break - face_client.person_group_person.add_face_from_url(PERSON_GROUP_ID, woman.person_id, image) - print("face {} added to person {}".format(face.face_id, woman.person_id)) - - if not sufficientQuality: continue - -# Add to man person -for image in man_images: - # Check if the image is of sufficent quality for recognition. - sufficientQuality = True - detected_faces = face_client.face.detect_with_url(url=image, detection_model='detection_03', recognition_model='recognition_04', return_face_attributes=['qualityForRecognition']) - for face in detected_faces: - if face.face_attributes.quality_for_recognition != QualityForRecognition.high: - sufficientQuality = False - break - face_client.person_group_person.add_face_from_url(PERSON_GROUP_ID, man.person_id, image) - print("face {} added to person {}".format(face.face_id, man.person_id)) - - if not sufficientQuality: continue - -# Add to child person -for image in child_images: - # Check if the image is of sufficent quality for recognition. - sufficientQuality = True - detected_faces = face_client.face.detect_with_url(url=image, detection_model='detection_03', recognition_model='recognition_04', return_face_attributes=['qualityForRecognition']) - for face in detected_faces: - if face.face_attributes.quality_for_recognition != QualityForRecognition.high: - sufficientQuality = False - print("{} has insufficient quality".format(face)) - break - face_client.person_group_person.add_face_from_url(PERSON_GROUP_ID, child.person_id, image) - print("face {} added to person {}".format(face.face_id, child.person_id)) - if not sufficientQuality: continue - - -''' -Train PersonGroup -''' -# Train the person group -print("pg resource is {}".format(PERSON_GROUP_ID)) -rawresponse = face_client.person_group.train(PERSON_GROUP_ID, raw= True) -print(rawresponse) - -while (True): - training_status = face_client.person_group.get_training_status(PERSON_GROUP_ID) - print("Training status: {}.".format(training_status.status)) +PERSON_GROUP_ID = str(uuid.uuid4()) # assign a random ID (or name it anything) + +# Create an authenticated FaceAdministrationClient and FaceClient. +# FaceAdministrationClient is used for create, update, get, or delete Person Group and Person. Also it can add or +# remove face from a Person. FaceClient is for calling detect, identify and verify. +with FaceAdministrationClient(endpoint=ENDPOINT, credential=AzureKeyCredential(KEY)) as face_admin_client, \ + FaceClient(endpoint=ENDPOINT, credential=AzureKeyCredential(KEY)) as face_client: + ''' + Create the PersonGroup + ''' + # Create empty Person Group. Person Group ID must be lower case, alphanumeric, and/or with '-', '_'. + print('Person group:', PERSON_GROUP_ID) + face_admin_client.create_person_group( + person_group_id=PERSON_GROUP_ID, name=PERSON_GROUP_ID, recognition_model=FaceRecognitionModel.RECOGNITION_04) + + # Define woman friend + woman = face_admin_client.create_person_group_person(PERSON_GROUP_ID, name="Woman") + # Define man friend + man = face_admin_client.create_person_group_person(PERSON_GROUP_ID, name="Man") + # Define child friend + child = face_admin_client.create_person_group_person(PERSON_GROUP_ID, name="Child") + + ''' + Detect faces and register them to each person + ''' + # Find all jpeg images of friends in working directory (TBD pull from web instead) + woman_images = [ + "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Mom1.jpg", # noqa: E501 + "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Mom2.jpg", # noqa: E501 + ] + man_images = [ + "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Dad1.jpg", # noqa: E501 + "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Dad2.jpg", # noqa: E501 + ] + child_images = [ + "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Son1.jpg", # noqa: E501 + "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Son2.jpg", # noqa: E501 + ] + + # Add to woman person + for image in woman_images: + # Check if the image is of sufficent quality for recognition. + sufficientQuality = True + detected_faces = face_client.detect_from_url( + url=image, + detection_model=FaceDetectionModel.DETECTION_03, + recognition_model=FaceRecognitionModel.RECOGNITION_04, + return_face_id=True, + return_face_attributes=[FaceAttributeTypeRecognition04.QUALITY_FOR_RECOGNITION]) + for face in detected_faces: + if face.face_attributes.quality_for_recognition != QualityForRecognition.HIGH: + sufficientQuality = False + break + face_admin_client.add_person_group_person_face_from_url(PERSON_GROUP_ID, woman.person_id, url=image) + print(f"face {face.face_id} added to person {woman.person_id}") + + if not sufficientQuality: + continue + + # Add to man person + for image in man_images: + # Check if the image is of sufficent quality for recognition. + sufficientQuality = True + detected_faces = face_client.detect_from_url( + url=image, + detection_model=FaceDetectionModel.DETECTION_03, + recognition_model=FaceRecognitionModel.RECOGNITION_04, + return_face_id=True, + return_face_attributes=[FaceAttributeTypeRecognition04.QUALITY_FOR_RECOGNITION]) + for face in detected_faces: + if face.face_attributes.quality_for_recognition != QualityForRecognition.HIGH: + sufficientQuality = False + break + face_admin_client.add_person_group_person_face_from_url(PERSON_GROUP_ID, man.person_id, url=image) + print(f"face {face.face_id} added to person {man.person_id}") + + if not sufficientQuality: + continue + + # Add to child person + for image in child_images: + # Check if the image is of sufficent quality for recognition. + sufficientQuality = True + detected_faces = face_client.detect_from_url( + url=image, + detection_model=FaceDetectionModel.DETECTION_03, + recognition_model=FaceRecognitionModel.RECOGNITION_04, + return_face_id=True, + return_face_attributes=[FaceAttributeTypeRecognition04.QUALITY_FOR_RECOGNITION]) + for face in detected_faces: + if face.face_attributes.quality_for_recognition != QualityForRecognition.HIGH: + sufficientQuality = False + print("{} has insufficient quality".format(face)) + break + face_admin_client.add_person_group_person_face_from_url(PERSON_GROUP_ID, child.person_id, url=image) + print(f"face {face.face_id} added to person {child.person_id}") + + if not sufficientQuality: + continue + + ''' + Train PersonGroup + ''' + # Train the person group + print(f"Train the person group {PERSON_GROUP_ID}") + try: + poller = face_admin_client.begin_train_person_group(PERSON_GROUP_ID, polling_interval=30) + poller.wait() # Keep polling until the "Train" operation completes. + except Exception as error: + face_admin_client.delete_person_group(person_group_id=PERSON_GROUP_ID) + sys.exit(f"Training the person group has failed. Error: {error}") + print(f"The person group {PERSON_GROUP_ID} is trained successfully.") + + ''' + Identify a face against a defined PersonGroup + ''' + # Group image for testing against + test_image = "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/identification1.jpg" # noqa: E501 + + print("Pausing for 10 seconds to avoid triggering rate limit on free account...") + time.sleep(10) + + # Detect faces + face_ids = [] + # We use detection model 03 to get better performance, recognition model 04 to support quality for + # recognition attribute. + faces = face_client.detect_from_url( + url=test_image, + detection_model=FaceDetectionModel.DETECTION_03, + recognition_model=FaceRecognitionModel.RECOGNITION_04, + return_face_id=True, + return_face_attributes=[FaceAttributeTypeRecognition04.QUALITY_FOR_RECOGNITION]) + for face in faces: + # Only take the face if it is of sufficient quality. + if face.face_attributes.quality_for_recognition == QualityForRecognition.HIGH or \ + face.face_attributes.quality_for_recognition == QualityForRecognition.MEDIUM: + face_ids.append(face.face_id) + + # Identify faces + results = face_client.identify_from_person_group(face_ids=face_ids, person_group_id=PERSON_GROUP_ID) + print("Identifying faces in image") + if not results: + print("No person identified in the person group") + for identifiedFace in results: + if len(identifiedFace.candidates) > 0: + print(f"Person is identified for face ID {identifiedFace.face_id} in image, with a confidence of " + f"{identifiedFace.candidates[0].confidence}.") # Get topmost confidence score + + # Verify faces + verify_result = face_client.verify_from_person_group( + face_id=identifiedFace.face_id, + person_group_id=PERSON_GROUP_ID, + person_id=identifiedFace.candidates[0].person_id) + print(f"verification result: {verify_result.is_identical}. confidence: {verify_result.confidence}") + else: + print(f"No person identified for face ID {identifiedFace.face_id} in image.") + print() - if (training_status.status is TrainingStatusType.succeeded): - break - elif (training_status.status is TrainingStatusType.failed): - face_client.person_group.delete(person_group_id=PERSON_GROUP_ID) - sys.exit('Training the person group has failed.') - time.sleep(5) - -''' -Identify a face against a defined PersonGroup -''' -# Group image for testing against -test_image = "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/identification1.jpg" - -print('Pausing for 10 seconds to avoid triggering rate limit on free account...') -time.sleep (10) - -# Detect faces -face_ids = [] -# We use detection model 3 to get better performance, recognition model 4 to support quality for recognition attribute. -faces = face_client.face.detect_with_url(test_image, detection_model='detection_03', recognition_model='recognition_04', return_face_attributes=['qualityForRecognition']) -for face in faces: - # Only take the face if it is of sufficient quality. - if face.face_attributes.quality_for_recognition == QualityForRecognition.high or face.face_attributes.quality_for_recognition == QualityForRecognition.medium: - face_ids.append(face.face_id) - -# Identify faces -results = face_client.face.identify(face_ids, PERSON_GROUP_ID) -print('Identifying faces in image') -if not results: - print('No person identified in the person group') -for identifiedFace in results: - if len(identifiedFace.candidates) > 0: - print('Person is identified for face ID {} in image, with a confidence of {}.'.format(identifiedFace.face_id, identifiedFace.candidates[0].confidence)) # Get topmost confidence score - - # Verify faces - verify_result = face_client.face.verify_face_to_person(identifiedFace.face_id, identifiedFace.candidates[0].person_id, PERSON_GROUP_ID) - print('verification result: {}. confidence: {}'.format(verify_result.is_identical, verify_result.confidence)) - else: - print('No person identified for face ID {} in image.'.format(identifiedFace.face_id)) - - -print() -print('End of quickstart.') - -# \ No newline at end of file + + # Delete the person group + face_admin_client.delete_person_group(person_group_id=PERSON_GROUP_ID) + print(f"The person group {PERSON_GROUP_ID} is deleted.") + + print() + print("End of quickstart.") + +# diff --git a/python/Face/README.md b/python/Face/README.md index 36d50022..e91bf50e 100644 --- a/python/Face/README.md +++ b/python/Face/README.md @@ -1,24 +1,18 @@ # Face quickstart and examples -This quickstart and example use the [Face SDK](https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-face/?view=azure-python) for Cognitive Services. +This quickstart and example use the [Azure Ai Vision Face SDK](https://learn.microsoft.com/en-us/python/api/overview/azure/ai-vision-face-readme?view=azure-python). ## Prerequisites - - Python 3+ - - Install Face SDK: pip install azure-cognitiveservices-vision-face - -### Images - - To your root folder, add all images downloaded mentioned in the quickstart. - - For the DetectIdentifyFace example, download all "woman" and "child" images. - - https://github.com/Azure-examples/cognitive-services-sample-data-files/tree/master/Face/images - + - Python 3.8+ + - Install Face SDK: python -m pip install azure-ai-vision-face + - Please refer to [SDK source code](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/face/azure-ai-vision-face) to get more information. + ## Run - Run from your favorite IDE, or using this from the command line: - - python FaceQuickstart.py - python DetectIdentifyFace.py - + + python FaceQuickstart-single.py + ## References - - Documentation: https://docs.microsoft.com/en-us/azure/cognitive-services/face/ - - SDK: https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-face/azure.cognitiveservices.vision.face?view=azure-python - - All Face APIs: https://docs.microsoft.com/en-us/azure/cognitive-services/face/APIReference + - Documentation: https://learn.microsoft.com/en-us/azure/ai-services/computer-vision/overview-identity + - SDK: https://learn.microsoft.com/en-us/python/api/overview/azure/ai-vision-face-readme?view=azure-python + - All Face APIs: https://learn.microsoft.com/en-us/azure/ai-services/computer-vision/identity-api-reference diff --git a/python/Face/DetectFaceAttributes.py b/python/Face/cognitiveservices-sdk/DetectFaceAttributes.py similarity index 100% rename from python/Face/DetectFaceAttributes.py rename to python/Face/cognitiveservices-sdk/DetectFaceAttributes.py diff --git a/python/Face/DetectIdentifyFace.py b/python/Face/cognitiveservices-sdk/DetectIdentifyFace.py similarity index 100% rename from python/Face/DetectIdentifyFace.py rename to python/Face/cognitiveservices-sdk/DetectIdentifyFace.py diff --git a/python/Face/cognitiveservices-sdk/FaceQuickstart-single.py b/python/Face/cognitiveservices-sdk/FaceQuickstart-single.py new file mode 100644 index 00000000..9859c63d --- /dev/null +++ b/python/Face/cognitiveservices-sdk/FaceQuickstart-single.py @@ -0,0 +1,160 @@ +# +import asyncio +import io +import os +import sys +import time +import uuid +import requests +from urllib.parse import urlparse +from io import BytesIO +# To install this module, run: +# python -m pip install Pillow +from PIL import Image, ImageDraw +from azure.cognitiveservices.vision.face import FaceClient +from msrest.authentication import CognitiveServicesCredentials +from azure.cognitiveservices.vision.face.models import TrainingStatusType, Person, QualityForRecognition + + +# This key will serve all examples in this document. +KEY = os.environ["VISION_KEY"] + +# This endpoint will be used in all examples in this quickstart. +ENDPOINT = os.environ["VISION_ENDPOINT"] + +# Base url for the Verify and Facelist/Large Facelist operations +IMAGE_BASE_URL = 'https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/' + +# Used in the Person Group Operations and Delete Person Group examples. +# You can call list_person_groups to print a list of preexisting PersonGroups. +# SOURCE_PERSON_GROUP_ID should be all lowercase and alphanumeric. For example, 'mygroupname' (dashes are OK). +PERSON_GROUP_ID = str(uuid.uuid4()) # assign a random ID (or name it anything) + +# Used for the Delete Person Group example. +TARGET_PERSON_GROUP_ID = str(uuid.uuid4()) # assign a random ID (or name it anything) + +# Create an authenticated FaceClient. +face_client = FaceClient(ENDPOINT, CognitiveServicesCredentials(KEY)) + +''' +Create the PersonGroup +''' +# Create empty Person Group. Person Group ID must be lower case, alphanumeric, and/or with '-', '_'. +print('Person group:', PERSON_GROUP_ID) +face_client.person_group.create(person_group_id=PERSON_GROUP_ID, name=PERSON_GROUP_ID, recognition_model='recognition_04') + +# Define woman friend +woman = face_client.person_group_person.create(PERSON_GROUP_ID, name="Woman") +# Define man friend +man = face_client.person_group_person.create(PERSON_GROUP_ID, name="Man") +# Define child friend +child = face_client.person_group_person.create(PERSON_GROUP_ID, name="Child") + +''' +Detect faces and register them to each person +''' +# Find all jpeg images of friends in working directory (TBD pull from web instead) +woman_images = ["https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Mom1.jpg", "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Mom2.jpg"] +man_images = ["https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Dad1.jpg", "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Dad2.jpg"] +child_images = ["https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Son1.jpg", "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/Family1-Son2.jpg"] + +# Add to woman person +for image in woman_images: + # Check if the image is of sufficent quality for recognition. + sufficientQuality = True + detected_faces = face_client.face.detect_with_url(url=image, detection_model='detection_03', recognition_model='recognition_04', return_face_attributes=['qualityForRecognition']) + for face in detected_faces: + if face.face_attributes.quality_for_recognition != QualityForRecognition.high: + sufficientQuality = False + break + face_client.person_group_person.add_face_from_url(PERSON_GROUP_ID, woman.person_id, image) + print("face {} added to person {}".format(face.face_id, woman.person_id)) + + if not sufficientQuality: continue + +# Add to man person +for image in man_images: + # Check if the image is of sufficent quality for recognition. + sufficientQuality = True + detected_faces = face_client.face.detect_with_url(url=image, detection_model='detection_03', recognition_model='recognition_04', return_face_attributes=['qualityForRecognition']) + for face in detected_faces: + if face.face_attributes.quality_for_recognition != QualityForRecognition.high: + sufficientQuality = False + break + face_client.person_group_person.add_face_from_url(PERSON_GROUP_ID, man.person_id, image) + print("face {} added to person {}".format(face.face_id, man.person_id)) + + if not sufficientQuality: continue + +# Add to child person +for image in child_images: + # Check if the image is of sufficent quality for recognition. + sufficientQuality = True + detected_faces = face_client.face.detect_with_url(url=image, detection_model='detection_03', recognition_model='recognition_04', return_face_attributes=['qualityForRecognition']) + for face in detected_faces: + if face.face_attributes.quality_for_recognition != QualityForRecognition.high: + sufficientQuality = False + print("{} has insufficient quality".format(face)) + break + face_client.person_group_person.add_face_from_url(PERSON_GROUP_ID, child.person_id, image) + print("face {} added to person {}".format(face.face_id, child.person_id)) + if not sufficientQuality: continue + + +''' +Train PersonGroup +''' +# Train the person group +print("pg resource is {}".format(PERSON_GROUP_ID)) +rawresponse = face_client.person_group.train(PERSON_GROUP_ID, raw= True) +print(rawresponse) + +while (True): + training_status = face_client.person_group.get_training_status(PERSON_GROUP_ID) + print("Training status: {}.".format(training_status.status)) + print() + if (training_status.status is TrainingStatusType.succeeded): + break + elif (training_status.status is TrainingStatusType.failed): + face_client.person_group.delete(person_group_id=PERSON_GROUP_ID) + sys.exit('Training the person group has failed.') + time.sleep(5) + +''' +Identify a face against a defined PersonGroup +''' +# Group image for testing against +test_image = "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/identification1.jpg" + +print('Pausing for 10 seconds to avoid triggering rate limit on free account...') +time.sleep (10) + +# Detect faces +face_ids = [] +# We use detection model 3 to get better performance, recognition model 4 to support quality for recognition attribute. +faces = face_client.face.detect_with_url(test_image, detection_model='detection_03', recognition_model='recognition_04', return_face_attributes=['qualityForRecognition']) +for face in faces: + # Only take the face if it is of sufficient quality. + if face.face_attributes.quality_for_recognition == QualityForRecognition.high or face.face_attributes.quality_for_recognition == QualityForRecognition.medium: + face_ids.append(face.face_id) + +# Identify faces +results = face_client.face.identify(face_ids, PERSON_GROUP_ID) +print('Identifying faces in image') +if not results: + print('No person identified in the person group') +for identifiedFace in results: + if len(identifiedFace.candidates) > 0: + print('Person is identified for face ID {} in image, with a confidence of {}.'.format(identifiedFace.face_id, identifiedFace.candidates[0].confidence)) # Get topmost confidence score + + # Verify faces + verify_result = face_client.face.verify_face_to_person(identifiedFace.face_id, identifiedFace.candidates[0].person_id, PERSON_GROUP_ID) + print('verification result: {}. confidence: {}'.format(verify_result.is_identical, verify_result.confidence)) + else: + print('No person identified for face ID {} in image.'.format(identifiedFace.face_id)) + + +print() +print('End of quickstart.') + +# \ No newline at end of file diff --git a/python/Face/FaceQuickstart.py b/python/Face/cognitiveservices-sdk/FaceQuickstart.py similarity index 100% rename from python/Face/FaceQuickstart.py rename to python/Face/cognitiveservices-sdk/FaceQuickstart.py diff --git a/python/Face/cognitiveservices-sdk/README.md b/python/Face/cognitiveservices-sdk/README.md new file mode 100644 index 00000000..36d50022 --- /dev/null +++ b/python/Face/cognitiveservices-sdk/README.md @@ -0,0 +1,24 @@ +# Face quickstart and examples + +This quickstart and example use the [Face SDK](https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-face/?view=azure-python) for Cognitive Services. + +## Prerequisites + - Python 3+ + - Install Face SDK: pip install azure-cognitiveservices-vision-face + +### Images + - To your root folder, add all images downloaded mentioned in the quickstart. + - For the DetectIdentifyFace example, download all "woman" and "child" images. + + https://github.com/Azure-examples/cognitive-services-sample-data-files/tree/master/Face/images + +## Run + - Run from your favorite IDE, or using this from the command line: + + python FaceQuickstart.py + python DetectIdentifyFace.py + +## References + - Documentation: https://docs.microsoft.com/en-us/azure/cognitive-services/face/ + - SDK: https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-face/azure.cognitiveservices.vision.face?view=azure-python + - All Face APIs: https://docs.microsoft.com/en-us/azure/cognitive-services/face/APIReference