Skip to content

Commit 43f33d3

Browse files
authored
Minor
1 parent 43bf5f0 commit 43f33d3

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

python/Vision/ComputerVision2.1.py

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

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

99
'''
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
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
1313
'''
1414

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'
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"
1818

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

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

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'}
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'}
3433

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

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

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

0 commit comments

Comments
 (0)