Class: Azure::CognitiveServices::ComputerVision::V2_1::ComputerVisionClient

Inherits:
MsRestAzure::AzureServiceClient
  • Object
show all
Includes:
MsRestAzure, MsRestAzure::Serialization
Defined in:
lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb

Overview

A service client - single point of access to the REST API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credentials = nil, options = nil) ⇒ ComputerVisionClient

Creates initializes a new instance of the ComputerVisionClient class.

Parameters:

  • credentials (MsRest::ServiceClientCredentials) (defaults to: nil)

    credentials to authorize HTTP requests made by the service client.

  • options (Array) (defaults to: nil)

    filters to be applied to the HTTP requests.



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 44

def initialize(credentials = nil, options = nil)
  super(credentials, options)
  @base_url = '{Endpoint}/vision/v2.1'

  fail ArgumentError, 'invalid type of credentials input parameter' unless credentials.is_a?(MsRest::ServiceClientCredentials) unless credentials.nil?
  @credentials = credentials

  @accept_language = 'en-US'
  @long_running_operation_retry_timeout = 30
  @generate_client_request_id = true
  add_telemetry
end

Instance Attribute Details

#accept_languageString

Returns The preferred language for the response.

Returns:

  • (String)

    The preferred language for the response.



28
29
30
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 28

def accept_language
  @accept_language
end

#base_urlString (readonly)

Returns the base URI of the service.

Returns:

  • (String)

    the base URI of the service.



15
16
17
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 15

def base_url
  @base_url
end

#credentialsObject

subscription.

Returns:

  • Subscription credentials which uniquely identify client



25
26
27
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 25

def credentials
  @credentials
end

#credentials1Object (readonly)

Returns Credentials needed for the client to connect to Azure.

Returns:

  • Credentials needed for the client to connect to Azure.



18
19
20
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 18

def credentials1
  @credentials1
end

#endpointString

Returns Supported Cognitive Services endpoints.

Returns:

  • (String)

    Supported Cognitive Services endpoints.



21
22
23
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 21

def endpoint
  @endpoint
end

#generate_client_request_idBoolean

generated. When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true.

Returns:

  • (Boolean)

    Whether a unique x-ms-client-request-id should be



37
38
39
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 37

def generate_client_request_id
  @generate_client_request_id
end

#long_running_operation_retry_timeoutInteger

Operations. Default value is 30.

Returns:

  • (Integer)

    The retry timeout in seconds for Long Running



32
33
34
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 32

def long_running_operation_retry_timeout
  @long_running_operation_retry_timeout
end

Instance Method Details

#analyze_image(url, visual_features: nil, details: nil, language: nil, description_exclude: nil, custom_headers: nil) ⇒ ImageAnalysis

This operation extracts a rich set of visual features based on the image content. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. Within your request, there is an optional parameter to allow you to choose which features to return. By default, image categories are returned in the response. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

visual feature types to return. Multiple values should be comma-separated. Valid visual feature types include: Categories - categorizes image content according to a taxonomy defined in documentation. Tags - tags the image with a detailed list of words related to the image content. Description - describes the image content with a complete English sentence. Faces - detects if faces are present. If present, generate coordinates, gender and age. ImageType - detects if image is clipart or a line drawing. Color - determines the accent color, dominant color, and whether an image is black&white. Adult

  • detects if the image is pornographic in nature (depicts nudity or a sex

act), or is gory (depicts extreme violence or blood). Sexually suggestive content (aka racy content) is also detected. Objects - detects various objects within an image, including the approximate location. The Objects argument is only available in English. Brands - detects various brands within an image, including the approximate location. The Brands argument is only available in English. details to return. Multiple values should be comma-separated. Valid visual feature types include: Celebrities - identifies celebrities if detected in the image, Landmarks - identifies notable landmarks in the image. parameter is not specified, the default value is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ domain models when generating the description. will be added to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • visual_features (Array<VisualFeatureTypes>) (defaults to: nil)

    A string indicating what

  • details (Array<Details>) (defaults to: nil)

    A string indicating which domain-specific

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • description_exclude (Array<DescriptionExclude>) (defaults to: nil)

    Turn off specified

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (ImageAnalysis)

    operation results.



159
160
161
162
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 159

def analyze_image(url, visual_features:nil, details:nil, language:nil, description_exclude:nil, custom_headers:nil)
  response = analyze_image_async(url, visual_features:visual_features, details:details, language:language, description_exclude:description_exclude, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#analyze_image_async(url, visual_features: nil, details: nil, language: nil, description_exclude: nil, custom_headers: nil) ⇒ Concurrent::Promise

This operation extracts a rich set of visual features based on the image content. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. Within your request, there is an optional parameter to allow you to choose which features to return. By default, image categories are returned in the response. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

visual feature types to return. Multiple values should be comma-separated. Valid visual feature types include: Categories - categorizes image content according to a taxonomy defined in documentation. Tags - tags the image with a detailed list of words related to the image content. Description - describes the image content with a complete English sentence. Faces - detects if faces are present. If present, generate coordinates, gender and age. ImageType - detects if image is clipart or a line drawing. Color - determines the accent color, dominant color, and whether an image is black&white. Adult

  • detects if the image is pornographic in nature (depicts nudity or a sex

act), or is gory (depicts extreme violence or blood). Sexually suggestive content (aka racy content) is also detected. Objects - detects various objects within an image, including the approximate location. The Objects argument is only available in English. Brands - detects various brands within an image, including the approximate location. The Brands argument is only available in English. details to return. Multiple values should be comma-separated. Valid visual feature types include: Celebrities - identifies celebrities if detected in the image, Landmarks - identifies notable landmarks in the image. parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ domain models when generating the description. to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • visual_features (Array<VisualFeatureTypes>) (defaults to: nil)

    A string indicating what

  • details (Array<Details>) (defaults to: nil)

    A string indicating which domain-specific

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • description_exclude (Array<DescriptionExclude>) (defaults to: nil)

    Turn off specified

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 256

def analyze_image_async(url, visual_features:nil, details:nil, language:nil, description_exclude:nil, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'url is nil' if url.nil?

  image_url = ImageUrl.new
  unless url.nil?
    image_url.url = url
  end

  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ImageUrl.mapper()
  request_content = self.serialize(request_mapper,  image_url)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'analyze'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'visualFeatures' => visual_features.nil? ? nil : visual_features.join(','),'details' => details.nil? ? nil : details.join(','),'language' => language,'descriptionExclude' => description_exclude.nil? ? nil : description_exclude.join(',')},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ImageAnalysis.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#analyze_image_by_domain(model, url, language: nil, custom_headers: nil) ⇒ DomainModelResults

This operation recognizes content within an image by applying a domain-specific model. The list of domain-specific models that are supported by the Computer Vision API can be retrieved using the /models GET request. Currently, the API provides following domain-specific models: celebrities, landmarks. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ will be added to the HTTP request.

Parameters:

  • model (String)

    The domain-specific content to recognize.

  • url (String)

    Publicly reachable URL of an image.

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (DomainModelResults)

    operation results.



714
715
716
717
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 714

def analyze_image_by_domain(model, url, language:nil, custom_headers:nil)
  response = analyze_image_by_domain_async(model, url, language:language, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#analyze_image_by_domain_async(model, url, language: nil, custom_headers: nil) ⇒ Concurrent::Promise

This operation recognizes content within an image by applying a domain-specific model. The list of domain-specific models that are supported by the Computer Vision API can be retrieved using the /models GET request. Currently, the API provides following domain-specific models: celebrities, landmarks. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ to the HTTP request.

Parameters:

  • model (String)

    The domain-specific content to recognize.

  • url (String)

    Publicly reachable URL of an image.

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 771

def analyze_image_by_domain_async(model, url, language:nil, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'model is nil' if model.nil?
  fail ArgumentError, 'url is nil' if url.nil?

  image_url = ImageUrl.new
  unless url.nil?
    image_url.url = url
  end

  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ImageUrl.mapper()
  request_content = self.serialize(request_mapper,  image_url)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'models/{model}/analyze'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      path_params: {'model' => model},
      query_params: {'language' => language},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::DomainModelResults.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#analyze_image_by_domain_in_stream(model, image, language: nil, custom_headers: nil) ⇒ DomainModelResults

This operation recognizes content within an image by applying a domain-specific model. The list of domain-specific models that are supported by the Computer Vision API can be retrieved using the /models GET request. Currently, the API provides following domain-specific models: celebrities, landmarks. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ will be added to the HTTP request.

Parameters:

  • model (String)

    The domain-specific content to recognize.

  • image

    An image stream.

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (DomainModelResults)

    operation results.



2607
2608
2609
2610
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2607

def analyze_image_by_domain_in_stream(model, image, language:nil, custom_headers:nil)
  response = analyze_image_by_domain_in_stream_async(model, image, language:language, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#analyze_image_by_domain_in_stream_async(model, image, language: nil, custom_headers: nil) ⇒ Concurrent::Promise

This operation recognizes content within an image by applying a domain-specific model. The list of domain-specific models that are supported by the Computer Vision API can be retrieved using the /models GET request. Currently, the API provides following domain-specific models: celebrities, landmarks. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ to the HTTP request.

Parameters:

  • model (String)

    The domain-specific content to recognize.

  • image

    An image stream.

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2664

def analyze_image_by_domain_in_stream_async(model, image, language:nil, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'model is nil' if model.nil?
  fail ArgumentError, 'image is nil' if image.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/octet-stream'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = {
    client_side_validation: true,
    required: true,
    serialized_name: 'Image',
    type: {
      name: 'Stream'
    }
  }
  request_content = self.serialize(request_mapper,  image)

  path_template = 'models/{model}/analyze'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      path_params: {'model' => model},
      query_params: {'language' => language},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::DomainModelResults.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#analyze_image_by_domain_in_stream_with_http_info(model, image, language: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This operation recognizes content within an image by applying a domain-specific model. The list of domain-specific models that are supported by the Computer Vision API can be retrieved using the /models GET request. Currently, the API provides following domain-specific models: celebrities, landmarks. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ will be added to the HTTP request.

Parameters:

  • model (String)

    The domain-specific content to recognize.

  • image

    An image stream.

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



2636
2637
2638
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2636

def analyze_image_by_domain_in_stream_with_http_info(model, image, language:nil, custom_headers:nil)
  analyze_image_by_domain_in_stream_async(model, image, language:language, custom_headers:custom_headers).value!
end

#analyze_image_by_domain_with_http_info(model, url, language: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This operation recognizes content within an image by applying a domain-specific model. The list of domain-specific models that are supported by the Computer Vision API can be retrieved using the /models GET request. Currently, the API provides following domain-specific models: celebrities, landmarks. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ will be added to the HTTP request.

Parameters:

  • model (String)

    The domain-specific content to recognize.

  • url (String)

    Publicly reachable URL of an image.

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



743
744
745
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 743

def analyze_image_by_domain_with_http_info(model, url, language:nil, custom_headers:nil)
  analyze_image_by_domain_async(model, url, language:language, custom_headers:custom_headers).value!
end

#analyze_image_in_stream(image, visual_features: nil, details: nil, language: nil, description_exclude: nil, custom_headers: nil) ⇒ ImageAnalysis

This operation extracts a rich set of visual features based on the image content. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. Within your request, there is an optional parameter to allow you to choose which features to return. By default, image categories are returned in the response. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

visual feature types to return. Multiple values should be comma-separated. Valid visual feature types include: Categories - categorizes image content according to a taxonomy defined in documentation. Tags - tags the image with a detailed list of words related to the image content. Description - describes the image content with a complete English sentence. Faces - detects if faces are present. If present, generate coordinates, gender and age. ImageType - detects if image is clipart or a line drawing. Color - determines the accent color, dominant color, and whether an image is black&white. Adult

  • detects if the image is pornographic in nature (depicts nudity or a sex

act), or is gory (depicts extreme violence or blood). Sexually suggestive content (aka racy content) is also detected. Objects - detects various objects within an image, including the approximate location. The Objects argument is only available in English. Brands - detects various brands within an image, including the approximate location. The Brands argument is only available in English. details to return. Multiple values should be comma-separated. Valid visual feature types include: Celebrities - identifies celebrities if detected in the image, Landmarks - identifies notable landmarks in the image. parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ domain models when generating the description. will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • visual_features (Array<VisualFeatureTypes>) (defaults to: nil)

    A string indicating what

  • details (Array<Details>) (defaults to: nil)

    A string indicating which domain-specific

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • description_exclude (Array<DescriptionExclude>) (defaults to: nil)

    Turn off specified

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (ImageAnalysis)

    operation results.



1860
1861
1862
1863
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1860

def analyze_image_in_stream(image, visual_features:nil, details:nil, language:nil, description_exclude:nil, custom_headers:nil)
  response = analyze_image_in_stream_async(image, visual_features:visual_features, details:details, language:language, description_exclude:description_exclude, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#analyze_image_in_stream_async(image, visual_features: nil, details: nil, language: nil, description_exclude: nil, custom_headers: nil) ⇒ Concurrent::Promise

This operation extracts a rich set of visual features based on the image content. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. Within your request, there is an optional parameter to allow you to choose which features to return. By default, image categories are returned in the response. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

visual feature types to return. Multiple values should be comma-separated. Valid visual feature types include: Categories - categorizes image content according to a taxonomy defined in documentation. Tags - tags the image with a detailed list of words related to the image content. Description - describes the image content with a complete English sentence. Faces - detects if faces are present. If present, generate coordinates, gender and age. ImageType - detects if image is clipart or a line drawing. Color - determines the accent color, dominant color, and whether an image is black&white. Adult

  • detects if the image is pornographic in nature (depicts nudity or a sex

act), or is gory (depicts extreme violence or blood). Sexually suggestive content (aka racy content) is also detected. Objects - detects various objects within an image, including the approximate location. The Objects argument is only available in English. Brands - detects various brands within an image, including the approximate location. The Brands argument is only available in English. details to return. Multiple values should be comma-separated. Valid visual feature types include: Celebrities - identifies celebrities if detected in the image, Landmarks - identifies notable landmarks in the image. parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ domain models when generating the description. to the HTTP request.

Parameters:

  • image

    An image stream.

  • visual_features (Array<VisualFeatureTypes>) (defaults to: nil)

    A string indicating what

  • details (Array<Details>) (defaults to: nil)

    A string indicating which domain-specific

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • description_exclude (Array<DescriptionExclude>) (defaults to: nil)

    Turn off specified

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1957

def analyze_image_in_stream_async(image, visual_features:nil, details:nil, language:nil, description_exclude:nil, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'image is nil' if image.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/octet-stream'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = {
    client_side_validation: true,
    required: true,
    serialized_name: 'Image',
    type: {
      name: 'Stream'
    }
  }
  request_content = self.serialize(request_mapper,  image)

  path_template = 'analyze'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'visualFeatures' => visual_features.nil? ? nil : visual_features.join(','),'details' => details.nil? ? nil : details.join(','),'language' => language,'descriptionExclude' => description_exclude.nil? ? nil : description_exclude.join(',')},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ImageAnalysis.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#analyze_image_in_stream_with_http_info(image, visual_features: nil, details: nil, language: nil, description_exclude: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This operation extracts a rich set of visual features based on the image content. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. Within your request, there is an optional parameter to allow you to choose which features to return. By default, image categories are returned in the response. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

visual feature types to return. Multiple values should be comma-separated. Valid visual feature types include: Categories - categorizes image content according to a taxonomy defined in documentation. Tags - tags the image with a detailed list of words related to the image content. Description - describes the image content with a complete English sentence. Faces - detects if faces are present. If present, generate coordinates, gender and age. ImageType - detects if image is clipart or a line drawing. Color - determines the accent color, dominant color, and whether an image is black&white. Adult

  • detects if the image is pornographic in nature (depicts nudity or a sex

act), or is gory (depicts extreme violence or blood). Sexually suggestive content (aka racy content) is also detected. Objects - detects various objects within an image, including the approximate location. The Objects argument is only available in English. Brands - detects various brands within an image, including the approximate location. The Brands argument is only available in English. details to return. Multiple values should be comma-separated. Valid visual feature types include: Celebrities - identifies celebrities if detected in the image, Landmarks - identifies notable landmarks in the image. parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ domain models when generating the description. will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • visual_features (Array<VisualFeatureTypes>) (defaults to: nil)

    A string indicating what

  • details (Array<Details>) (defaults to: nil)

    A string indicating which domain-specific

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • description_exclude (Array<DescriptionExclude>) (defaults to: nil)

    Turn off specified

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



1909
1910
1911
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1909

def analyze_image_in_stream_with_http_info(image, visual_features:nil, details:nil, language:nil, description_exclude:nil, custom_headers:nil)
  analyze_image_in_stream_async(image, visual_features:visual_features, details:details, language:language, description_exclude:description_exclude, custom_headers:custom_headers).value!
end

#analyze_image_with_http_info(url, visual_features: nil, details: nil, language: nil, description_exclude: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This operation extracts a rich set of visual features based on the image content. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. Within your request, there is an optional parameter to allow you to choose which features to return. By default, image categories are returned in the response. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

visual feature types to return. Multiple values should be comma-separated. Valid visual feature types include: Categories - categorizes image content according to a taxonomy defined in documentation. Tags - tags the image with a detailed list of words related to the image content. Description - describes the image content with a complete English sentence. Faces - detects if faces are present. If present, generate coordinates, gender and age. ImageType - detects if image is clipart or a line drawing. Color - determines the accent color, dominant color, and whether an image is black&white. Adult

  • detects if the image is pornographic in nature (depicts nudity or a sex

act), or is gory (depicts extreme violence or blood). Sexually suggestive content (aka racy content) is also detected. Objects - detects various objects within an image, including the approximate location. The Objects argument is only available in English. Brands - detects various brands within an image, including the approximate location. The Brands argument is only available in English. details to return. Multiple values should be comma-separated. Valid visual feature types include: Celebrities - identifies celebrities if detected in the image, Landmarks - identifies notable landmarks in the image. parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ domain models when generating the description. will be added to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • visual_features (Array<VisualFeatureTypes>) (defaults to: nil)

    A string indicating what

  • details (Array<Details>) (defaults to: nil)

    A string indicating which domain-specific

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • description_exclude (Array<DescriptionExclude>) (defaults to: nil)

    Turn off specified

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



208
209
210
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 208

def analyze_image_with_http_info(url, visual_features:nil, details:nil, language:nil, description_exclude:nil, custom_headers:nil)
  analyze_image_async(url, visual_features:visual_features, details:details, language:language, description_exclude:description_exclude, custom_headers:custom_headers).value!
end

#batch_read_file(url, custom_headers: nil) ⇒ Object

Use this interface to get the result of a Read operation, employing the state-of-the-art Optical Character Recognition (OCR) algorithms optimized for text-heavy documents. When you use the Read File interface, the response contains a field called ‘Operation-Location’. The ‘Operation-Location’ field contains the URL that you must use for your ‘GetReadOperationResult’ operation to access OCR results.​

will be added to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that



1628
1629
1630
1631
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1628

def batch_read_file(url, custom_headers:nil)
  response = batch_read_file_async(url, custom_headers:custom_headers).value!
  nil
end

#batch_read_file_async(url, custom_headers: nil) ⇒ Concurrent::Promise

Use this interface to get the result of a Read operation, employing the state-of-the-art Optical Character Recognition (OCR) algorithms optimized for text-heavy documents. When you use the Read File interface, the response contains a field called ‘Operation-Location’. The ‘Operation-Location’ field contains the URL that you must use for your ‘GetReadOperationResult’ operation to access OCR results.​

to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1665

def batch_read_file_async(url, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'url is nil' if url.nil?

  image_url = ImageUrl.new
  unless url.nil?
    image_url.url = url
  end

  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ImageUrl.mapper()
  request_content = self.serialize(request_mapper,  image_url)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'read/core/asyncBatchAnalyze'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 202
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?

    result
  end

  promise.execute
end

#batch_read_file_in_stream(image, custom_headers: nil) ⇒ Object

Use this interface to get the result of a Read Document operation, employing the state-of-the-art Optical Character Recognition (OCR) algorithms optimized for text-heavy documents. When you use the Read Document interface, the response contains a field called ‘Operation-Location’. The ‘Operation-Location’ field contains the URL that you must use for your ‘Get Read Result operation’ to access OCR results.​

will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that



3150
3151
3152
3153
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 3150

def batch_read_file_in_stream(image, custom_headers:nil)
  response = batch_read_file_in_stream_async(image, custom_headers:custom_headers).value!
  nil
end

#batch_read_file_in_stream_async(image, custom_headers: nil) ⇒ Concurrent::Promise

Use this interface to get the result of a Read Document operation, employing the state-of-the-art Optical Character Recognition (OCR) algorithms optimized for text-heavy documents. When you use the Read Document interface, the response contains a field called ‘Operation-Location’. The ‘Operation-Location’ field contains the URL that you must use for your ‘Get Read Result operation’ to access OCR results.​

to the HTTP request.

Parameters:

  • image

    An image stream.

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 3187

def batch_read_file_in_stream_async(image, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'image is nil' if image.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/octet-stream'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = {
    client_side_validation: true,
    required: true,
    serialized_name: 'Image',
    type: {
      name: 'Stream'
    }
  }
  request_content = self.serialize(request_mapper,  image)

  path_template = 'read/core/asyncBatchAnalyze'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 202
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?

    result
  end

  promise.execute
end

#batch_read_file_in_stream_with_http_info(image, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Use this interface to get the result of a Read Document operation, employing the state-of-the-art Optical Character Recognition (OCR) algorithms optimized for text-heavy documents. When you use the Read Document interface, the response contains a field called ‘Operation-Location’. The ‘Operation-Location’ field contains the URL that you must use for your ‘Get Read Result operation’ to access OCR results.​

will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



3169
3170
3171
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 3169

def batch_read_file_in_stream_with_http_info(image, custom_headers:nil)
  batch_read_file_in_stream_async(image, custom_headers:custom_headers).value!
end

#batch_read_file_with_http_info(url, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Use this interface to get the result of a Read operation, employing the state-of-the-art Optical Character Recognition (OCR) algorithms optimized for text-heavy documents. When you use the Read File interface, the response contains a field called ‘Operation-Location’. The ‘Operation-Location’ field contains the URL that you must use for your ‘GetReadOperationResult’ operation to access OCR results.​

will be added to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



1647
1648
1649
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1647

def batch_read_file_with_http_info(url, custom_headers:nil)
  batch_read_file_async(url, custom_headers:custom_headers).value!
end

#describe_image(url, max_candidates: 1, language: nil, description_exclude: nil, custom_headers: nil) ⇒ ImageDescription

This operation generates a description of an image in human readable language with complete sentences. The description is based on a collection of content tags, which are also returned by the operation. More than one description can be generated for each image. Descriptions are ordered by their confidence score. Descriptions may include results from celebrity and landmark domain models, if applicable. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

be returned. The default is 1. parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ domain models when generating the description. will be added to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • max_candidates (Integer) (defaults to: 1)

    Maximum number of candidate descriptions to

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • description_exclude (Array<DescriptionExclude>) (defaults to: nil)

    Turn off specified

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (ImageDescription)

    operation results.



348
349
350
351
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 348

def describe_image(url, max_candidates:1, language:nil, description_exclude:nil, custom_headers:nil)
  response = describe_image_async(url, max_candidates:max_candidates, language:language, description_exclude:description_exclude, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#describe_image_async(url, max_candidates: 1, language: nil, description_exclude: nil, custom_headers: nil) ⇒ Concurrent::Promise

This operation generates a description of an image in human readable language with complete sentences. The description is based on a collection of content tags, which are also returned by the operation. More than one description can be generated for each image. Descriptions are ordered by their confidence score. Descriptions may include results from celebrity and landmark domain models, if applicable. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

be returned. The default is 1. parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ domain models when generating the description. to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • max_candidates (Integer) (defaults to: 1)

    Maximum number of candidate descriptions to

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • description_exclude (Array<DescriptionExclude>) (defaults to: nil)

    Turn off specified

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 413

def describe_image_async(url, max_candidates:1, language:nil, description_exclude:nil, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'url is nil' if url.nil?

  image_url = ImageUrl.new
  unless url.nil?
    image_url.url = url
  end

  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ImageUrl.mapper()
  request_content = self.serialize(request_mapper,  image_url)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'describe'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'maxCandidates' => max_candidates,'language' => language,'descriptionExclude' => description_exclude.nil? ? nil : description_exclude.join(',')},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ImageDescription.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#describe_image_in_stream(image, max_candidates: 1, language: nil, description_exclude: nil, custom_headers: nil) ⇒ ImageDescription

This operation generates a description of an image in human readable language with complete sentences. The description is based on a collection of content tags, which are also returned by the operation. More than one description can be generated for each image. Descriptions are ordered by their confidence score. Descriptions may include results from celebrity and landmark domain models, if applicable. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

be returned. The default is 1. parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ domain models when generating the description. will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • max_candidates (Integer) (defaults to: 1)

    Maximum number of candidate descriptions to

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • description_exclude (Array<DescriptionExclude>) (defaults to: nil)

    Turn off specified

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (ImageDescription)

    operation results.



2173
2174
2175
2176
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2173

def describe_image_in_stream(image, max_candidates:1, language:nil, description_exclude:nil, custom_headers:nil)
  response = describe_image_in_stream_async(image, max_candidates:max_candidates, language:language, description_exclude:description_exclude, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#describe_image_in_stream_async(image, max_candidates: 1, language: nil, description_exclude: nil, custom_headers: nil) ⇒ Concurrent::Promise

This operation generates a description of an image in human readable language with complete sentences. The description is based on a collection of content tags, which are also returned by the operation. More than one description can be generated for each image. Descriptions are ordered by their confidence score. Descriptions may include results from celebrity and landmark domain models, if applicable. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

be returned. The default is 1. parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ domain models when generating the description. to the HTTP request.

Parameters:

  • image

    An image stream.

  • max_candidates (Integer) (defaults to: 1)

    Maximum number of candidate descriptions to

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • description_exclude (Array<DescriptionExclude>) (defaults to: nil)

    Turn off specified

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2238

def describe_image_in_stream_async(image, max_candidates:1, language:nil, description_exclude:nil, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'image is nil' if image.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/octet-stream'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = {
    client_side_validation: true,
    required: true,
    serialized_name: 'Image',
    type: {
      name: 'Stream'
    }
  }
  request_content = self.serialize(request_mapper,  image)

  path_template = 'describe'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'maxCandidates' => max_candidates,'language' => language,'descriptionExclude' => description_exclude.nil? ? nil : description_exclude.join(',')},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ImageDescription.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#describe_image_in_stream_with_http_info(image, max_candidates: 1, language: nil, description_exclude: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This operation generates a description of an image in human readable language with complete sentences. The description is based on a collection of content tags, which are also returned by the operation. More than one description can be generated for each image. Descriptions are ordered by their confidence score. Descriptions may include results from celebrity and landmark domain models, if applicable. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

be returned. The default is 1. parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ domain models when generating the description. will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • max_candidates (Integer) (defaults to: 1)

    Maximum number of candidate descriptions to

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • description_exclude (Array<DescriptionExclude>) (defaults to: nil)

    Turn off specified

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



2206
2207
2208
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2206

def describe_image_in_stream_with_http_info(image, max_candidates:1, language:nil, description_exclude:nil, custom_headers:nil)
  describe_image_in_stream_async(image, max_candidates:max_candidates, language:language, description_exclude:description_exclude, custom_headers:custom_headers).value!
end

#describe_image_with_http_info(url, max_candidates: 1, language: nil, description_exclude: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This operation generates a description of an image in human readable language with complete sentences. The description is based on a collection of content tags, which are also returned by the operation. More than one description can be generated for each image. Descriptions are ordered by their confidence score. Descriptions may include results from celebrity and landmark domain models, if applicable. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

be returned. The default is 1. parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ domain models when generating the description. will be added to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • max_candidates (Integer) (defaults to: 1)

    Maximum number of candidate descriptions to

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • description_exclude (Array<DescriptionExclude>) (defaults to: nil)

    Turn off specified

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



381
382
383
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 381

def describe_image_with_http_info(url, max_candidates:1, language:nil, description_exclude:nil, custom_headers:nil)
  describe_image_async(url, max_candidates:max_candidates, language:language, description_exclude:description_exclude, custom_headers:custom_headers).value!
end

#detect_objects(url, custom_headers: nil) ⇒ DetectResult

Performs object detection on the specified image. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

will be added to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (DetectResult)

    operation results.



491
492
493
494
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 491

def detect_objects(url, custom_headers:nil)
  response = detect_objects_async(url, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#detect_objects_async(url, custom_headers: nil) ⇒ Concurrent::Promise

Performs object detection on the specified image. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 528

def detect_objects_async(url, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'url is nil' if url.nil?

  image_url = ImageUrl.new
  unless url.nil?
    image_url.url = url
  end

  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ImageUrl.mapper()
  request_content = self.serialize(request_mapper,  image_url)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'detect'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::DetectResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#detect_objects_in_stream(image, custom_headers: nil) ⇒ DetectResult

Performs object detection on the specified image. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (DetectResult)

    operation results.



2318
2319
2320
2321
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2318

def detect_objects_in_stream(image, custom_headers:nil)
  response = detect_objects_in_stream_async(image, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#detect_objects_in_stream_async(image, custom_headers: nil) ⇒ Concurrent::Promise

Performs object detection on the specified image. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

to the HTTP request.

Parameters:

  • image

    An image stream.

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2355

def detect_objects_in_stream_async(image, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'image is nil' if image.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/octet-stream'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = {
    client_side_validation: true,
    required: true,
    serialized_name: 'Image',
    type: {
      name: 'Stream'
    }
  }
  request_content = self.serialize(request_mapper,  image)

  path_template = 'detect'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::DetectResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#detect_objects_in_stream_with_http_info(image, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Performs object detection on the specified image. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



2337
2338
2339
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2337

def detect_objects_in_stream_with_http_info(image, custom_headers:nil)
  detect_objects_in_stream_async(image, custom_headers:custom_headers).value!
end

#detect_objects_with_http_info(url, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Performs object detection on the specified image. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

will be added to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



510
511
512
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 510

def detect_objects_with_http_info(url, custom_headers:nil)
  detect_objects_async(url, custom_headers:custom_headers).value!
end

#generate_thumbnail(width, height, url, smart_cropping: false, custom_headers: nil) ⇒ NOT_IMPLEMENTED

This operation generates a thumbnail image with the user-specified width and height. By default, the service analyzes the image, identifies the region of interest (ROI), and generates smart cropping coordinates based on the ROI. Smart cropping helps when you specify an aspect ratio that differs from that of the input image. A successful response contains the thumbnail image binary. If the request failed, the response contains an error code and a message to help determine what went wrong. Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, InvalidThumbnailSize, NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.

1 and 1024. Recommended minimum of 50. between 1 and 1024. Recommended minimum of 50. will be added to the HTTP request.

Parameters:

  • width (Integer)

    Width of the thumbnail, in pixels. It must be between

  • height (Integer)

    Height of the thumbnail, in pixels. It must be

  • url (String)

    Publicly reachable URL of an image.

  • smart_cropping (Boolean) (defaults to: false)

    Boolean flag for enabling smart cropping.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (NOT_IMPLEMENTED)

    operation results.



1156
1157
1158
1159
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1156

def generate_thumbnail(width, height, url, smart_cropping:false, custom_headers:nil)
  response = generate_thumbnail_async(width, height, url, smart_cropping:smart_cropping, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#generate_thumbnail_async(width, height, url, smart_cropping: false, custom_headers: nil) ⇒ Concurrent::Promise

This operation generates a thumbnail image with the user-specified width and height. By default, the service analyzes the image, identifies the region of interest (ROI), and generates smart cropping coordinates based on the ROI. Smart cropping helps when you specify an aspect ratio that differs from that of the input image. A successful response contains the thumbnail image binary. If the request failed, the response contains an error code and a message to help determine what went wrong. Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, InvalidThumbnailSize, NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.

1 and 1024. Recommended minimum of 50. between 1 and 1024. Recommended minimum of 50. to the HTTP request.

Parameters:

  • width (Integer)

    Width of the thumbnail, in pixels. It must be between

  • height (Integer)

    Height of the thumbnail, in pixels. It must be

  • url (String)

    Publicly reachable URL of an image.

  • smart_cropping (Boolean) (defaults to: false)

    Boolean flag for enabling smart cropping.

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1215

def generate_thumbnail_async(width, height, url, smart_cropping:false, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'width is nil' if width.nil?
  fail ArgumentError, "'width' should satisfy the constraint - 'InclusiveMaximum': '1024'" if !width.nil? && width > 1024
  fail ArgumentError, "'width' should satisfy the constraint - 'InclusiveMinimum': '1'" if !width.nil? && width < 1
  fail ArgumentError, 'height is nil' if height.nil?
  fail ArgumentError, "'height' should satisfy the constraint - 'InclusiveMaximum': '1024'" if !height.nil? && height > 1024
  fail ArgumentError, "'height' should satisfy the constraint - 'InclusiveMinimum': '1'" if !height.nil? && height < 1
  fail ArgumentError, 'url is nil' if url.nil?

  image_url = ImageUrl.new
  unless url.nil?
    image_url.url = url
  end

  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ImageUrl.mapper()
  request_content = self.serialize(request_mapper,  image_url)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'generateThumbnail'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'width' => width,'height' => height,'smartCropping' => smart_cropping},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = {
          client_side_validation: true,
          required: false,
          serialized_name: 'parsed_response',
          type: {
            name: 'Stream'
          }
        }
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#generate_thumbnail_in_stream(width, height, image, smart_cropping: false, custom_headers: nil) ⇒ NOT_IMPLEMENTED

This operation generates a thumbnail image with the user-specified width and height. By default, the service analyzes the image, identifies the region of interest (ROI), and generates smart cropping coordinates based on the ROI. Smart cropping helps when you specify an aspect ratio that differs from that of the input image. A successful response contains the thumbnail image binary. If the request failed, the response contains an error code and a message to help determine what went wrong. Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, InvalidThumbnailSize, NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.

1 and 1024. Recommended minimum of 50. between 1 and 1024. Recommended minimum of 50. will be added to the HTTP request.

Parameters:

  • width (Integer)

    Width of the thumbnail, in pixels. It must be between

  • height (Integer)

    Height of the thumbnail, in pixels. It must be

  • image

    An image stream.

  • smart_cropping (Boolean) (defaults to: false)

    Boolean flag for enabling smart cropping.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (NOT_IMPLEMENTED)

    operation results.



2445
2446
2447
2448
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2445

def generate_thumbnail_in_stream(width, height, image, smart_cropping:false, custom_headers:nil)
  response = generate_thumbnail_in_stream_async(width, height, image, smart_cropping:smart_cropping, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#generate_thumbnail_in_stream_async(width, height, image, smart_cropping: false, custom_headers: nil) ⇒ Concurrent::Promise

This operation generates a thumbnail image with the user-specified width and height. By default, the service analyzes the image, identifies the region of interest (ROI), and generates smart cropping coordinates based on the ROI. Smart cropping helps when you specify an aspect ratio that differs from that of the input image. A successful response contains the thumbnail image binary. If the request failed, the response contains an error code and a message to help determine what went wrong. Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, InvalidThumbnailSize, NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.

1 and 1024. Recommended minimum of 50. between 1 and 1024. Recommended minimum of 50. to the HTTP request.

Parameters:

  • width (Integer)

    Width of the thumbnail, in pixels. It must be between

  • height (Integer)

    Height of the thumbnail, in pixels. It must be

  • image

    An image stream.

  • smart_cropping (Boolean) (defaults to: false)

    Boolean flag for enabling smart cropping.

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2504

def generate_thumbnail_in_stream_async(width, height, image, smart_cropping:false, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'width is nil' if width.nil?
  fail ArgumentError, "'width' should satisfy the constraint - 'InclusiveMaximum': '1024'" if !width.nil? && width > 1024
  fail ArgumentError, "'width' should satisfy the constraint - 'InclusiveMinimum': '1'" if !width.nil? && width < 1
  fail ArgumentError, 'height is nil' if height.nil?
  fail ArgumentError, "'height' should satisfy the constraint - 'InclusiveMaximum': '1024'" if !height.nil? && height > 1024
  fail ArgumentError, "'height' should satisfy the constraint - 'InclusiveMinimum': '1'" if !height.nil? && height < 1
  fail ArgumentError, 'image is nil' if image.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/octet-stream'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = {
    client_side_validation: true,
    required: true,
    serialized_name: 'Image',
    type: {
      name: 'Stream'
    }
  }
  request_content = self.serialize(request_mapper,  image)

  path_template = 'generateThumbnail'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'width' => width,'height' => height,'smartCropping' => smart_cropping},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = {
          client_side_validation: true,
          required: false,
          serialized_name: 'parsed_response',
          type: {
            name: 'Stream'
          }
        }
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#generate_thumbnail_in_stream_with_http_info(width, height, image, smart_cropping: false, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This operation generates a thumbnail image with the user-specified width and height. By default, the service analyzes the image, identifies the region of interest (ROI), and generates smart cropping coordinates based on the ROI. Smart cropping helps when you specify an aspect ratio that differs from that of the input image. A successful response contains the thumbnail image binary. If the request failed, the response contains an error code and a message to help determine what went wrong. Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, InvalidThumbnailSize, NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.

1 and 1024. Recommended minimum of 50. between 1 and 1024. Recommended minimum of 50. will be added to the HTTP request.

Parameters:

  • width (Integer)

    Width of the thumbnail, in pixels. It must be between

  • height (Integer)

    Height of the thumbnail, in pixels. It must be

  • image

    An image stream.

  • smart_cropping (Boolean) (defaults to: false)

    Boolean flag for enabling smart cropping.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



2475
2476
2477
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2475

def generate_thumbnail_in_stream_with_http_info(width, height, image, smart_cropping:false, custom_headers:nil)
  generate_thumbnail_in_stream_async(width, height, image, smart_cropping:smart_cropping, custom_headers:custom_headers).value!
end

#generate_thumbnail_with_http_info(width, height, url, smart_cropping: false, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This operation generates a thumbnail image with the user-specified width and height. By default, the service analyzes the image, identifies the region of interest (ROI), and generates smart cropping coordinates based on the ROI. Smart cropping helps when you specify an aspect ratio that differs from that of the input image. A successful response contains the thumbnail image binary. If the request failed, the response contains an error code and a message to help determine what went wrong. Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, InvalidThumbnailSize, NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.

1 and 1024. Recommended minimum of 50. between 1 and 1024. Recommended minimum of 50. will be added to the HTTP request.

Parameters:

  • width (Integer)

    Width of the thumbnail, in pixels. It must be between

  • height (Integer)

    Height of the thumbnail, in pixels. It must be

  • url (String)

    Publicly reachable URL of an image.

  • smart_cropping (Boolean) (defaults to: false)

    Boolean flag for enabling smart cropping.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



1186
1187
1188
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1186

def generate_thumbnail_with_http_info(width, height, url, smart_cropping:false, custom_headers:nil)
  generate_thumbnail_async(width, height, url, smart_cropping:smart_cropping, custom_headers:custom_headers).value!
end

#get_area_of_interest(url, custom_headers: nil) ⇒ AreaOfInterestResult

This operation returns a bounding box around the most important area of the image. A successful response will be returned in JSON. If the request failed, the response contains an error code and a message to help determine what went wrong. Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.

will be added to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (AreaOfInterestResult)

    operation results.



1308
1309
1310
1311
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1308

def get_area_of_interest(url, custom_headers:nil)
  response = get_area_of_interest_async(url, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#get_area_of_interest_async(url, custom_headers: nil) ⇒ Concurrent::Promise

This operation returns a bounding box around the most important area of the image. A successful response will be returned in JSON. If the request failed, the response contains an error code and a message to help determine what went wrong. Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.

to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1349

def get_area_of_interest_async(url, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'url is nil' if url.nil?

  image_url = ImageUrl.new
  unless url.nil?
    image_url.url = url
  end

  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ImageUrl.mapper()
  request_content = self.serialize(request_mapper,  image_url)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'areaOfInterest'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::AreaOfInterestResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#get_area_of_interest_in_stream(image, custom_headers: nil) ⇒ AreaOfInterestResult

This operation returns a bounding box around the most important area of the image. A successful response will be returned in JSON. If the request failed, the response contains an error code and a message to help determine what went wrong. Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.

will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (AreaOfInterestResult)

    operation results.



2039
2040
2041
2042
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2039

def get_area_of_interest_in_stream(image, custom_headers:nil)
  response = get_area_of_interest_in_stream_async(image, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#get_area_of_interest_in_stream_async(image, custom_headers: nil) ⇒ Concurrent::Promise

This operation returns a bounding box around the most important area of the image. A successful response will be returned in JSON. If the request failed, the response contains an error code and a message to help determine what went wrong. Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.

to the HTTP request.

Parameters:

  • image

    An image stream.

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2080

def get_area_of_interest_in_stream_async(image, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'image is nil' if image.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/octet-stream'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = {
    client_side_validation: true,
    required: true,
    serialized_name: 'Image',
    type: {
      name: 'Stream'
    }
  }
  request_content = self.serialize(request_mapper,  image)

  path_template = 'areaOfInterest'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::AreaOfInterestResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#get_area_of_interest_in_stream_with_http_info(image, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This operation returns a bounding box around the most important area of the image. A successful response will be returned in JSON. If the request failed, the response contains an error code and a message to help determine what went wrong. Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.

will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



2060
2061
2062
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2060

def get_area_of_interest_in_stream_with_http_info(image, custom_headers:nil)
  get_area_of_interest_in_stream_async(image, custom_headers:custom_headers).value!
end

#get_area_of_interest_with_http_info(url, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This operation returns a bounding box around the most important area of the image. A successful response will be returned in JSON. If the request failed, the response contains an error code and a message to help determine what went wrong. Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.

will be added to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



1329
1330
1331
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1329

def get_area_of_interest_with_http_info(url, custom_headers:nil)
  get_area_of_interest_async(url, custom_headers:custom_headers).value!
end

#get_read_operation_result(operation_id, custom_headers: nil) ⇒ ReadOperationResult

This interface is used for getting OCR results of Read operation. The URL to this interface should be retrieved from ‘Operation-Location’ field returned from Batch Read File interface.

the ‘Batch Read File’ interface. will be added to the HTTP request.

Parameters:

  • operation_id (String)

    Id of read operation returned in the response of

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (ReadOperationResult)

    operation results.



1730
1731
1732
1733
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1730

def get_read_operation_result(operation_id, custom_headers:nil)
  response = get_read_operation_result_async(operation_id, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#get_read_operation_result_async(operation_id, custom_headers: nil) ⇒ Concurrent::Promise

This interface is used for getting OCR results of Read operation. The URL to this interface should be retrieved from ‘Operation-Location’ field returned from Batch Read File interface.

the ‘Batch Read File’ interface. to the HTTP request.

Parameters:

  • operation_id (String)

    Id of read operation returned in the response of

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1763

def get_read_operation_result_async(operation_id, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'operation_id is nil' if operation_id.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?
  path_template = 'read/operations/{operationId}'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      path_params: {'operationId' => operation_id},
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:get, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ReadOperationResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#get_read_operation_result_with_http_info(operation_id, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This interface is used for getting OCR results of Read operation. The URL to this interface should be retrieved from ‘Operation-Location’ field returned from Batch Read File interface.

the ‘Batch Read File’ interface. will be added to the HTTP request.

Parameters:

  • operation_id (String)

    Id of read operation returned in the response of

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



1747
1748
1749
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1747

def get_read_operation_result_with_http_info(operation_id, custom_headers:nil)
  get_read_operation_result_async(operation_id, custom_headers:custom_headers).value!
end

#get_text_operation_result(operation_id, custom_headers: nil) ⇒ TextOperationResult

This interface is used for getting text operation result. The URL to this interface should be retrieved from ‘Operation-Location’ field returned from Recognize Text interface.

response of the ‘Recognize Text’ will be added to the HTTP request.

Parameters:

  • operation_id (String)

    Id of the text operation returned in the

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (TextOperationResult)

    operation results.



1529
1530
1531
1532
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1529

def get_text_operation_result(operation_id, custom_headers:nil)
  response = get_text_operation_result_async(operation_id, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#get_text_operation_result_async(operation_id, custom_headers: nil) ⇒ Concurrent::Promise

This interface is used for getting text operation result. The URL to this interface should be retrieved from ‘Operation-Location’ field returned from Recognize Text interface.

response of the ‘Recognize Text’ to the HTTP request.

Parameters:

  • operation_id (String)

    Id of the text operation returned in the

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1562

def get_text_operation_result_async(operation_id, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'operation_id is nil' if operation_id.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?
  path_template = 'textOperations/{operationId}'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      path_params: {'operationId' => operation_id},
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:get, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::TextOperationResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#get_text_operation_result_with_http_info(operation_id, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This interface is used for getting text operation result. The URL to this interface should be retrieved from ‘Operation-Location’ field returned from Recognize Text interface.

response of the ‘Recognize Text’ will be added to the HTTP request.

Parameters:

  • operation_id (String)

    Id of the text operation returned in the

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



1546
1547
1548
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1546

def get_text_operation_result_with_http_info(operation_id, custom_headers:nil)
  get_text_operation_result_async(operation_id, custom_headers:custom_headers).value!
end

#list_models(custom_headers: nil) ⇒ ListModelsResult

This operation returns the list of domain-specific models that are supported by the Computer Vision API. Currently, the API supports following domain-specific models: celebrity recognizer, landmark recognizer. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

will be added to the HTTP request.

Parameters:

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (ListModelsResult)

    operation results.



604
605
606
607
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 604

def list_models(custom_headers:nil)
  response = list_models_async(custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#list_models_async(custom_headers: nil) ⇒ Concurrent::Promise

This operation returns the list of domain-specific models that are supported by the Computer Vision API. Currently, the API supports following domain-specific models: celebrity recognizer, landmark recognizer. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

to the HTTP request.

Parameters:

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 639

def list_models_async(custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?
  path_template = 'models'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:get, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ListModelsResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#list_models_with_http_info(custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This operation returns the list of domain-specific models that are supported by the Computer Vision API. Currently, the API supports following domain-specific models: celebrity recognizer, landmark recognizer. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

will be added to the HTTP request.

Parameters:

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



622
623
624
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 622

def list_models_with_http_info(custom_headers:nil)
  list_models_async(custom_headers:custom_headers).value!
end

#make_request(method, path, options = {}) ⇒ Hash{String=>String}

Makes a request and returns the body of the response. Example:

request_content = "{'location':'westus','tags':{'tag1':'val1','tag2':'val2'}}"
path = "/path"
options = {
  body: request_content,
  query_params: {'api-version' => '2016-02-01'}
}
result = @client.make_request(:put, path, options)

Parameters:

  • method (Symbol)

    with any of the following values :get, :put, :post, :patch, :delete.

  • path (String)

    the path, relative to #base_url.

  • options (Hash{String=>String}) (defaults to: {})

    specifying any request options like :body.

Returns:

  • (Hash{String=>String})

    containing the body of the response.



73
74
75
76
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 73

def make_request(method, path, options = {})
  result = make_request_with_http_info(method, path, options)
  result.body unless result.nil?
end

#make_request_async(method, path, options = {}) ⇒ Concurrent::Promise

Makes a request asynchronously.

Parameters:

  • method (Symbol)

    with any of the following values :get, :put, :post, :patch, :delete.

  • path (String)

    the path, relative to #base_url.

  • options (Hash{String=>String}) (defaults to: {})

    specifying any request options like :body.

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 98

def make_request_async(method, path, options = {})
  fail ArgumentError, 'method is nil' if method.nil?
  fail ArgumentError, 'path is nil' if path.nil?

  request_url = options[:base_url] || @base_url
  if(!options[:headers].nil? && !options[:headers]['Content-Type'].nil?)
    @request_headers['Content-Type'] = options[:headers]['Content-Type']
  end

  request_headers = @request_headers
  request_headers.merge!({'accept-language' => @accept_language}) unless @accept_language.nil?
  options.merge!({headers: request_headers.merge(options[:headers] || {})})
  options.merge!({credentials: @credentials}) unless @credentials.nil?

  super(request_url, method, path, options)
end

#make_request_with_http_info(method, path, options = {}) ⇒ MsRestAzure::AzureOperationResponse

Makes a request and returns the operation response.

Parameters:

  • method (Symbol)

    with any of the following values :get, :put, :post, :patch, :delete.

  • path (String)

    the path, relative to #base_url.

  • options (Hash{String=>String}) (defaults to: {})

    specifying any request options like :body.

Returns:

  • (MsRestAzure::AzureOperationResponse)

    Operation response containing the request, response and status.



85
86
87
88
89
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 85

def make_request_with_http_info(method, path, options = {})
  result = make_request_async(method, path, options).value!
  result.body = result.response.body.to_s.empty? ? nil : JSON.load(result.response.body)
  result
end

#recognize_printed_text(detect_orientation, url, language: nil, custom_headers: nil) ⇒ OcrResult

Optical Character Recognition (OCR) detects text in an image and extracts the recognized characters into a machine-usable character stream. Upon success, the OCR results will be returned. Upon failure, the error code together with an error message will be returned. The error code can be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, NotSupportedLanguage, or InternalServerError.

the image. With detectOrientation=true the OCR service tries to detect the image orientation and correct it before further processing (e.g. if it’s upside-down). detected in the image. The default value is ‘unk’. Possible values include: ‘unk’, ‘zh-Hans’, ‘zh-Hant’, ‘cs’, ‘da’, ‘nl’, ‘en’, ‘fi’, ‘fr’, ‘de’, ‘el’, ‘hu’, ‘it’, ‘ja’, ‘ko’, ‘nb’, ‘pl’, ‘pt’, ‘ru’, ‘es’, ‘sv’, ‘tr’, ‘ar’, ‘ro’, ‘sr-Cyrl’, ‘sr-Latn’, ‘sk’ will be added to the HTTP request.

Parameters:

  • detect_orientation (Boolean)

    Whether detect the text orientation in

  • url (String)

    Publicly reachable URL of an image.

  • language (OcrLanguages) (defaults to: nil)

    The BCP-47 language code of the text to be

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (OcrResult)

    operation results.



861
862
863
864
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 861

def recognize_printed_text(detect_orientation, url, language:nil, custom_headers:nil)
  response = recognize_printed_text_async(detect_orientation, url, language:language, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#recognize_printed_text_async(detect_orientation, url, language: nil, custom_headers: nil) ⇒ Concurrent::Promise

Optical Character Recognition (OCR) detects text in an image and extracts the recognized characters into a machine-usable character stream. Upon success, the OCR results will be returned. Upon failure, the error code together with an error message will be returned. The error code can be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, NotSupportedLanguage, or InternalServerError.

the image. With detectOrientation=true the OCR service tries to detect the image orientation and correct it before further processing (e.g. if it’s upside-down). detected in the image. The default value is ‘unk’. Possible values include: ‘unk’, ‘zh-Hans’, ‘zh-Hant’, ‘cs’, ‘da’, ‘nl’, ‘en’, ‘fi’, ‘fr’, ‘de’, ‘el’, ‘hu’, ‘it’, ‘ja’, ‘ko’, ‘nb’, ‘pl’, ‘pt’, ‘ru’, ‘es’, ‘sv’, ‘tr’, ‘ar’, ‘ro’, ‘sr-Cyrl’, ‘sr-Latn’, ‘sk’ to the HTTP request.

Parameters:

  • detect_orientation (Boolean)

    Whether detect the text orientation in

  • url (String)

    Publicly reachable URL of an image.

  • language (OcrLanguages) (defaults to: nil)

    The BCP-47 language code of the text to be

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 918

def recognize_printed_text_async(detect_orientation, url, language:nil, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'detect_orientation is nil' if detect_orientation.nil?
  fail ArgumentError, 'url is nil' if url.nil?

  image_url = ImageUrl.new
  unless url.nil?
    image_url.url = url
  end

  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ImageUrl.mapper()
  request_content = self.serialize(request_mapper,  image_url)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'ocr'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'detectOrientation' => detect_orientation,'language' => language},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::OcrResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#recognize_printed_text_in_stream(detect_orientation, image, language: nil, custom_headers: nil) ⇒ OcrResult

Optical Character Recognition (OCR) detects text in an image and extracts the recognized characters into a machine-usable character stream. Upon success, the OCR results will be returned. Upon failure, the error code together with an error message will be returned. The error code can be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, NotSupportedLanguage, or InternalServerError.

the image. With detectOrientation=true the OCR service tries to detect the image orientation and correct it before further processing (e.g. if it’s upside-down). detected in the image. The default value is ‘unk’. Possible values include: ‘unk’, ‘zh-Hans’, ‘zh-Hant’, ‘cs’, ‘da’, ‘nl’, ‘en’, ‘fi’, ‘fr’, ‘de’, ‘el’, ‘hu’, ‘it’, ‘ja’, ‘ko’, ‘nb’, ‘pl’, ‘pt’, ‘ru’, ‘es’, ‘sv’, ‘tr’, ‘ar’, ‘ro’, ‘sr-Cyrl’, ‘sr-Latn’, ‘sk’ will be added to the HTTP request.

Parameters:

  • detect_orientation (Boolean)

    Whether detect the text orientation in

  • image

    An image stream.

  • language (OcrLanguages) (defaults to: nil)

    The BCP-47 language code of the text to be

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (OcrResult)

    operation results.



2756
2757
2758
2759
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2756

def recognize_printed_text_in_stream(detect_orientation, image, language:nil, custom_headers:nil)
  response = recognize_printed_text_in_stream_async(detect_orientation, image, language:language, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#recognize_printed_text_in_stream_async(detect_orientation, image, language: nil, custom_headers: nil) ⇒ Concurrent::Promise

Optical Character Recognition (OCR) detects text in an image and extracts the recognized characters into a machine-usable character stream. Upon success, the OCR results will be returned. Upon failure, the error code together with an error message will be returned. The error code can be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, NotSupportedLanguage, or InternalServerError.

the image. With detectOrientation=true the OCR service tries to detect the image orientation and correct it before further processing (e.g. if it’s upside-down). detected in the image. The default value is ‘unk’. Possible values include: ‘unk’, ‘zh-Hans’, ‘zh-Hant’, ‘cs’, ‘da’, ‘nl’, ‘en’, ‘fi’, ‘fr’, ‘de’, ‘el’, ‘hu’, ‘it’, ‘ja’, ‘ko’, ‘nb’, ‘pl’, ‘pt’, ‘ru’, ‘es’, ‘sv’, ‘tr’, ‘ar’, ‘ro’, ‘sr-Cyrl’, ‘sr-Latn’, ‘sk’ to the HTTP request.

Parameters:

  • detect_orientation (Boolean)

    Whether detect the text orientation in

  • image

    An image stream.

  • language (OcrLanguages) (defaults to: nil)

    The BCP-47 language code of the text to be

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2813

def recognize_printed_text_in_stream_async(detect_orientation, image, language:nil, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'detect_orientation is nil' if detect_orientation.nil?
  fail ArgumentError, 'image is nil' if image.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/octet-stream'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = {
    client_side_validation: true,
    required: true,
    serialized_name: 'Image',
    type: {
      name: 'Stream'
    }
  }
  request_content = self.serialize(request_mapper,  image)

  path_template = 'ocr'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'detectOrientation' => detect_orientation,'language' => language},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::OcrResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#recognize_printed_text_in_stream_with_http_info(detect_orientation, image, language: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Optical Character Recognition (OCR) detects text in an image and extracts the recognized characters into a machine-usable character stream. Upon success, the OCR results will be returned. Upon failure, the error code together with an error message will be returned. The error code can be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, NotSupportedLanguage, or InternalServerError.

the image. With detectOrientation=true the OCR service tries to detect the image orientation and correct it before further processing (e.g. if it’s upside-down). detected in the image. The default value is ‘unk’. Possible values include: ‘unk’, ‘zh-Hans’, ‘zh-Hant’, ‘cs’, ‘da’, ‘nl’, ‘en’, ‘fi’, ‘fr’, ‘de’, ‘el’, ‘hu’, ‘it’, ‘ja’, ‘ko’, ‘nb’, ‘pl’, ‘pt’, ‘ru’, ‘es’, ‘sv’, ‘tr’, ‘ar’, ‘ro’, ‘sr-Cyrl’, ‘sr-Latn’, ‘sk’ will be added to the HTTP request.

Parameters:

  • detect_orientation (Boolean)

    Whether detect the text orientation in

  • image

    An image stream.

  • language (OcrLanguages) (defaults to: nil)

    The BCP-47 language code of the text to be

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



2785
2786
2787
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2785

def recognize_printed_text_in_stream_with_http_info(detect_orientation, image, language:nil, custom_headers:nil)
  recognize_printed_text_in_stream_async(detect_orientation, image, language:language, custom_headers:custom_headers).value!
end

#recognize_printed_text_with_http_info(detect_orientation, url, language: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Optical Character Recognition (OCR) detects text in an image and extracts the recognized characters into a machine-usable character stream. Upon success, the OCR results will be returned. Upon failure, the error code together with an error message will be returned. The error code can be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, NotSupportedLanguage, or InternalServerError.

the image. With detectOrientation=true the OCR service tries to detect the image orientation and correct it before further processing (e.g. if it’s upside-down). detected in the image. The default value is ‘unk’. Possible values include: ‘unk’, ‘zh-Hans’, ‘zh-Hant’, ‘cs’, ‘da’, ‘nl’, ‘en’, ‘fi’, ‘fr’, ‘de’, ‘el’, ‘hu’, ‘it’, ‘ja’, ‘ko’, ‘nb’, ‘pl’, ‘pt’, ‘ru’, ‘es’, ‘sv’, ‘tr’, ‘ar’, ‘ro’, ‘sr-Cyrl’, ‘sr-Latn’, ‘sk’ will be added to the HTTP request.

Parameters:

  • detect_orientation (Boolean)

    Whether detect the text orientation in

  • url (String)

    Publicly reachable URL of an image.

  • language (OcrLanguages) (defaults to: nil)

    The BCP-47 language code of the text to be

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



890
891
892
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 890

def recognize_printed_text_with_http_info(detect_orientation, url, language:nil, custom_headers:nil)
  recognize_printed_text_async(detect_orientation, url, language:language, custom_headers:custom_headers).value!
end

#recognize_text(url, mode, custom_headers: nil) ⇒ Object

Recognize Text operation. When you use the Recognize Text interface, the response contains a field called ‘Operation-Location’. The ‘Operation-Location’ field contains the URL that you must use for your Get Recognize Text Operation Result operation.

include: ‘Handwritten’, ‘Printed’ will be added to the HTTP request.

Parameters:

  • mode (TextRecognitionMode)

    Type of text to recognize. Possible values

  • url (String)

    Publicly reachable URL of an image.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that



1425
1426
1427
1428
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1425

def recognize_text(url, mode, custom_headers:nil)
  response = recognize_text_async(url, mode, custom_headers:custom_headers).value!
  nil
end

#recognize_text_async(url, mode, custom_headers: nil) ⇒ Concurrent::Promise

Recognize Text operation. When you use the Recognize Text interface, the response contains a field called ‘Operation-Location’. The ‘Operation-Location’ field contains the URL that you must use for your Get Recognize Text Operation Result operation.

include: ‘Handwritten’, ‘Printed’ to the HTTP request.

Parameters:

  • mode (TextRecognitionMode)

    Type of text to recognize. Possible values

  • url (String)

    Publicly reachable URL of an image.

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1462

def recognize_text_async(url, mode, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'mode is nil' if mode.nil?
  fail ArgumentError, 'url is nil' if url.nil?

  image_url = ImageUrl.new
  unless url.nil?
    image_url.url = url
  end

  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ImageUrl.mapper()
  request_content = self.serialize(request_mapper,  image_url)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'recognizeText'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'mode' => mode},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 202
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?

    result
  end

  promise.execute
end

#recognize_text_in_stream(image, mode, custom_headers: nil) ⇒ Object

Recognize Text operation. When you use the Recognize Text interface, the response contains a field called ‘Operation-Location’. The ‘Operation-Location’ field contains the URL that you must use for your Get Recognize Text Operation Result operation.

include: ‘Handwritten’, ‘Printed’ will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • mode (TextRecognitionMode)

    Type of text to recognize. Possible values

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that



3043
3044
3045
3046
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 3043

def recognize_text_in_stream(image, mode, custom_headers:nil)
  response = recognize_text_in_stream_async(image, mode, custom_headers:custom_headers).value!
  nil
end

#recognize_text_in_stream_async(image, mode, custom_headers: nil) ⇒ Concurrent::Promise

Recognize Text operation. When you use the Recognize Text interface, the response contains a field called ‘Operation-Location’. The ‘Operation-Location’ field contains the URL that you must use for your Get Recognize Text Operation Result operation.

include: ‘Handwritten’, ‘Printed’ to the HTTP request.

Parameters:

  • image

    An image stream.

  • mode (TextRecognitionMode)

    Type of text to recognize. Possible values

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 3080

def recognize_text_in_stream_async(image, mode, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'image is nil' if image.nil?
  fail ArgumentError, 'mode is nil' if mode.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/octet-stream'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = {
    client_side_validation: true,
    required: true,
    serialized_name: 'Image',
    type: {
      name: 'Stream'
    }
  }
  request_content = self.serialize(request_mapper,  image)

  path_template = 'recognizeText'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'mode' => mode},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 202
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?

    result
  end

  promise.execute
end

#recognize_text_in_stream_with_http_info(image, mode, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Recognize Text operation. When you use the Recognize Text interface, the response contains a field called ‘Operation-Location’. The ‘Operation-Location’ field contains the URL that you must use for your Get Recognize Text Operation Result operation.

include: ‘Handwritten’, ‘Printed’ will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • mode (TextRecognitionMode)

    Type of text to recognize. Possible values

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



3062
3063
3064
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 3062

def recognize_text_in_stream_with_http_info(image, mode, custom_headers:nil)
  recognize_text_in_stream_async(image, mode, custom_headers:custom_headers).value!
end

#recognize_text_with_http_info(url, mode, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Recognize Text operation. When you use the Recognize Text interface, the response contains a field called ‘Operation-Location’. The ‘Operation-Location’ field contains the URL that you must use for your Get Recognize Text Operation Result operation.

include: ‘Handwritten’, ‘Printed’ will be added to the HTTP request.

Parameters:

  • mode (TextRecognitionMode)

    Type of text to recognize. Possible values

  • url (String)

    Publicly reachable URL of an image.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



1444
1445
1446
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1444

def recognize_text_with_http_info(url, mode, custom_headers:nil)
  recognize_text_async(url, mode, custom_headers:custom_headers).value!
end

#tag_image(url, language: nil, custom_headers: nil) ⇒ TagResult

This operation generates a list of words, or tags, that are relevant to the content of the supplied image. The Computer Vision API can return tags based on objects, living beings, scenery or actions found in images. Unlike categories, tags are not organized according to a hierarchical classification system, but correspond to image content. Tags may contain hints to avoid ambiguity or provide context, for example the tag “ascomycete” may be accompanied by the hint “fungus”. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ will be added to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (TagResult)

    operation results.



1008
1009
1010
1011
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1008

def tag_image(url, language:nil, custom_headers:nil)
  response = tag_image_async(url, language:language, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#tag_image_async(url, language: nil, custom_headers: nil) ⇒ Concurrent::Promise

This operation generates a list of words, or tags, that are relevant to the content of the supplied image. The Computer Vision API can return tags based on objects, living beings, scenery or actions found in images. Unlike categories, tags are not organized according to a hierarchical classification system, but correspond to image content. Tags may contain hints to avoid ambiguity or provide context, for example the tag “ascomycete” may be accompanied by the hint “fungus”. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1067

def tag_image_async(url, language:nil, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'url is nil' if url.nil?

  image_url = ImageUrl.new
  unless url.nil?
    image_url.url = url
  end

  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::ImageUrl.mapper()
  request_content = self.serialize(request_mapper,  image_url)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'tag'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'language' => language},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::TagResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#tag_image_in_stream(image, language: nil, custom_headers: nil) ⇒ TagResult

This operation generates a list of words, or tags, that are relevant to the content of the supplied image. The Computer Vision API can return tags based on objects, living beings, scenery or actions found in images. Unlike categories, tags are not organized according to a hierarchical classification system, but correspond to image content. Tags may contain hints to avoid ambiguity or provide context, for example the tag “ascomycete” may be accompanied by the hint “fungus”. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (TagResult)

    operation results.



2905
2906
2907
2908
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2905

def tag_image_in_stream(image, language:nil, custom_headers:nil)
  response = tag_image_in_stream_async(image, language:language, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#tag_image_in_stream_async(image, language: nil, custom_headers: nil) ⇒ Concurrent::Promise

This operation generates a list of words, or tags, that are relevant to the content of the supplied image. The Computer Vision API can return tags based on objects, living beings, scenery or actions found in images. Unlike categories, tags are not organized according to a hierarchical classification system, but correspond to image content. Tags may contain hints to avoid ambiguity or provide context, for example the tag “ascomycete” may be accompanied by the hint “fungus”. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ to the HTTP request.

Parameters:

  • image

    An image stream.

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2964

def tag_image_in_stream_async(image, language:nil, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'image is nil' if image.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/octet-stream'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = {
    client_side_validation: true,
    required: true,
    serialized_name: 'Image',
    type: {
      name: 'Stream'
    }
  }
  request_content = self.serialize(request_mapper,  image)

  path_template = 'tag'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'language' => language},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ComputerVision::V2_1::Models::TagResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#tag_image_in_stream_with_http_info(image, language: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This operation generates a list of words, or tags, that are relevant to the content of the supplied image. The Computer Vision API can return tags based on objects, living beings, scenery or actions found in images. Unlike categories, tags are not organized according to a hierarchical classification system, but correspond to image content. Tags may contain hints to avoid ambiguity or provide context, for example the tag “ascomycete” may be accompanied by the hint “fungus”. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



2935
2936
2937
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 2935

def tag_image_in_stream_with_http_info(image, language:nil, custom_headers:nil)
  tag_image_in_stream_async(image, language:language, custom_headers:custom_headers).value!
end

#tag_image_with_http_info(url, language: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This operation generates a list of words, or tags, that are relevant to the content of the supplied image. The Computer Vision API can return tags based on objects, living beings, scenery or actions found in images. Unlike categories, tags are not organized according to a hierarchical classification system, but correspond to image content. Tags may contain hints to avoid ambiguity or provide context, for example the tag “ascomycete” may be accompanied by the hint “fungus”. Two input methods are supported – (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. If the request failed, the response will contain an error code and a message to help understand what went wrong.

parameter is not specified, the default value is &quot;en&quot;.Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, zh - Simplified Chinese. Possible values include: ‘en’, ‘es’, ‘ja’, ‘pt’, ‘zh’ will be added to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • language (Enum) (defaults to: nil)

    The desired language for output generation. If this

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



1038
1039
1040
# File 'lib/2.1/generated/azure_cognitiveservices_computervision/computer_vision_client.rb', line 1038

def tag_image_with_http_info(url, language:nil, custom_headers:nil)
  tag_image_async(url, language:language, custom_headers:custom_headers).value!
end