Skip to content

Commit ed27a9f

Browse files
iscai-msftlmazuel
authored andcommitted
[DO NOT MERGE] updated computer vision samples (#32)
updated computer vision samples
1 parent 72c4d65 commit ed27a9f

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ azure-cognitiveservices-search-newssearch
1111
azure-cognitiveservices-search-videosearch
1212
azure-cognitiveservices-search-visualsearch>=0.2.0 # sample won't work with previous versions
1313
azure-cognitiveservices-search-websearch
14-
azure-cognitiveservices-vision-computervision>=0.2.0 # sample won't work with previous versions
14+
azure-cognitiveservices-vision-computervision>=0.3.0 # sample won't work with previous versions
1515
azure-cognitiveservices-vision-contentmoderator>=1.0.0 # sample won't work with previous versions
1616
azure-cognitiveservices-vision-customvision>=0.4.0 # sample won't work with previous versions
1717
azure-cognitiveservices-vision-face

samples/vision/computer_vision_samples.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os.path
22

3-
from azure.cognitiveservices.vision.computervision import ComputerVisionAPI
3+
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
44
from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes
55
from msrest.authentication import CognitiveServicesCredentials
66

@@ -14,11 +14,14 @@ def image_analysis_in_stream(subscription_key):
1414
1515
This will analyze an image from a stream and return all available features.
1616
"""
17-
client = ComputerVisionAPI(COMPUTERVISION_LOCATION, CognitiveServicesCredentials(subscription_key))
17+
client = ComputerVisionClient(
18+
endpoint="https://" + COMPUTERVISION_LOCATION + ".api.cognitive.microsoft.com/",
19+
credentials=CognitiveServicesCredentials(subscription_key)
20+
)
1821

1922
with open(os.path.join(IMAGES_FOLDER, "house.jpg"), "rb") as image_stream:
2023
image_analysis = client.analyze_image_in_stream(
21-
image_stream,
24+
image=image_stream,
2225
visual_features=[
2326
VisualFeatureTypes.image_type, # Could use simple str "ImageType"
2427
VisualFeatureTypes.faces, # Could use simple str "Faces"
@@ -43,11 +46,14 @@ def recognize_text(subscription_key):
4346
This will recognize text of the given image using the recognizeText API.
4447
"""
4548
import time
46-
client = ComputerVisionAPI(COMPUTERVISION_LOCATION, CognitiveServicesCredentials(subscription_key))
49+
client = ComputerVisionClient(
50+
endpoint="https://" + COMPUTERVISION_LOCATION + ".api.cognitive.microsoft.com/",
51+
credentials=CognitiveServicesCredentials(subscription_key)
52+
)
4753

4854
with open(os.path.join(IMAGES_FOLDER, "make_things_happen.jpg"), "rb") as image_stream:
4955
job = client.recognize_text_in_stream(
50-
image_stream,
56+
image=image_stream,
5157
mode="Printed",
5258
raw=True
5359
)
@@ -56,7 +62,7 @@ def recognize_text(subscription_key):
5662
image_analysis = client.get_text_operation_result(operation_id)
5763
while image_analysis.status in ['NotStarted', 'Running']:
5864
time.sleep(1)
59-
image_analysis = client.get_text_operation_result(operation_id)
65+
image_analysis = client.get_text_operation_result(operation_id=operation_id)
6066

6167
print("Job completion is: {}\n".format(image_analysis.status))
6268

@@ -71,12 +77,14 @@ def recognize_printed_text_in_stream(subscription_key):
7177
7278
This will do an OCR analysis of the given image.
7379
"""
74-
import time
75-
client = ComputerVisionAPI(COMPUTERVISION_LOCATION, CognitiveServicesCredentials(subscription_key))
80+
client = ComputerVisionClient(
81+
endpoint="https://" + COMPUTERVISION_LOCATION + ".api.cognitive.microsoft.com/",
82+
credentials=CognitiveServicesCredentials(subscription_key)
83+
)
7684

7785
with open(os.path.join(IMAGES_FOLDER, "computer_vision_ocr.png"), "rb") as image_stream:
7886
image_analysis = client.recognize_printed_text_in_stream(
79-
image_stream,
87+
image=image_stream,
8088
language="en"
8189
)
8290

0 commit comments

Comments
 (0)