Skip to content

Commit 43bf5f0

Browse files
authored
Updated structure and libraries
1 parent 59f82cc commit 43bf5f0

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

python/Vision/ComputerVision2.1.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,38 @@
22
# Licensed under the MIT License.
33

44
import json
5-
import os
6-
from pprint import pprint
75
import requests
6+
import os
7+
from pprint import pprint
88

99
'''
10-
This sample makes a call to the Computer Vision API with a URL image query to analyze an image,
11-
and then returns user input parameter data like category, description, and color.
12-
API: https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/587f2c6a154055056008f200
10+
This sample makes a call to the Face API with a URL image query
11+
to detect faces and features in an image.
12+
Face API: https://westus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236
1313
'''
1414

15-
# Add your Computer Vision subscription key and endpoint to your environment variables.
16-
subscription_key = os.environ['COMPUTER_VISION_SUBSCRIPTION_KEY']
17-
endpoint = os.environ['COMPUTER_VISION_ENDPOINT'] + "/vision/v2.1/analyze"
15+
# Add your Face subscription key and endpoint to your environment variables.
16+
subscription_key = os.environ['FACE_SUBSCRIPTION_KEY']
17+
endpoint = os.environ['FACE_ENDPOINT'] + '/face/v1.0/detect'
1818

1919
# Request headers.
2020
headers = {
2121
'Content-Type': 'application/json',
2222
'Ocp-Apim-Subscription-Key': subscription_key,
2323
}
2424

25-
# Request parameters. All of them are optional.
25+
# Request parameters.
2626
params = {
27-
'visualFeatures': 'Categories,Description,Color',
28-
'language': 'en',
27+
'returnFaceId': 'true',
28+
'returnFaceLandmarks': 'false',
29+
'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',
2930
}
3031

31-
# Any image with objects will work.
32-
body = {'url': 'https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/ComputerVision/Images/objects.jpg'}
32+
# The URL of a JPEG image of faces to analyze.
33+
body = {'url': 'https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/test-image-person-group.jpg'}
3334

34-
# Call the API.
3535
try:
36+
# Call API.
3637
response = requests.post(endpoint, headers=headers, params=params, json=body)
3738
response.raise_for_status()
3839

@@ -41,5 +42,7 @@
4142

4243
print("\nJSON Response:\n")
4344
pprint(response.json())
44-
except Exception as ex:
45-
raise ex
45+
46+
except Exception as e:
47+
print('Error:')
48+
print(e)

0 commit comments

Comments
 (0)