11import os .path
22
3- from azure .cognitiveservices .vision .computervision import ComputerVisionAPI
3+ from azure .cognitiveservices .vision .computervision import ComputerVisionClient
44from azure .cognitiveservices .vision .computervision .models import VisualFeatureTypes
55from 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