1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
from azure.cognitiveservices.vision.face import FaceClient from msrest.authentication import CognitiveServicesCredentials import os class colors: green = '\033[92m' blue = '\033[94m' red = '\033[31m' yellow = '\033[33m' reset = '\033[0m' # Paste your endpoint and key below cog_endpoint = "https://westus.api.cognitive.microsoft.com/" cog_key = "fdfsdfdsfsdfsdfsdfdsf" face_client = FaceClient(cog_endpoint, CognitiveServicesCredentials(cog_key)) # Change the URL between the quotes below to run your own faces through the Azure Face Service! #face_to_analyze = "https://raw.githubusercontent.com/pluralsight-cloud/AI-900-Artificial-Intelligence-Workloads-and-Considerations/main/images/image-analysis/2-azureface-couple.jpg" face_to_analyze = "https://gd-hbimg.huaban.com/afdf6ae71a2aae825ed9ebb9d1157f3dee5fa6c9c2cea-YszQ1F_fw1200webp" detected_faces = face_client.face.detect_with_url(url=face_to_analyze, return_face_attributes=list(['headPose','glasses','accessories','blur','noise','occlusion']), return_face_landmarks=True, return_face_id=False) if not detected_faces: print("No faces were found in the image! Please try another image!") input("Press Enter to exit") quit() print("\n-----Facial Attributes-----") for count, face in enumerate(detected_faces): print() print(f"{colors.green}\nPerson Number: {colors.reset}" + str(count)) for acc in face.face_attributes.accessories: print(f"{colors.red}\nAccessories: {colors.reset}" + str(acc)) print(f"{colors.yellow}\nGlasses: {colors.reset}" + str(face.face_attributes.glasses)) print(f"{colors.blue}\nBlur: {colors.reset}" + str(face.face_attributes.blur.blur_level)) print(f"{colors.green}\nOcclusion: {colors.reset}" + str(face.face_attributes.occlusion)) print(f"{colors.red}\nNoise Level: {colors.reset}" + str(face.face_attributes.noise.noise_level)) print("\n----------\n") input("\nPress Enter to Exit...") |
检测结果:
-----Facial Attributes-----
Person Number: 0
Glasses: GlassesType.no_glasses
Blur: BlurLevel.low
Occlusion: {'additional_properties': {}, 'forehead_occluded': False, 'eye_occluded': False, 'mouth_occluded': False}
Noise Level: NoiseLevel.low
Person Number: 1
Glasses: GlassesType.no_glasses
Blur: BlurLevel.low
Occlusion: {'additional_properties': {}, 'forehead_occluded': False, 'eye_occluded': False, 'mouth_occluded': False}
Noise Level: NoiseLevel.high
Person Number: 2
Glasses: GlassesType.no_glasses
Blur: BlurLevel.low
Occlusion: {'additional_properties': {}, 'forehead_occluded': False, 'eye_occluded': False, 'mouth_occluded': False}
Noise Level: NoiseLevel.low
Person Number: 3
Accessories: {'additional_properties': {}, 'type': <AccessoryType.glasses: 'glasses'>, 'confidence': 1.0}
Glasses: GlassesType.reading_glasses
Blur: BlurLevel.low
Occlusion: {'additional_properties': {}, 'forehead_occluded': False, 'eye_occluded': False, 'mouth_occluded': False}
Noise Level: NoiseLevel.low
Person Number: 4
Glasses: GlassesType.no_glasses
Blur: BlurLevel.low
Occlusion: {'additional_properties': {}, 'forehead_occluded': False, 'eye_occluded': False, 'mouth_occluded': False}
Noise Level: NoiseLevel.medium
Person Number: 5
Accessories: {'additional_properties': {}, 'type': <AccessoryType.head_wear: 'headWear'>, 'confidence': 0.98}
Glasses: GlassesType.no_glasses
Blur: BlurLevel.medium
Occlusion: {'additional_properties': {}, 'forehead_occluded': True, 'eye_occluded': False, 'mouth_occluded': False}
Noise Level: NoiseLevel.low
文章评论