...

Source file src/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v2.1/computervision/client.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v2.1/computervision

     1  // Package computervision implements the Azure ARM Computervision service API version 2.1.
     2  //
     3  // The Computer Vision API provides state-of-the-art algorithms to process images and return information. For example,
     4  // it can be used to determine if an image contains mature content, or it can be used to find all the faces in an
     5  // image.  It also has other features like estimating dominant and accent colors, categorizing the content of images,
     6  // and describing an image with complete English sentences.  Additionally, it can also intelligently generate images
     7  // thumbnails for displaying large images effectively.
     8  package computervision
     9  
    10  // Copyright (c) Microsoft Corporation. All rights reserved.
    11  // Licensed under the MIT License. See License.txt in the project root for license information.
    12  //
    13  // Code generated by Microsoft (R) AutoRest Code Generator.
    14  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
    15  
    16  import (
    17  	"context"
    18  	"github.com/Azure/go-autorest/autorest"
    19  	"github.com/Azure/go-autorest/autorest/azure"
    20  	"github.com/Azure/go-autorest/autorest/validation"
    21  	"github.com/Azure/go-autorest/tracing"
    22  	"io"
    23  	"net/http"
    24  )
    25  
    26  // BaseClient is the base client for Computervision.
    27  type BaseClient struct {
    28  	autorest.Client
    29  	Endpoint string
    30  }
    31  
    32  // New creates an instance of the BaseClient client.
    33  func New(endpoint string) BaseClient {
    34  	return NewWithoutDefaults(endpoint)
    35  }
    36  
    37  // NewWithoutDefaults creates an instance of the BaseClient client.
    38  func NewWithoutDefaults(endpoint string) BaseClient {
    39  	return BaseClient{
    40  		Client:   autorest.NewClientWithUserAgent(UserAgent()),
    41  		Endpoint: endpoint,
    42  	}
    43  }
    44  
    45  // AnalyzeImage this operation extracts a rich set of visual features based on the image content.
    46  // Two input methods are supported -- (1) Uploading an image or (2) specifying an image URL. Within your request, there
    47  // is an optional parameter to allow you to choose which features to return. By default, image categories are returned
    48  // in the response.
    49  // A successful response will be returned in JSON. If the request failed, the response will contain an error code and a
    50  // message to help understand what went wrong.
    51  // Parameters:
    52  // imageURL - a JSON document with a URL pointing to the image that is to be analyzed.
    53  // visualFeatures - a string indicating what visual feature types to return. Multiple values should be
    54  // comma-separated. Valid visual feature types include: Categories - categorizes image content according to a
    55  // taxonomy defined in documentation. Tags - tags the image with a detailed list of words related to the image
    56  // content. Description - describes the image content with a complete English sentence. Faces - detects if
    57  // faces are present. If present, generate coordinates, gender and age. ImageType - detects if image is clipart
    58  // or a line drawing. Color - determines the accent color, dominant color, and whether an image is black&white.
    59  // Adult - detects if the image is pornographic in nature (depicts nudity or a sex act), or is gory (depicts
    60  // extreme violence or blood). Sexually suggestive content (aka racy content) is also detected. Objects -
    61  // detects various objects within an image, including the approximate location. The Objects argument is only
    62  // available in English. Brands - detects various brands within an image, including the approximate location.
    63  // The Brands argument is only available in English.
    64  // details - a string indicating which domain-specific details to return. Multiple values should be
    65  // comma-separated. Valid visual feature types include: Celebrities - identifies celebrities if detected in the
    66  // image, Landmarks - identifies notable landmarks in the image.
    67  // language - the desired language for output generation. If this parameter is not specified, the default value
    68  // is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese,
    69  // zh - Simplified Chinese.
    70  // descriptionExclude - turn off specified domain models when generating the description.
    71  func (client BaseClient) AnalyzeImage(ctx context.Context, imageURL ImageURL, visualFeatures []VisualFeatureTypes, details []Details, language string, descriptionExclude []DescriptionExclude) (result ImageAnalysis, err error) {
    72  	if tracing.IsEnabled() {
    73  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.AnalyzeImage")
    74  		defer func() {
    75  			sc := -1
    76  			if result.Response.Response != nil {
    77  				sc = result.Response.Response.StatusCode
    78  			}
    79  			tracing.EndSpan(ctx, sc, err)
    80  		}()
    81  	}
    82  	if err := validation.Validate([]validation.Validation{
    83  		{TargetValue: imageURL,
    84  			Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
    85  		return result, validation.NewError("computervision.BaseClient", "AnalyzeImage", err.Error())
    86  	}
    87  
    88  	req, err := client.AnalyzeImagePreparer(ctx, imageURL, visualFeatures, details, language, descriptionExclude)
    89  	if err != nil {
    90  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImage", nil, "Failure preparing request")
    91  		return
    92  	}
    93  
    94  	resp, err := client.AnalyzeImageSender(req)
    95  	if err != nil {
    96  		result.Response = autorest.Response{Response: resp}
    97  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImage", resp, "Failure sending request")
    98  		return
    99  	}
   100  
   101  	result, err = client.AnalyzeImageResponder(resp)
   102  	if err != nil {
   103  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImage", resp, "Failure responding to request")
   104  		return
   105  	}
   106  
   107  	return
   108  }
   109  
   110  // AnalyzeImagePreparer prepares the AnalyzeImage request.
   111  func (client BaseClient) AnalyzeImagePreparer(ctx context.Context, imageURL ImageURL, visualFeatures []VisualFeatureTypes, details []Details, language string, descriptionExclude []DescriptionExclude) (*http.Request, error) {
   112  	urlParameters := map[string]interface{}{
   113  		"Endpoint": client.Endpoint,
   114  	}
   115  
   116  	queryParameters := map[string]interface{}{}
   117  	if visualFeatures != nil && len(visualFeatures) > 0 {
   118  		queryParameters["visualFeatures"] = autorest.Encode("query", visualFeatures, ",")
   119  	}
   120  	if details != nil && len(details) > 0 {
   121  		queryParameters["details"] = autorest.Encode("query", details, ",")
   122  	}
   123  	if len(string(language)) > 0 {
   124  		queryParameters["language"] = autorest.Encode("query", language)
   125  	} else {
   126  		queryParameters["language"] = autorest.Encode("query", "en")
   127  	}
   128  	if descriptionExclude != nil && len(descriptionExclude) > 0 {
   129  		queryParameters["descriptionExclude"] = autorest.Encode("query", descriptionExclude, ",")
   130  	}
   131  
   132  	preparer := autorest.CreatePreparer(
   133  		autorest.AsContentType("application/json; charset=utf-8"),
   134  		autorest.AsPost(),
   135  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
   136  		autorest.WithPath("/analyze"),
   137  		autorest.WithJSON(imageURL),
   138  		autorest.WithQueryParameters(queryParameters))
   139  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   140  }
   141  
   142  // AnalyzeImageSender sends the AnalyzeImage request. The method will close the
   143  // http.Response Body if it receives an error.
   144  func (client BaseClient) AnalyzeImageSender(req *http.Request) (*http.Response, error) {
   145  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   146  }
   147  
   148  // AnalyzeImageResponder handles the response to the AnalyzeImage request. The method always
   149  // closes the http.Response Body.
   150  func (client BaseClient) AnalyzeImageResponder(resp *http.Response) (result ImageAnalysis, err error) {
   151  	err = autorest.Respond(
   152  		resp,
   153  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   154  		autorest.ByUnmarshallingJSON(&result),
   155  		autorest.ByClosing())
   156  	result.Response = autorest.Response{Response: resp}
   157  	return
   158  }
   159  
   160  // AnalyzeImageByDomain this operation recognizes content within an image by applying a domain-specific model. The list
   161  // of domain-specific models that are supported by the Computer Vision API can be retrieved using the /models GET
   162  // request. Currently, the API provides following domain-specific models: celebrities, landmarks.
   163  // Two input methods are supported -- (1) Uploading an image or (2) specifying an image URL.
   164  // A successful response will be returned in JSON.
   165  // If the request failed, the response will contain an error code and a message to help understand what went wrong.
   166  // Parameters:
   167  // model - the domain-specific content to recognize.
   168  // imageURL - a JSON document with a URL pointing to the image that is to be analyzed.
   169  // language - the desired language for output generation. If this parameter is not specified, the default value
   170  // is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese,
   171  // zh - Simplified Chinese.
   172  func (client BaseClient) AnalyzeImageByDomain(ctx context.Context, model string, imageURL ImageURL, language string) (result DomainModelResults, err error) {
   173  	if tracing.IsEnabled() {
   174  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.AnalyzeImageByDomain")
   175  		defer func() {
   176  			sc := -1
   177  			if result.Response.Response != nil {
   178  				sc = result.Response.Response.StatusCode
   179  			}
   180  			tracing.EndSpan(ctx, sc, err)
   181  		}()
   182  	}
   183  	if err := validation.Validate([]validation.Validation{
   184  		{TargetValue: imageURL,
   185  			Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   186  		return result, validation.NewError("computervision.BaseClient", "AnalyzeImageByDomain", err.Error())
   187  	}
   188  
   189  	req, err := client.AnalyzeImageByDomainPreparer(ctx, model, imageURL, language)
   190  	if err != nil {
   191  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageByDomain", nil, "Failure preparing request")
   192  		return
   193  	}
   194  
   195  	resp, err := client.AnalyzeImageByDomainSender(req)
   196  	if err != nil {
   197  		result.Response = autorest.Response{Response: resp}
   198  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageByDomain", resp, "Failure sending request")
   199  		return
   200  	}
   201  
   202  	result, err = client.AnalyzeImageByDomainResponder(resp)
   203  	if err != nil {
   204  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageByDomain", resp, "Failure responding to request")
   205  		return
   206  	}
   207  
   208  	return
   209  }
   210  
   211  // AnalyzeImageByDomainPreparer prepares the AnalyzeImageByDomain request.
   212  func (client BaseClient) AnalyzeImageByDomainPreparer(ctx context.Context, model string, imageURL ImageURL, language string) (*http.Request, error) {
   213  	urlParameters := map[string]interface{}{
   214  		"Endpoint": client.Endpoint,
   215  	}
   216  
   217  	pathParameters := map[string]interface{}{
   218  		"model": autorest.Encode("path", model),
   219  	}
   220  
   221  	queryParameters := map[string]interface{}{}
   222  	if len(string(language)) > 0 {
   223  		queryParameters["language"] = autorest.Encode("query", language)
   224  	} else {
   225  		queryParameters["language"] = autorest.Encode("query", "en")
   226  	}
   227  
   228  	preparer := autorest.CreatePreparer(
   229  		autorest.AsContentType("application/json; charset=utf-8"),
   230  		autorest.AsPost(),
   231  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
   232  		autorest.WithPathParameters("/models/{model}/analyze", pathParameters),
   233  		autorest.WithJSON(imageURL),
   234  		autorest.WithQueryParameters(queryParameters))
   235  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   236  }
   237  
   238  // AnalyzeImageByDomainSender sends the AnalyzeImageByDomain request. The method will close the
   239  // http.Response Body if it receives an error.
   240  func (client BaseClient) AnalyzeImageByDomainSender(req *http.Request) (*http.Response, error) {
   241  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   242  }
   243  
   244  // AnalyzeImageByDomainResponder handles the response to the AnalyzeImageByDomain request. The method always
   245  // closes the http.Response Body.
   246  func (client BaseClient) AnalyzeImageByDomainResponder(resp *http.Response) (result DomainModelResults, err error) {
   247  	err = autorest.Respond(
   248  		resp,
   249  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   250  		autorest.ByUnmarshallingJSON(&result),
   251  		autorest.ByClosing())
   252  	result.Response = autorest.Response{Response: resp}
   253  	return
   254  }
   255  
   256  // AnalyzeImageByDomainInStream this operation recognizes content within an image by applying a domain-specific model.
   257  // The list of domain-specific models that are supported by the Computer Vision API can be retrieved using the /models
   258  // GET request. Currently, the API provides following domain-specific models: celebrities, landmarks.
   259  // Two input methods are supported -- (1) Uploading an image or (2) specifying an image URL.
   260  // A successful response will be returned in JSON.
   261  // If the request failed, the response will contain an error code and a message to help understand what went wrong.
   262  // Parameters:
   263  // model - the domain-specific content to recognize.
   264  // imageParameter - an image stream.
   265  // language - the desired language for output generation. If this parameter is not specified, the default value
   266  // is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese,
   267  // zh - Simplified Chinese.
   268  func (client BaseClient) AnalyzeImageByDomainInStream(ctx context.Context, model string, imageParameter io.ReadCloser, language string) (result DomainModelResults, err error) {
   269  	if tracing.IsEnabled() {
   270  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.AnalyzeImageByDomainInStream")
   271  		defer func() {
   272  			sc := -1
   273  			if result.Response.Response != nil {
   274  				sc = result.Response.Response.StatusCode
   275  			}
   276  			tracing.EndSpan(ctx, sc, err)
   277  		}()
   278  	}
   279  	req, err := client.AnalyzeImageByDomainInStreamPreparer(ctx, model, imageParameter, language)
   280  	if err != nil {
   281  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageByDomainInStream", nil, "Failure preparing request")
   282  		return
   283  	}
   284  
   285  	resp, err := client.AnalyzeImageByDomainInStreamSender(req)
   286  	if err != nil {
   287  		result.Response = autorest.Response{Response: resp}
   288  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageByDomainInStream", resp, "Failure sending request")
   289  		return
   290  	}
   291  
   292  	result, err = client.AnalyzeImageByDomainInStreamResponder(resp)
   293  	if err != nil {
   294  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageByDomainInStream", resp, "Failure responding to request")
   295  		return
   296  	}
   297  
   298  	return
   299  }
   300  
   301  // AnalyzeImageByDomainInStreamPreparer prepares the AnalyzeImageByDomainInStream request.
   302  func (client BaseClient) AnalyzeImageByDomainInStreamPreparer(ctx context.Context, model string, imageParameter io.ReadCloser, language string) (*http.Request, error) {
   303  	urlParameters := map[string]interface{}{
   304  		"Endpoint": client.Endpoint,
   305  	}
   306  
   307  	pathParameters := map[string]interface{}{
   308  		"model": autorest.Encode("path", model),
   309  	}
   310  
   311  	queryParameters := map[string]interface{}{}
   312  	if len(string(language)) > 0 {
   313  		queryParameters["language"] = autorest.Encode("query", language)
   314  	} else {
   315  		queryParameters["language"] = autorest.Encode("query", "en")
   316  	}
   317  
   318  	preparer := autorest.CreatePreparer(
   319  		autorest.AsContentType("application/octet-stream"),
   320  		autorest.AsPost(),
   321  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
   322  		autorest.WithPathParameters("/models/{model}/analyze", pathParameters),
   323  		autorest.WithFile(imageParameter),
   324  		autorest.WithQueryParameters(queryParameters))
   325  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   326  }
   327  
   328  // AnalyzeImageByDomainInStreamSender sends the AnalyzeImageByDomainInStream request. The method will close the
   329  // http.Response Body if it receives an error.
   330  func (client BaseClient) AnalyzeImageByDomainInStreamSender(req *http.Request) (*http.Response, error) {
   331  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   332  }
   333  
   334  // AnalyzeImageByDomainInStreamResponder handles the response to the AnalyzeImageByDomainInStream request. The method always
   335  // closes the http.Response Body.
   336  func (client BaseClient) AnalyzeImageByDomainInStreamResponder(resp *http.Response) (result DomainModelResults, err error) {
   337  	err = autorest.Respond(
   338  		resp,
   339  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   340  		autorest.ByUnmarshallingJSON(&result),
   341  		autorest.ByClosing())
   342  	result.Response = autorest.Response{Response: resp}
   343  	return
   344  }
   345  
   346  // AnalyzeImageInStream this operation extracts a rich set of visual features based on the image content.
   347  // Two input methods are supported -- (1) Uploading an image or (2) specifying an image URL. Within your request, there
   348  // is an optional parameter to allow you to choose which features to return. By default, image categories are returned
   349  // in the response.
   350  // A successful response will be returned in JSON. If the request failed, the response will contain an error code and a
   351  // message to help understand what went wrong.
   352  // Parameters:
   353  // imageParameter - an image stream.
   354  // visualFeatures - a string indicating what visual feature types to return. Multiple values should be
   355  // comma-separated. Valid visual feature types include: Categories - categorizes image content according to a
   356  // taxonomy defined in documentation. Tags - tags the image with a detailed list of words related to the image
   357  // content. Description - describes the image content with a complete English sentence. Faces - detects if
   358  // faces are present. If present, generate coordinates, gender and age. ImageType - detects if image is clipart
   359  // or a line drawing. Color - determines the accent color, dominant color, and whether an image is black&white.
   360  // Adult - detects if the image is pornographic in nature (depicts nudity or a sex act), or is gory (depicts
   361  // extreme violence or blood). Sexually suggestive content (aka racy content) is also detected. Objects -
   362  // detects various objects within an image, including the approximate location. The Objects argument is only
   363  // available in English. Brands - detects various brands within an image, including the approximate location.
   364  // The Brands argument is only available in English.
   365  // details - a string indicating which domain-specific details to return. Multiple values should be
   366  // comma-separated. Valid visual feature types include: Celebrities - identifies celebrities if detected in the
   367  // image, Landmarks - identifies notable landmarks in the image.
   368  // language - the desired language for output generation. If this parameter is not specified, the default value
   369  // is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese,
   370  // zh - Simplified Chinese.
   371  // descriptionExclude - turn off specified domain models when generating the description.
   372  func (client BaseClient) AnalyzeImageInStream(ctx context.Context, imageParameter io.ReadCloser, visualFeatures []VisualFeatureTypes, details []Details, language string, descriptionExclude []DescriptionExclude) (result ImageAnalysis, err error) {
   373  	if tracing.IsEnabled() {
   374  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.AnalyzeImageInStream")
   375  		defer func() {
   376  			sc := -1
   377  			if result.Response.Response != nil {
   378  				sc = result.Response.Response.StatusCode
   379  			}
   380  			tracing.EndSpan(ctx, sc, err)
   381  		}()
   382  	}
   383  	req, err := client.AnalyzeImageInStreamPreparer(ctx, imageParameter, visualFeatures, details, language, descriptionExclude)
   384  	if err != nil {
   385  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageInStream", nil, "Failure preparing request")
   386  		return
   387  	}
   388  
   389  	resp, err := client.AnalyzeImageInStreamSender(req)
   390  	if err != nil {
   391  		result.Response = autorest.Response{Response: resp}
   392  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageInStream", resp, "Failure sending request")
   393  		return
   394  	}
   395  
   396  	result, err = client.AnalyzeImageInStreamResponder(resp)
   397  	if err != nil {
   398  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageInStream", resp, "Failure responding to request")
   399  		return
   400  	}
   401  
   402  	return
   403  }
   404  
   405  // AnalyzeImageInStreamPreparer prepares the AnalyzeImageInStream request.
   406  func (client BaseClient) AnalyzeImageInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser, visualFeatures []VisualFeatureTypes, details []Details, language string, descriptionExclude []DescriptionExclude) (*http.Request, error) {
   407  	urlParameters := map[string]interface{}{
   408  		"Endpoint": client.Endpoint,
   409  	}
   410  
   411  	queryParameters := map[string]interface{}{}
   412  	if visualFeatures != nil && len(visualFeatures) > 0 {
   413  		queryParameters["visualFeatures"] = autorest.Encode("query", visualFeatures, ",")
   414  	}
   415  	if details != nil && len(details) > 0 {
   416  		queryParameters["details"] = autorest.Encode("query", details, ",")
   417  	}
   418  	if len(string(language)) > 0 {
   419  		queryParameters["language"] = autorest.Encode("query", language)
   420  	} else {
   421  		queryParameters["language"] = autorest.Encode("query", "en")
   422  	}
   423  	if descriptionExclude != nil && len(descriptionExclude) > 0 {
   424  		queryParameters["descriptionExclude"] = autorest.Encode("query", descriptionExclude, ",")
   425  	}
   426  
   427  	preparer := autorest.CreatePreparer(
   428  		autorest.AsContentType("application/octet-stream"),
   429  		autorest.AsPost(),
   430  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
   431  		autorest.WithPath("/analyze"),
   432  		autorest.WithFile(imageParameter),
   433  		autorest.WithQueryParameters(queryParameters))
   434  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   435  }
   436  
   437  // AnalyzeImageInStreamSender sends the AnalyzeImageInStream request. The method will close the
   438  // http.Response Body if it receives an error.
   439  func (client BaseClient) AnalyzeImageInStreamSender(req *http.Request) (*http.Response, error) {
   440  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   441  }
   442  
   443  // AnalyzeImageInStreamResponder handles the response to the AnalyzeImageInStream request. The method always
   444  // closes the http.Response Body.
   445  func (client BaseClient) AnalyzeImageInStreamResponder(resp *http.Response) (result ImageAnalysis, err error) {
   446  	err = autorest.Respond(
   447  		resp,
   448  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   449  		autorest.ByUnmarshallingJSON(&result),
   450  		autorest.ByClosing())
   451  	result.Response = autorest.Response{Response: resp}
   452  	return
   453  }
   454  
   455  // BatchReadFile use this interface to get the result of a Read operation, employing the state-of-the-art Optical
   456  // Character Recognition (OCR) algorithms optimized for text-heavy documents. When you use the Read File interface, the
   457  // response contains a field called 'Operation-Location'. The 'Operation-Location' field contains the URL that you must
   458  // use for your 'GetReadOperationResult' operation to access OCR results.​
   459  // Parameters:
   460  // imageURL - a JSON document with a URL pointing to the image that is to be analyzed.
   461  func (client BaseClient) BatchReadFile(ctx context.Context, imageURL ImageURL) (result autorest.Response, err error) {
   462  	if tracing.IsEnabled() {
   463  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.BatchReadFile")
   464  		defer func() {
   465  			sc := -1
   466  			if result.Response != nil {
   467  				sc = result.Response.StatusCode
   468  			}
   469  			tracing.EndSpan(ctx, sc, err)
   470  		}()
   471  	}
   472  	if err := validation.Validate([]validation.Validation{
   473  		{TargetValue: imageURL,
   474  			Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   475  		return result, validation.NewError("computervision.BaseClient", "BatchReadFile", err.Error())
   476  	}
   477  
   478  	req, err := client.BatchReadFilePreparer(ctx, imageURL)
   479  	if err != nil {
   480  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "BatchReadFile", nil, "Failure preparing request")
   481  		return
   482  	}
   483  
   484  	resp, err := client.BatchReadFileSender(req)
   485  	if err != nil {
   486  		result.Response = resp
   487  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "BatchReadFile", resp, "Failure sending request")
   488  		return
   489  	}
   490  
   491  	result, err = client.BatchReadFileResponder(resp)
   492  	if err != nil {
   493  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "BatchReadFile", resp, "Failure responding to request")
   494  		return
   495  	}
   496  
   497  	return
   498  }
   499  
   500  // BatchReadFilePreparer prepares the BatchReadFile request.
   501  func (client BaseClient) BatchReadFilePreparer(ctx context.Context, imageURL ImageURL) (*http.Request, error) {
   502  	urlParameters := map[string]interface{}{
   503  		"Endpoint": client.Endpoint,
   504  	}
   505  
   506  	preparer := autorest.CreatePreparer(
   507  		autorest.AsContentType("application/json; charset=utf-8"),
   508  		autorest.AsPost(),
   509  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
   510  		autorest.WithPath("/read/core/asyncBatchAnalyze"),
   511  		autorest.WithJSON(imageURL))
   512  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   513  }
   514  
   515  // BatchReadFileSender sends the BatchReadFile request. The method will close the
   516  // http.Response Body if it receives an error.
   517  func (client BaseClient) BatchReadFileSender(req *http.Request) (*http.Response, error) {
   518  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   519  }
   520  
   521  // BatchReadFileResponder handles the response to the BatchReadFile request. The method always
   522  // closes the http.Response Body.
   523  func (client BaseClient) BatchReadFileResponder(resp *http.Response) (result autorest.Response, err error) {
   524  	err = autorest.Respond(
   525  		resp,
   526  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   527  		autorest.ByClosing())
   528  	result.Response = resp
   529  	return
   530  }
   531  
   532  // BatchReadFileInStream use this interface to get the result of a Read Document operation, employing the
   533  // state-of-the-art Optical Character Recognition (OCR) algorithms optimized for text-heavy documents. When you use the
   534  // Read Document interface, the response contains a field called 'Operation-Location'. The 'Operation-Location' field
   535  // contains the URL that you must use for your 'Get Read Result operation' to access OCR results.​
   536  // Parameters:
   537  // imageParameter - an image stream.
   538  func (client BaseClient) BatchReadFileInStream(ctx context.Context, imageParameter io.ReadCloser) (result autorest.Response, err error) {
   539  	if tracing.IsEnabled() {
   540  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.BatchReadFileInStream")
   541  		defer func() {
   542  			sc := -1
   543  			if result.Response != nil {
   544  				sc = result.Response.StatusCode
   545  			}
   546  			tracing.EndSpan(ctx, sc, err)
   547  		}()
   548  	}
   549  	req, err := client.BatchReadFileInStreamPreparer(ctx, imageParameter)
   550  	if err != nil {
   551  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "BatchReadFileInStream", nil, "Failure preparing request")
   552  		return
   553  	}
   554  
   555  	resp, err := client.BatchReadFileInStreamSender(req)
   556  	if err != nil {
   557  		result.Response = resp
   558  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "BatchReadFileInStream", resp, "Failure sending request")
   559  		return
   560  	}
   561  
   562  	result, err = client.BatchReadFileInStreamResponder(resp)
   563  	if err != nil {
   564  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "BatchReadFileInStream", resp, "Failure responding to request")
   565  		return
   566  	}
   567  
   568  	return
   569  }
   570  
   571  // BatchReadFileInStreamPreparer prepares the BatchReadFileInStream request.
   572  func (client BaseClient) BatchReadFileInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser) (*http.Request, error) {
   573  	urlParameters := map[string]interface{}{
   574  		"Endpoint": client.Endpoint,
   575  	}
   576  
   577  	preparer := autorest.CreatePreparer(
   578  		autorest.AsContentType("application/octet-stream"),
   579  		autorest.AsPost(),
   580  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
   581  		autorest.WithPath("/read/core/asyncBatchAnalyze"),
   582  		autorest.WithFile(imageParameter))
   583  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   584  }
   585  
   586  // BatchReadFileInStreamSender sends the BatchReadFileInStream request. The method will close the
   587  // http.Response Body if it receives an error.
   588  func (client BaseClient) BatchReadFileInStreamSender(req *http.Request) (*http.Response, error) {
   589  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   590  }
   591  
   592  // BatchReadFileInStreamResponder handles the response to the BatchReadFileInStream request. The method always
   593  // closes the http.Response Body.
   594  func (client BaseClient) BatchReadFileInStreamResponder(resp *http.Response) (result autorest.Response, err error) {
   595  	err = autorest.Respond(
   596  		resp,
   597  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   598  		autorest.ByClosing())
   599  	result.Response = resp
   600  	return
   601  }
   602  
   603  // DescribeImage this operation generates a description of an image in human readable language with complete sentences.
   604  // The description is based on a collection of content tags, which are also returned by the operation. More than one
   605  // description can be generated for each image. Descriptions are ordered by their confidence score. Descriptions may
   606  // include results from celebrity and landmark domain models, if applicable.
   607  // Two input methods are supported -- (1) Uploading an image or (2) specifying an image URL.
   608  // A successful response will be returned in JSON. If the request failed, the response will contain an error code and a
   609  // message to help understand what went wrong.
   610  // Parameters:
   611  // imageURL - a JSON document with a URL pointing to the image that is to be analyzed.
   612  // maxCandidates - maximum number of candidate descriptions to be returned.  The default is 1.
   613  // language - the desired language for output generation. If this parameter is not specified, the default value
   614  // is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese,
   615  // zh - Simplified Chinese.
   616  // descriptionExclude - turn off specified domain models when generating the description.
   617  func (client BaseClient) DescribeImage(ctx context.Context, imageURL ImageURL, maxCandidates *int32, language string, descriptionExclude []DescriptionExclude) (result ImageDescription, err error) {
   618  	if tracing.IsEnabled() {
   619  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.DescribeImage")
   620  		defer func() {
   621  			sc := -1
   622  			if result.Response.Response != nil {
   623  				sc = result.Response.Response.StatusCode
   624  			}
   625  			tracing.EndSpan(ctx, sc, err)
   626  		}()
   627  	}
   628  	if err := validation.Validate([]validation.Validation{
   629  		{TargetValue: imageURL,
   630  			Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   631  		return result, validation.NewError("computervision.BaseClient", "DescribeImage", err.Error())
   632  	}
   633  
   634  	req, err := client.DescribeImagePreparer(ctx, imageURL, maxCandidates, language, descriptionExclude)
   635  	if err != nil {
   636  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DescribeImage", nil, "Failure preparing request")
   637  		return
   638  	}
   639  
   640  	resp, err := client.DescribeImageSender(req)
   641  	if err != nil {
   642  		result.Response = autorest.Response{Response: resp}
   643  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DescribeImage", resp, "Failure sending request")
   644  		return
   645  	}
   646  
   647  	result, err = client.DescribeImageResponder(resp)
   648  	if err != nil {
   649  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DescribeImage", resp, "Failure responding to request")
   650  		return
   651  	}
   652  
   653  	return
   654  }
   655  
   656  // DescribeImagePreparer prepares the DescribeImage request.
   657  func (client BaseClient) DescribeImagePreparer(ctx context.Context, imageURL ImageURL, maxCandidates *int32, language string, descriptionExclude []DescriptionExclude) (*http.Request, error) {
   658  	urlParameters := map[string]interface{}{
   659  		"Endpoint": client.Endpoint,
   660  	}
   661  
   662  	queryParameters := map[string]interface{}{}
   663  	if maxCandidates != nil {
   664  		queryParameters["maxCandidates"] = autorest.Encode("query", *maxCandidates)
   665  	} else {
   666  		queryParameters["maxCandidates"] = autorest.Encode("query", 1)
   667  	}
   668  	if len(string(language)) > 0 {
   669  		queryParameters["language"] = autorest.Encode("query", language)
   670  	} else {
   671  		queryParameters["language"] = autorest.Encode("query", "en")
   672  	}
   673  	if descriptionExclude != nil && len(descriptionExclude) > 0 {
   674  		queryParameters["descriptionExclude"] = autorest.Encode("query", descriptionExclude, ",")
   675  	}
   676  
   677  	preparer := autorest.CreatePreparer(
   678  		autorest.AsContentType("application/json; charset=utf-8"),
   679  		autorest.AsPost(),
   680  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
   681  		autorest.WithPath("/describe"),
   682  		autorest.WithJSON(imageURL),
   683  		autorest.WithQueryParameters(queryParameters))
   684  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   685  }
   686  
   687  // DescribeImageSender sends the DescribeImage request. The method will close the
   688  // http.Response Body if it receives an error.
   689  func (client BaseClient) DescribeImageSender(req *http.Request) (*http.Response, error) {
   690  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   691  }
   692  
   693  // DescribeImageResponder handles the response to the DescribeImage request. The method always
   694  // closes the http.Response Body.
   695  func (client BaseClient) DescribeImageResponder(resp *http.Response) (result ImageDescription, err error) {
   696  	err = autorest.Respond(
   697  		resp,
   698  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   699  		autorest.ByUnmarshallingJSON(&result),
   700  		autorest.ByClosing())
   701  	result.Response = autorest.Response{Response: resp}
   702  	return
   703  }
   704  
   705  // DescribeImageInStream this operation generates a description of an image in human readable language with complete
   706  // sentences. The description is based on a collection of content tags, which are also returned by the operation. More
   707  // than one description can be generated for each image. Descriptions are ordered by their confidence score.
   708  // Descriptions may include results from celebrity and landmark domain models, if applicable.
   709  // Two input methods are supported -- (1) Uploading an image or (2) specifying an image URL.
   710  // A successful response will be returned in JSON. If the request failed, the response will contain an error code and a
   711  // message to help understand what went wrong.
   712  // Parameters:
   713  // imageParameter - an image stream.
   714  // maxCandidates - maximum number of candidate descriptions to be returned.  The default is 1.
   715  // language - the desired language for output generation. If this parameter is not specified, the default value
   716  // is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese,
   717  // zh - Simplified Chinese.
   718  // descriptionExclude - turn off specified domain models when generating the description.
   719  func (client BaseClient) DescribeImageInStream(ctx context.Context, imageParameter io.ReadCloser, maxCandidates *int32, language string, descriptionExclude []DescriptionExclude) (result ImageDescription, err error) {
   720  	if tracing.IsEnabled() {
   721  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.DescribeImageInStream")
   722  		defer func() {
   723  			sc := -1
   724  			if result.Response.Response != nil {
   725  				sc = result.Response.Response.StatusCode
   726  			}
   727  			tracing.EndSpan(ctx, sc, err)
   728  		}()
   729  	}
   730  	req, err := client.DescribeImageInStreamPreparer(ctx, imageParameter, maxCandidates, language, descriptionExclude)
   731  	if err != nil {
   732  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DescribeImageInStream", nil, "Failure preparing request")
   733  		return
   734  	}
   735  
   736  	resp, err := client.DescribeImageInStreamSender(req)
   737  	if err != nil {
   738  		result.Response = autorest.Response{Response: resp}
   739  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DescribeImageInStream", resp, "Failure sending request")
   740  		return
   741  	}
   742  
   743  	result, err = client.DescribeImageInStreamResponder(resp)
   744  	if err != nil {
   745  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DescribeImageInStream", resp, "Failure responding to request")
   746  		return
   747  	}
   748  
   749  	return
   750  }
   751  
   752  // DescribeImageInStreamPreparer prepares the DescribeImageInStream request.
   753  func (client BaseClient) DescribeImageInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser, maxCandidates *int32, language string, descriptionExclude []DescriptionExclude) (*http.Request, error) {
   754  	urlParameters := map[string]interface{}{
   755  		"Endpoint": client.Endpoint,
   756  	}
   757  
   758  	queryParameters := map[string]interface{}{}
   759  	if maxCandidates != nil {
   760  		queryParameters["maxCandidates"] = autorest.Encode("query", *maxCandidates)
   761  	} else {
   762  		queryParameters["maxCandidates"] = autorest.Encode("query", 1)
   763  	}
   764  	if len(string(language)) > 0 {
   765  		queryParameters["language"] = autorest.Encode("query", language)
   766  	} else {
   767  		queryParameters["language"] = autorest.Encode("query", "en")
   768  	}
   769  	if descriptionExclude != nil && len(descriptionExclude) > 0 {
   770  		queryParameters["descriptionExclude"] = autorest.Encode("query", descriptionExclude, ",")
   771  	}
   772  
   773  	preparer := autorest.CreatePreparer(
   774  		autorest.AsContentType("application/octet-stream"),
   775  		autorest.AsPost(),
   776  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
   777  		autorest.WithPath("/describe"),
   778  		autorest.WithFile(imageParameter),
   779  		autorest.WithQueryParameters(queryParameters))
   780  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   781  }
   782  
   783  // DescribeImageInStreamSender sends the DescribeImageInStream request. The method will close the
   784  // http.Response Body if it receives an error.
   785  func (client BaseClient) DescribeImageInStreamSender(req *http.Request) (*http.Response, error) {
   786  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   787  }
   788  
   789  // DescribeImageInStreamResponder handles the response to the DescribeImageInStream request. The method always
   790  // closes the http.Response Body.
   791  func (client BaseClient) DescribeImageInStreamResponder(resp *http.Response) (result ImageDescription, err error) {
   792  	err = autorest.Respond(
   793  		resp,
   794  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   795  		autorest.ByUnmarshallingJSON(&result),
   796  		autorest.ByClosing())
   797  	result.Response = autorest.Response{Response: resp}
   798  	return
   799  }
   800  
   801  // DetectObjects performs object detection on the specified image.
   802  // Two input methods are supported -- (1) Uploading an image or (2) specifying an image URL.
   803  // A successful response will be returned in JSON. If the request failed, the response will contain an error code and a
   804  // message to help understand what went wrong.
   805  // Parameters:
   806  // imageURL - a JSON document with a URL pointing to the image that is to be analyzed.
   807  func (client BaseClient) DetectObjects(ctx context.Context, imageURL ImageURL) (result DetectResult, err error) {
   808  	if tracing.IsEnabled() {
   809  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.DetectObjects")
   810  		defer func() {
   811  			sc := -1
   812  			if result.Response.Response != nil {
   813  				sc = result.Response.Response.StatusCode
   814  			}
   815  			tracing.EndSpan(ctx, sc, err)
   816  		}()
   817  	}
   818  	if err := validation.Validate([]validation.Validation{
   819  		{TargetValue: imageURL,
   820  			Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   821  		return result, validation.NewError("computervision.BaseClient", "DetectObjects", err.Error())
   822  	}
   823  
   824  	req, err := client.DetectObjectsPreparer(ctx, imageURL)
   825  	if err != nil {
   826  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DetectObjects", nil, "Failure preparing request")
   827  		return
   828  	}
   829  
   830  	resp, err := client.DetectObjectsSender(req)
   831  	if err != nil {
   832  		result.Response = autorest.Response{Response: resp}
   833  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DetectObjects", resp, "Failure sending request")
   834  		return
   835  	}
   836  
   837  	result, err = client.DetectObjectsResponder(resp)
   838  	if err != nil {
   839  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DetectObjects", resp, "Failure responding to request")
   840  		return
   841  	}
   842  
   843  	return
   844  }
   845  
   846  // DetectObjectsPreparer prepares the DetectObjects request.
   847  func (client BaseClient) DetectObjectsPreparer(ctx context.Context, imageURL ImageURL) (*http.Request, error) {
   848  	urlParameters := map[string]interface{}{
   849  		"Endpoint": client.Endpoint,
   850  	}
   851  
   852  	preparer := autorest.CreatePreparer(
   853  		autorest.AsContentType("application/json; charset=utf-8"),
   854  		autorest.AsPost(),
   855  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
   856  		autorest.WithPath("/detect"),
   857  		autorest.WithJSON(imageURL))
   858  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   859  }
   860  
   861  // DetectObjectsSender sends the DetectObjects request. The method will close the
   862  // http.Response Body if it receives an error.
   863  func (client BaseClient) DetectObjectsSender(req *http.Request) (*http.Response, error) {
   864  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   865  }
   866  
   867  // DetectObjectsResponder handles the response to the DetectObjects request. The method always
   868  // closes the http.Response Body.
   869  func (client BaseClient) DetectObjectsResponder(resp *http.Response) (result DetectResult, err error) {
   870  	err = autorest.Respond(
   871  		resp,
   872  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   873  		autorest.ByUnmarshallingJSON(&result),
   874  		autorest.ByClosing())
   875  	result.Response = autorest.Response{Response: resp}
   876  	return
   877  }
   878  
   879  // DetectObjectsInStream performs object detection on the specified image.
   880  // Two input methods are supported -- (1) Uploading an image or (2) specifying an image URL.
   881  // A successful response will be returned in JSON. If the request failed, the response will contain an error code and a
   882  // message to help understand what went wrong.
   883  // Parameters:
   884  // imageParameter - an image stream.
   885  func (client BaseClient) DetectObjectsInStream(ctx context.Context, imageParameter io.ReadCloser) (result DetectResult, err error) {
   886  	if tracing.IsEnabled() {
   887  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.DetectObjectsInStream")
   888  		defer func() {
   889  			sc := -1
   890  			if result.Response.Response != nil {
   891  				sc = result.Response.Response.StatusCode
   892  			}
   893  			tracing.EndSpan(ctx, sc, err)
   894  		}()
   895  	}
   896  	req, err := client.DetectObjectsInStreamPreparer(ctx, imageParameter)
   897  	if err != nil {
   898  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DetectObjectsInStream", nil, "Failure preparing request")
   899  		return
   900  	}
   901  
   902  	resp, err := client.DetectObjectsInStreamSender(req)
   903  	if err != nil {
   904  		result.Response = autorest.Response{Response: resp}
   905  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DetectObjectsInStream", resp, "Failure sending request")
   906  		return
   907  	}
   908  
   909  	result, err = client.DetectObjectsInStreamResponder(resp)
   910  	if err != nil {
   911  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DetectObjectsInStream", resp, "Failure responding to request")
   912  		return
   913  	}
   914  
   915  	return
   916  }
   917  
   918  // DetectObjectsInStreamPreparer prepares the DetectObjectsInStream request.
   919  func (client BaseClient) DetectObjectsInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser) (*http.Request, error) {
   920  	urlParameters := map[string]interface{}{
   921  		"Endpoint": client.Endpoint,
   922  	}
   923  
   924  	preparer := autorest.CreatePreparer(
   925  		autorest.AsContentType("application/octet-stream"),
   926  		autorest.AsPost(),
   927  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
   928  		autorest.WithPath("/detect"),
   929  		autorest.WithFile(imageParameter))
   930  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   931  }
   932  
   933  // DetectObjectsInStreamSender sends the DetectObjectsInStream request. The method will close the
   934  // http.Response Body if it receives an error.
   935  func (client BaseClient) DetectObjectsInStreamSender(req *http.Request) (*http.Response, error) {
   936  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   937  }
   938  
   939  // DetectObjectsInStreamResponder handles the response to the DetectObjectsInStream request. The method always
   940  // closes the http.Response Body.
   941  func (client BaseClient) DetectObjectsInStreamResponder(resp *http.Response) (result DetectResult, err error) {
   942  	err = autorest.Respond(
   943  		resp,
   944  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   945  		autorest.ByUnmarshallingJSON(&result),
   946  		autorest.ByClosing())
   947  	result.Response = autorest.Response{Response: resp}
   948  	return
   949  }
   950  
   951  // GenerateThumbnail this operation generates a thumbnail image with the user-specified width and height. By default,
   952  // the service analyzes the image, identifies the region of interest (ROI), and generates smart cropping coordinates
   953  // based on the ROI. Smart cropping helps when you specify an aspect ratio that differs from that of the input image.
   954  // A successful response contains the thumbnail image binary. If the request failed, the response contains an error
   955  // code and a message to help determine what went wrong.
   956  // Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl,
   957  // InvalidImageFormat, InvalidImageSize, InvalidThumbnailSize, NotSupportedImage, FailedToProcess, Timeout, or
   958  // InternalServerError.
   959  // Parameters:
   960  // width - width of the thumbnail, in pixels. It must be between 1 and 1024. Recommended minimum of 50.
   961  // height - height of the thumbnail, in pixels. It must be between 1 and 1024. Recommended minimum of 50.
   962  // imageURL - a JSON document with a URL pointing to the image that is to be analyzed.
   963  // smartCropping - boolean flag for enabling smart cropping.
   964  func (client BaseClient) GenerateThumbnail(ctx context.Context, width int32, height int32, imageURL ImageURL, smartCropping *bool) (result ReadCloser, err error) {
   965  	if tracing.IsEnabled() {
   966  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GenerateThumbnail")
   967  		defer func() {
   968  			sc := -1
   969  			if result.Response.Response != nil {
   970  				sc = result.Response.Response.StatusCode
   971  			}
   972  			tracing.EndSpan(ctx, sc, err)
   973  		}()
   974  	}
   975  	if err := validation.Validate([]validation.Validation{
   976  		{TargetValue: width,
   977  			Constraints: []validation.Constraint{{Target: "width", Name: validation.InclusiveMaximum, Rule: int64(1024), Chain: nil},
   978  				{Target: "width", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}},
   979  		{TargetValue: height,
   980  			Constraints: []validation.Constraint{{Target: "height", Name: validation.InclusiveMaximum, Rule: int64(1024), Chain: nil},
   981  				{Target: "height", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}},
   982  		{TargetValue: imageURL,
   983  			Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   984  		return result, validation.NewError("computervision.BaseClient", "GenerateThumbnail", err.Error())
   985  	}
   986  
   987  	req, err := client.GenerateThumbnailPreparer(ctx, width, height, imageURL, smartCropping)
   988  	if err != nil {
   989  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GenerateThumbnail", nil, "Failure preparing request")
   990  		return
   991  	}
   992  
   993  	resp, err := client.GenerateThumbnailSender(req)
   994  	if err != nil {
   995  		result.Response = autorest.Response{Response: resp}
   996  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GenerateThumbnail", resp, "Failure sending request")
   997  		return
   998  	}
   999  
  1000  	result, err = client.GenerateThumbnailResponder(resp)
  1001  	if err != nil {
  1002  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GenerateThumbnail", resp, "Failure responding to request")
  1003  		return
  1004  	}
  1005  
  1006  	return
  1007  }
  1008  
  1009  // GenerateThumbnailPreparer prepares the GenerateThumbnail request.
  1010  func (client BaseClient) GenerateThumbnailPreparer(ctx context.Context, width int32, height int32, imageURL ImageURL, smartCropping *bool) (*http.Request, error) {
  1011  	urlParameters := map[string]interface{}{
  1012  		"Endpoint": client.Endpoint,
  1013  	}
  1014  
  1015  	queryParameters := map[string]interface{}{
  1016  		"height": autorest.Encode("query", height),
  1017  		"width":  autorest.Encode("query", width),
  1018  	}
  1019  	if smartCropping != nil {
  1020  		queryParameters["smartCropping"] = autorest.Encode("query", *smartCropping)
  1021  	} else {
  1022  		queryParameters["smartCropping"] = autorest.Encode("query", false)
  1023  	}
  1024  
  1025  	preparer := autorest.CreatePreparer(
  1026  		autorest.AsContentType("application/json; charset=utf-8"),
  1027  		autorest.AsPost(),
  1028  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
  1029  		autorest.WithPath("/generateThumbnail"),
  1030  		autorest.WithJSON(imageURL),
  1031  		autorest.WithQueryParameters(queryParameters))
  1032  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1033  }
  1034  
  1035  // GenerateThumbnailSender sends the GenerateThumbnail request. The method will close the
  1036  // http.Response Body if it receives an error.
  1037  func (client BaseClient) GenerateThumbnailSender(req *http.Request) (*http.Response, error) {
  1038  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  1039  }
  1040  
  1041  // GenerateThumbnailResponder handles the response to the GenerateThumbnail request. The method always
  1042  // closes the http.Response Body.
  1043  func (client BaseClient) GenerateThumbnailResponder(resp *http.Response) (result ReadCloser, err error) {
  1044  	result.Value = &resp.Body
  1045  	err = autorest.Respond(
  1046  		resp,
  1047  		azure.WithErrorUnlessStatusCode(http.StatusOK))
  1048  	result.Response = autorest.Response{Response: resp}
  1049  	return
  1050  }
  1051  
  1052  // GenerateThumbnailInStream this operation generates a thumbnail image with the user-specified width and height. By
  1053  // default, the service analyzes the image, identifies the region of interest (ROI), and generates smart cropping
  1054  // coordinates based on the ROI. Smart cropping helps when you specify an aspect ratio that differs from that of the
  1055  // input image.
  1056  // A successful response contains the thumbnail image binary. If the request failed, the response contains an error
  1057  // code and a message to help determine what went wrong.
  1058  // Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl,
  1059  // InvalidImageFormat, InvalidImageSize, InvalidThumbnailSize, NotSupportedImage, FailedToProcess, Timeout, or
  1060  // InternalServerError.
  1061  // Parameters:
  1062  // width - width of the thumbnail, in pixels. It must be between 1 and 1024. Recommended minimum of 50.
  1063  // height - height of the thumbnail, in pixels. It must be between 1 and 1024. Recommended minimum of 50.
  1064  // imageParameter - an image stream.
  1065  // smartCropping - boolean flag for enabling smart cropping.
  1066  func (client BaseClient) GenerateThumbnailInStream(ctx context.Context, width int32, height int32, imageParameter io.ReadCloser, smartCropping *bool) (result ReadCloser, err error) {
  1067  	if tracing.IsEnabled() {
  1068  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GenerateThumbnailInStream")
  1069  		defer func() {
  1070  			sc := -1
  1071  			if result.Response.Response != nil {
  1072  				sc = result.Response.Response.StatusCode
  1073  			}
  1074  			tracing.EndSpan(ctx, sc, err)
  1075  		}()
  1076  	}
  1077  	if err := validation.Validate([]validation.Validation{
  1078  		{TargetValue: width,
  1079  			Constraints: []validation.Constraint{{Target: "width", Name: validation.InclusiveMaximum, Rule: int64(1024), Chain: nil},
  1080  				{Target: "width", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}},
  1081  		{TargetValue: height,
  1082  			Constraints: []validation.Constraint{{Target: "height", Name: validation.InclusiveMaximum, Rule: int64(1024), Chain: nil},
  1083  				{Target: "height", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}); err != nil {
  1084  		return result, validation.NewError("computervision.BaseClient", "GenerateThumbnailInStream", err.Error())
  1085  	}
  1086  
  1087  	req, err := client.GenerateThumbnailInStreamPreparer(ctx, width, height, imageParameter, smartCropping)
  1088  	if err != nil {
  1089  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GenerateThumbnailInStream", nil, "Failure preparing request")
  1090  		return
  1091  	}
  1092  
  1093  	resp, err := client.GenerateThumbnailInStreamSender(req)
  1094  	if err != nil {
  1095  		result.Response = autorest.Response{Response: resp}
  1096  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GenerateThumbnailInStream", resp, "Failure sending request")
  1097  		return
  1098  	}
  1099  
  1100  	result, err = client.GenerateThumbnailInStreamResponder(resp)
  1101  	if err != nil {
  1102  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GenerateThumbnailInStream", resp, "Failure responding to request")
  1103  		return
  1104  	}
  1105  
  1106  	return
  1107  }
  1108  
  1109  // GenerateThumbnailInStreamPreparer prepares the GenerateThumbnailInStream request.
  1110  func (client BaseClient) GenerateThumbnailInStreamPreparer(ctx context.Context, width int32, height int32, imageParameter io.ReadCloser, smartCropping *bool) (*http.Request, error) {
  1111  	urlParameters := map[string]interface{}{
  1112  		"Endpoint": client.Endpoint,
  1113  	}
  1114  
  1115  	queryParameters := map[string]interface{}{
  1116  		"height": autorest.Encode("query", height),
  1117  		"width":  autorest.Encode("query", width),
  1118  	}
  1119  	if smartCropping != nil {
  1120  		queryParameters["smartCropping"] = autorest.Encode("query", *smartCropping)
  1121  	} else {
  1122  		queryParameters["smartCropping"] = autorest.Encode("query", false)
  1123  	}
  1124  
  1125  	preparer := autorest.CreatePreparer(
  1126  		autorest.AsContentType("application/octet-stream"),
  1127  		autorest.AsPost(),
  1128  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
  1129  		autorest.WithPath("/generateThumbnail"),
  1130  		autorest.WithFile(imageParameter),
  1131  		autorest.WithQueryParameters(queryParameters))
  1132  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1133  }
  1134  
  1135  // GenerateThumbnailInStreamSender sends the GenerateThumbnailInStream request. The method will close the
  1136  // http.Response Body if it receives an error.
  1137  func (client BaseClient) GenerateThumbnailInStreamSender(req *http.Request) (*http.Response, error) {
  1138  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  1139  }
  1140  
  1141  // GenerateThumbnailInStreamResponder handles the response to the GenerateThumbnailInStream request. The method always
  1142  // closes the http.Response Body.
  1143  func (client BaseClient) GenerateThumbnailInStreamResponder(resp *http.Response) (result ReadCloser, err error) {
  1144  	result.Value = &resp.Body
  1145  	err = autorest.Respond(
  1146  		resp,
  1147  		azure.WithErrorUnlessStatusCode(http.StatusOK))
  1148  	result.Response = autorest.Response{Response: resp}
  1149  	return
  1150  }
  1151  
  1152  // GetAreaOfInterest this operation returns a bounding box around the most important area of the image.
  1153  // A successful response will be returned in JSON. If the request failed, the response contains an error code and a
  1154  // message to help determine what went wrong.
  1155  // Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl,
  1156  // InvalidImageFormat, InvalidImageSize, NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.
  1157  // Parameters:
  1158  // imageURL - a JSON document with a URL pointing to the image that is to be analyzed.
  1159  func (client BaseClient) GetAreaOfInterest(ctx context.Context, imageURL ImageURL) (result AreaOfInterestResult, err error) {
  1160  	if tracing.IsEnabled() {
  1161  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetAreaOfInterest")
  1162  		defer func() {
  1163  			sc := -1
  1164  			if result.Response.Response != nil {
  1165  				sc = result.Response.Response.StatusCode
  1166  			}
  1167  			tracing.EndSpan(ctx, sc, err)
  1168  		}()
  1169  	}
  1170  	if err := validation.Validate([]validation.Validation{
  1171  		{TargetValue: imageURL,
  1172  			Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
  1173  		return result, validation.NewError("computervision.BaseClient", "GetAreaOfInterest", err.Error())
  1174  	}
  1175  
  1176  	req, err := client.GetAreaOfInterestPreparer(ctx, imageURL)
  1177  	if err != nil {
  1178  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GetAreaOfInterest", nil, "Failure preparing request")
  1179  		return
  1180  	}
  1181  
  1182  	resp, err := client.GetAreaOfInterestSender(req)
  1183  	if err != nil {
  1184  		result.Response = autorest.Response{Response: resp}
  1185  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GetAreaOfInterest", resp, "Failure sending request")
  1186  		return
  1187  	}
  1188  
  1189  	result, err = client.GetAreaOfInterestResponder(resp)
  1190  	if err != nil {
  1191  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GetAreaOfInterest", resp, "Failure responding to request")
  1192  		return
  1193  	}
  1194  
  1195  	return
  1196  }
  1197  
  1198  // GetAreaOfInterestPreparer prepares the GetAreaOfInterest request.
  1199  func (client BaseClient) GetAreaOfInterestPreparer(ctx context.Context, imageURL ImageURL) (*http.Request, error) {
  1200  	urlParameters := map[string]interface{}{
  1201  		"Endpoint": client.Endpoint,
  1202  	}
  1203  
  1204  	preparer := autorest.CreatePreparer(
  1205  		autorest.AsContentType("application/json; charset=utf-8"),
  1206  		autorest.AsPost(),
  1207  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
  1208  		autorest.WithPath("/areaOfInterest"),
  1209  		autorest.WithJSON(imageURL))
  1210  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1211  }
  1212  
  1213  // GetAreaOfInterestSender sends the GetAreaOfInterest request. The method will close the
  1214  // http.Response Body if it receives an error.
  1215  func (client BaseClient) GetAreaOfInterestSender(req *http.Request) (*http.Response, error) {
  1216  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  1217  }
  1218  
  1219  // GetAreaOfInterestResponder handles the response to the GetAreaOfInterest request. The method always
  1220  // closes the http.Response Body.
  1221  func (client BaseClient) GetAreaOfInterestResponder(resp *http.Response) (result AreaOfInterestResult, err error) {
  1222  	err = autorest.Respond(
  1223  		resp,
  1224  		azure.WithErrorUnlessStatusCode(http.StatusOK),
  1225  		autorest.ByUnmarshallingJSON(&result),
  1226  		autorest.ByClosing())
  1227  	result.Response = autorest.Response{Response: resp}
  1228  	return
  1229  }
  1230  
  1231  // GetAreaOfInterestInStream this operation returns a bounding box around the most important area of the image.
  1232  // A successful response will be returned in JSON. If the request failed, the response contains an error code and a
  1233  // message to help determine what went wrong.
  1234  // Upon failure, the error code and an error message are returned. The error code could be one of InvalidImageUrl,
  1235  // InvalidImageFormat, InvalidImageSize, NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.
  1236  // Parameters:
  1237  // imageParameter - an image stream.
  1238  func (client BaseClient) GetAreaOfInterestInStream(ctx context.Context, imageParameter io.ReadCloser) (result AreaOfInterestResult, err error) {
  1239  	if tracing.IsEnabled() {
  1240  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetAreaOfInterestInStream")
  1241  		defer func() {
  1242  			sc := -1
  1243  			if result.Response.Response != nil {
  1244  				sc = result.Response.Response.StatusCode
  1245  			}
  1246  			tracing.EndSpan(ctx, sc, err)
  1247  		}()
  1248  	}
  1249  	req, err := client.GetAreaOfInterestInStreamPreparer(ctx, imageParameter)
  1250  	if err != nil {
  1251  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GetAreaOfInterestInStream", nil, "Failure preparing request")
  1252  		return
  1253  	}
  1254  
  1255  	resp, err := client.GetAreaOfInterestInStreamSender(req)
  1256  	if err != nil {
  1257  		result.Response = autorest.Response{Response: resp}
  1258  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GetAreaOfInterestInStream", resp, "Failure sending request")
  1259  		return
  1260  	}
  1261  
  1262  	result, err = client.GetAreaOfInterestInStreamResponder(resp)
  1263  	if err != nil {
  1264  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GetAreaOfInterestInStream", resp, "Failure responding to request")
  1265  		return
  1266  	}
  1267  
  1268  	return
  1269  }
  1270  
  1271  // GetAreaOfInterestInStreamPreparer prepares the GetAreaOfInterestInStream request.
  1272  func (client BaseClient) GetAreaOfInterestInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser) (*http.Request, error) {
  1273  	urlParameters := map[string]interface{}{
  1274  		"Endpoint": client.Endpoint,
  1275  	}
  1276  
  1277  	preparer := autorest.CreatePreparer(
  1278  		autorest.AsContentType("application/octet-stream"),
  1279  		autorest.AsPost(),
  1280  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
  1281  		autorest.WithPath("/areaOfInterest"),
  1282  		autorest.WithFile(imageParameter))
  1283  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1284  }
  1285  
  1286  // GetAreaOfInterestInStreamSender sends the GetAreaOfInterestInStream request. The method will close the
  1287  // http.Response Body if it receives an error.
  1288  func (client BaseClient) GetAreaOfInterestInStreamSender(req *http.Request) (*http.Response, error) {
  1289  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  1290  }
  1291  
  1292  // GetAreaOfInterestInStreamResponder handles the response to the GetAreaOfInterestInStream request. The method always
  1293  // closes the http.Response Body.
  1294  func (client BaseClient) GetAreaOfInterestInStreamResponder(resp *http.Response) (result AreaOfInterestResult, err error) {
  1295  	err = autorest.Respond(
  1296  		resp,
  1297  		azure.WithErrorUnlessStatusCode(http.StatusOK),
  1298  		autorest.ByUnmarshallingJSON(&result),
  1299  		autorest.ByClosing())
  1300  	result.Response = autorest.Response{Response: resp}
  1301  	return
  1302  }
  1303  
  1304  // GetReadOperationResult this interface is used for getting OCR results of Read operation. The URL to this interface
  1305  // should be retrieved from 'Operation-Location' field returned from Batch Read File interface.
  1306  // Parameters:
  1307  // operationID - id of read operation returned in the response of the 'Batch Read File' interface.
  1308  func (client BaseClient) GetReadOperationResult(ctx context.Context, operationID string) (result ReadOperationResult, err error) {
  1309  	if tracing.IsEnabled() {
  1310  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetReadOperationResult")
  1311  		defer func() {
  1312  			sc := -1
  1313  			if result.Response.Response != nil {
  1314  				sc = result.Response.Response.StatusCode
  1315  			}
  1316  			tracing.EndSpan(ctx, sc, err)
  1317  		}()
  1318  	}
  1319  	req, err := client.GetReadOperationResultPreparer(ctx, operationID)
  1320  	if err != nil {
  1321  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GetReadOperationResult", nil, "Failure preparing request")
  1322  		return
  1323  	}
  1324  
  1325  	resp, err := client.GetReadOperationResultSender(req)
  1326  	if err != nil {
  1327  		result.Response = autorest.Response{Response: resp}
  1328  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GetReadOperationResult", resp, "Failure sending request")
  1329  		return
  1330  	}
  1331  
  1332  	result, err = client.GetReadOperationResultResponder(resp)
  1333  	if err != nil {
  1334  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GetReadOperationResult", resp, "Failure responding to request")
  1335  		return
  1336  	}
  1337  
  1338  	return
  1339  }
  1340  
  1341  // GetReadOperationResultPreparer prepares the GetReadOperationResult request.
  1342  func (client BaseClient) GetReadOperationResultPreparer(ctx context.Context, operationID string) (*http.Request, error) {
  1343  	urlParameters := map[string]interface{}{
  1344  		"Endpoint": client.Endpoint,
  1345  	}
  1346  
  1347  	pathParameters := map[string]interface{}{
  1348  		"operationId": autorest.Encode("path", operationID),
  1349  	}
  1350  
  1351  	preparer := autorest.CreatePreparer(
  1352  		autorest.AsGet(),
  1353  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
  1354  		autorest.WithPathParameters("/read/operations/{operationId}", pathParameters))
  1355  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1356  }
  1357  
  1358  // GetReadOperationResultSender sends the GetReadOperationResult request. The method will close the
  1359  // http.Response Body if it receives an error.
  1360  func (client BaseClient) GetReadOperationResultSender(req *http.Request) (*http.Response, error) {
  1361  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  1362  }
  1363  
  1364  // GetReadOperationResultResponder handles the response to the GetReadOperationResult request. The method always
  1365  // closes the http.Response Body.
  1366  func (client BaseClient) GetReadOperationResultResponder(resp *http.Response) (result ReadOperationResult, err error) {
  1367  	err = autorest.Respond(
  1368  		resp,
  1369  		azure.WithErrorUnlessStatusCode(http.StatusOK),
  1370  		autorest.ByUnmarshallingJSON(&result),
  1371  		autorest.ByClosing())
  1372  	result.Response = autorest.Response{Response: resp}
  1373  	return
  1374  }
  1375  
  1376  // GetTextOperationResult this interface is used for getting text operation result. The URL to this interface should be
  1377  // retrieved from 'Operation-Location' field returned from Recognize Text interface.
  1378  // Parameters:
  1379  // operationID - id of the text operation returned in the response of the 'Recognize Text'
  1380  func (client BaseClient) GetTextOperationResult(ctx context.Context, operationID string) (result TextOperationResult, err error) {
  1381  	if tracing.IsEnabled() {
  1382  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetTextOperationResult")
  1383  		defer func() {
  1384  			sc := -1
  1385  			if result.Response.Response != nil {
  1386  				sc = result.Response.Response.StatusCode
  1387  			}
  1388  			tracing.EndSpan(ctx, sc, err)
  1389  		}()
  1390  	}
  1391  	req, err := client.GetTextOperationResultPreparer(ctx, operationID)
  1392  	if err != nil {
  1393  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GetTextOperationResult", nil, "Failure preparing request")
  1394  		return
  1395  	}
  1396  
  1397  	resp, err := client.GetTextOperationResultSender(req)
  1398  	if err != nil {
  1399  		result.Response = autorest.Response{Response: resp}
  1400  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GetTextOperationResult", resp, "Failure sending request")
  1401  		return
  1402  	}
  1403  
  1404  	result, err = client.GetTextOperationResultResponder(resp)
  1405  	if err != nil {
  1406  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GetTextOperationResult", resp, "Failure responding to request")
  1407  		return
  1408  	}
  1409  
  1410  	return
  1411  }
  1412  
  1413  // GetTextOperationResultPreparer prepares the GetTextOperationResult request.
  1414  func (client BaseClient) GetTextOperationResultPreparer(ctx context.Context, operationID string) (*http.Request, error) {
  1415  	urlParameters := map[string]interface{}{
  1416  		"Endpoint": client.Endpoint,
  1417  	}
  1418  
  1419  	pathParameters := map[string]interface{}{
  1420  		"operationId": autorest.Encode("path", operationID),
  1421  	}
  1422  
  1423  	preparer := autorest.CreatePreparer(
  1424  		autorest.AsGet(),
  1425  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
  1426  		autorest.WithPathParameters("/textOperations/{operationId}", pathParameters))
  1427  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1428  }
  1429  
  1430  // GetTextOperationResultSender sends the GetTextOperationResult request. The method will close the
  1431  // http.Response Body if it receives an error.
  1432  func (client BaseClient) GetTextOperationResultSender(req *http.Request) (*http.Response, error) {
  1433  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  1434  }
  1435  
  1436  // GetTextOperationResultResponder handles the response to the GetTextOperationResult request. The method always
  1437  // closes the http.Response Body.
  1438  func (client BaseClient) GetTextOperationResultResponder(resp *http.Response) (result TextOperationResult, err error) {
  1439  	err = autorest.Respond(
  1440  		resp,
  1441  		azure.WithErrorUnlessStatusCode(http.StatusOK),
  1442  		autorest.ByUnmarshallingJSON(&result),
  1443  		autorest.ByClosing())
  1444  	result.Response = autorest.Response{Response: resp}
  1445  	return
  1446  }
  1447  
  1448  // ListModels this operation returns the list of domain-specific models that are supported by the Computer Vision API.
  1449  // Currently, the API supports following domain-specific models: celebrity recognizer, landmark recognizer.
  1450  // A successful response will be returned in JSON. If the request failed, the response will contain an error code and a
  1451  // message to help understand what went wrong.
  1452  func (client BaseClient) ListModels(ctx context.Context) (result ListModelsResult, err error) {
  1453  	if tracing.IsEnabled() {
  1454  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.ListModels")
  1455  		defer func() {
  1456  			sc := -1
  1457  			if result.Response.Response != nil {
  1458  				sc = result.Response.Response.StatusCode
  1459  			}
  1460  			tracing.EndSpan(ctx, sc, err)
  1461  		}()
  1462  	}
  1463  	req, err := client.ListModelsPreparer(ctx)
  1464  	if err != nil {
  1465  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "ListModels", nil, "Failure preparing request")
  1466  		return
  1467  	}
  1468  
  1469  	resp, err := client.ListModelsSender(req)
  1470  	if err != nil {
  1471  		result.Response = autorest.Response{Response: resp}
  1472  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "ListModels", resp, "Failure sending request")
  1473  		return
  1474  	}
  1475  
  1476  	result, err = client.ListModelsResponder(resp)
  1477  	if err != nil {
  1478  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "ListModels", resp, "Failure responding to request")
  1479  		return
  1480  	}
  1481  
  1482  	return
  1483  }
  1484  
  1485  // ListModelsPreparer prepares the ListModels request.
  1486  func (client BaseClient) ListModelsPreparer(ctx context.Context) (*http.Request, error) {
  1487  	urlParameters := map[string]interface{}{
  1488  		"Endpoint": client.Endpoint,
  1489  	}
  1490  
  1491  	preparer := autorest.CreatePreparer(
  1492  		autorest.AsGet(),
  1493  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
  1494  		autorest.WithPath("/models"))
  1495  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1496  }
  1497  
  1498  // ListModelsSender sends the ListModels request. The method will close the
  1499  // http.Response Body if it receives an error.
  1500  func (client BaseClient) ListModelsSender(req *http.Request) (*http.Response, error) {
  1501  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  1502  }
  1503  
  1504  // ListModelsResponder handles the response to the ListModels request. The method always
  1505  // closes the http.Response Body.
  1506  func (client BaseClient) ListModelsResponder(resp *http.Response) (result ListModelsResult, err error) {
  1507  	err = autorest.Respond(
  1508  		resp,
  1509  		azure.WithErrorUnlessStatusCode(http.StatusOK),
  1510  		autorest.ByUnmarshallingJSON(&result),
  1511  		autorest.ByClosing())
  1512  	result.Response = autorest.Response{Response: resp}
  1513  	return
  1514  }
  1515  
  1516  // RecognizePrintedText optical Character Recognition (OCR) detects text in an image and extracts the recognized
  1517  // characters into a machine-usable character stream.
  1518  // Upon success, the OCR results will be returned.
  1519  // Upon failure, the error code together with an error message will be returned. The error code can be one of
  1520  // InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, NotSupportedLanguage, or
  1521  // InternalServerError.
  1522  // Parameters:
  1523  // detectOrientation - whether detect the text orientation in the image. With detectOrientation=true the OCR
  1524  // service tries to detect the image orientation and correct it before further processing (e.g. if it's
  1525  // upside-down).
  1526  // imageURL - a JSON document with a URL pointing to the image that is to be analyzed.
  1527  // language - the BCP-47 language code of the text to be detected in the image. The default value is 'unk'.
  1528  func (client BaseClient) RecognizePrintedText(ctx context.Context, detectOrientation bool, imageURL ImageURL, language OcrLanguages) (result OcrResult, err error) {
  1529  	if tracing.IsEnabled() {
  1530  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.RecognizePrintedText")
  1531  		defer func() {
  1532  			sc := -1
  1533  			if result.Response.Response != nil {
  1534  				sc = result.Response.Response.StatusCode
  1535  			}
  1536  			tracing.EndSpan(ctx, sc, err)
  1537  		}()
  1538  	}
  1539  	if err := validation.Validate([]validation.Validation{
  1540  		{TargetValue: imageURL,
  1541  			Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
  1542  		return result, validation.NewError("computervision.BaseClient", "RecognizePrintedText", err.Error())
  1543  	}
  1544  
  1545  	req, err := client.RecognizePrintedTextPreparer(ctx, detectOrientation, imageURL, language)
  1546  	if err != nil {
  1547  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizePrintedText", nil, "Failure preparing request")
  1548  		return
  1549  	}
  1550  
  1551  	resp, err := client.RecognizePrintedTextSender(req)
  1552  	if err != nil {
  1553  		result.Response = autorest.Response{Response: resp}
  1554  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizePrintedText", resp, "Failure sending request")
  1555  		return
  1556  	}
  1557  
  1558  	result, err = client.RecognizePrintedTextResponder(resp)
  1559  	if err != nil {
  1560  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizePrintedText", resp, "Failure responding to request")
  1561  		return
  1562  	}
  1563  
  1564  	return
  1565  }
  1566  
  1567  // RecognizePrintedTextPreparer prepares the RecognizePrintedText request.
  1568  func (client BaseClient) RecognizePrintedTextPreparer(ctx context.Context, detectOrientation bool, imageURL ImageURL, language OcrLanguages) (*http.Request, error) {
  1569  	urlParameters := map[string]interface{}{
  1570  		"Endpoint": client.Endpoint,
  1571  	}
  1572  
  1573  	queryParameters := map[string]interface{}{
  1574  		"detectOrientation": autorest.Encode("query", detectOrientation),
  1575  	}
  1576  	if len(string(language)) > 0 {
  1577  		queryParameters["language"] = autorest.Encode("query", language)
  1578  	} else {
  1579  		queryParameters["language"] = autorest.Encode("query", "unk")
  1580  	}
  1581  
  1582  	preparer := autorest.CreatePreparer(
  1583  		autorest.AsContentType("application/json; charset=utf-8"),
  1584  		autorest.AsPost(),
  1585  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
  1586  		autorest.WithPath("/ocr"),
  1587  		autorest.WithJSON(imageURL),
  1588  		autorest.WithQueryParameters(queryParameters))
  1589  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1590  }
  1591  
  1592  // RecognizePrintedTextSender sends the RecognizePrintedText request. The method will close the
  1593  // http.Response Body if it receives an error.
  1594  func (client BaseClient) RecognizePrintedTextSender(req *http.Request) (*http.Response, error) {
  1595  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  1596  }
  1597  
  1598  // RecognizePrintedTextResponder handles the response to the RecognizePrintedText request. The method always
  1599  // closes the http.Response Body.
  1600  func (client BaseClient) RecognizePrintedTextResponder(resp *http.Response) (result OcrResult, err error) {
  1601  	err = autorest.Respond(
  1602  		resp,
  1603  		azure.WithErrorUnlessStatusCode(http.StatusOK),
  1604  		autorest.ByUnmarshallingJSON(&result),
  1605  		autorest.ByClosing())
  1606  	result.Response = autorest.Response{Response: resp}
  1607  	return
  1608  }
  1609  
  1610  // RecognizePrintedTextInStream optical Character Recognition (OCR) detects text in an image and extracts the
  1611  // recognized characters into a machine-usable character stream.
  1612  // Upon success, the OCR results will be returned.
  1613  // Upon failure, the error code together with an error message will be returned. The error code can be one of
  1614  // InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, NotSupportedLanguage, or
  1615  // InternalServerError.
  1616  // Parameters:
  1617  // detectOrientation - whether detect the text orientation in the image. With detectOrientation=true the OCR
  1618  // service tries to detect the image orientation and correct it before further processing (e.g. if it's
  1619  // upside-down).
  1620  // imageParameter - an image stream.
  1621  // language - the BCP-47 language code of the text to be detected in the image. The default value is 'unk'.
  1622  func (client BaseClient) RecognizePrintedTextInStream(ctx context.Context, detectOrientation bool, imageParameter io.ReadCloser, language OcrLanguages) (result OcrResult, err error) {
  1623  	if tracing.IsEnabled() {
  1624  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.RecognizePrintedTextInStream")
  1625  		defer func() {
  1626  			sc := -1
  1627  			if result.Response.Response != nil {
  1628  				sc = result.Response.Response.StatusCode
  1629  			}
  1630  			tracing.EndSpan(ctx, sc, err)
  1631  		}()
  1632  	}
  1633  	req, err := client.RecognizePrintedTextInStreamPreparer(ctx, detectOrientation, imageParameter, language)
  1634  	if err != nil {
  1635  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizePrintedTextInStream", nil, "Failure preparing request")
  1636  		return
  1637  	}
  1638  
  1639  	resp, err := client.RecognizePrintedTextInStreamSender(req)
  1640  	if err != nil {
  1641  		result.Response = autorest.Response{Response: resp}
  1642  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizePrintedTextInStream", resp, "Failure sending request")
  1643  		return
  1644  	}
  1645  
  1646  	result, err = client.RecognizePrintedTextInStreamResponder(resp)
  1647  	if err != nil {
  1648  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizePrintedTextInStream", resp, "Failure responding to request")
  1649  		return
  1650  	}
  1651  
  1652  	return
  1653  }
  1654  
  1655  // RecognizePrintedTextInStreamPreparer prepares the RecognizePrintedTextInStream request.
  1656  func (client BaseClient) RecognizePrintedTextInStreamPreparer(ctx context.Context, detectOrientation bool, imageParameter io.ReadCloser, language OcrLanguages) (*http.Request, error) {
  1657  	urlParameters := map[string]interface{}{
  1658  		"Endpoint": client.Endpoint,
  1659  	}
  1660  
  1661  	queryParameters := map[string]interface{}{
  1662  		"detectOrientation": autorest.Encode("query", detectOrientation),
  1663  	}
  1664  	if len(string(language)) > 0 {
  1665  		queryParameters["language"] = autorest.Encode("query", language)
  1666  	} else {
  1667  		queryParameters["language"] = autorest.Encode("query", "unk")
  1668  	}
  1669  
  1670  	preparer := autorest.CreatePreparer(
  1671  		autorest.AsContentType("application/octet-stream"),
  1672  		autorest.AsPost(),
  1673  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
  1674  		autorest.WithPath("/ocr"),
  1675  		autorest.WithFile(imageParameter),
  1676  		autorest.WithQueryParameters(queryParameters))
  1677  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1678  }
  1679  
  1680  // RecognizePrintedTextInStreamSender sends the RecognizePrintedTextInStream request. The method will close the
  1681  // http.Response Body if it receives an error.
  1682  func (client BaseClient) RecognizePrintedTextInStreamSender(req *http.Request) (*http.Response, error) {
  1683  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  1684  }
  1685  
  1686  // RecognizePrintedTextInStreamResponder handles the response to the RecognizePrintedTextInStream request. The method always
  1687  // closes the http.Response Body.
  1688  func (client BaseClient) RecognizePrintedTextInStreamResponder(resp *http.Response) (result OcrResult, err error) {
  1689  	err = autorest.Respond(
  1690  		resp,
  1691  		azure.WithErrorUnlessStatusCode(http.StatusOK),
  1692  		autorest.ByUnmarshallingJSON(&result),
  1693  		autorest.ByClosing())
  1694  	result.Response = autorest.Response{Response: resp}
  1695  	return
  1696  }
  1697  
  1698  // RecognizeText recognize Text operation. When you use the Recognize Text interface, the response contains a field
  1699  // called 'Operation-Location'. The 'Operation-Location' field contains the URL that you must use for your Get
  1700  // Recognize Text Operation Result operation.
  1701  // Parameters:
  1702  // imageURL - a JSON document with a URL pointing to the image that is to be analyzed.
  1703  // mode - type of text to recognize.
  1704  func (client BaseClient) RecognizeText(ctx context.Context, imageURL ImageURL, mode TextRecognitionMode) (result autorest.Response, err error) {
  1705  	if tracing.IsEnabled() {
  1706  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.RecognizeText")
  1707  		defer func() {
  1708  			sc := -1
  1709  			if result.Response != nil {
  1710  				sc = result.Response.StatusCode
  1711  			}
  1712  			tracing.EndSpan(ctx, sc, err)
  1713  		}()
  1714  	}
  1715  	if err := validation.Validate([]validation.Validation{
  1716  		{TargetValue: imageURL,
  1717  			Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
  1718  		return result, validation.NewError("computervision.BaseClient", "RecognizeText", err.Error())
  1719  	}
  1720  
  1721  	req, err := client.RecognizeTextPreparer(ctx, imageURL, mode)
  1722  	if err != nil {
  1723  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizeText", nil, "Failure preparing request")
  1724  		return
  1725  	}
  1726  
  1727  	resp, err := client.RecognizeTextSender(req)
  1728  	if err != nil {
  1729  		result.Response = resp
  1730  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizeText", resp, "Failure sending request")
  1731  		return
  1732  	}
  1733  
  1734  	result, err = client.RecognizeTextResponder(resp)
  1735  	if err != nil {
  1736  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizeText", resp, "Failure responding to request")
  1737  		return
  1738  	}
  1739  
  1740  	return
  1741  }
  1742  
  1743  // RecognizeTextPreparer prepares the RecognizeText request.
  1744  func (client BaseClient) RecognizeTextPreparer(ctx context.Context, imageURL ImageURL, mode TextRecognitionMode) (*http.Request, error) {
  1745  	urlParameters := map[string]interface{}{
  1746  		"Endpoint": client.Endpoint,
  1747  	}
  1748  
  1749  	queryParameters := map[string]interface{}{
  1750  		"mode": autorest.Encode("query", mode),
  1751  	}
  1752  
  1753  	preparer := autorest.CreatePreparer(
  1754  		autorest.AsContentType("application/json; charset=utf-8"),
  1755  		autorest.AsPost(),
  1756  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
  1757  		autorest.WithPath("/recognizeText"),
  1758  		autorest.WithJSON(imageURL),
  1759  		autorest.WithQueryParameters(queryParameters))
  1760  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1761  }
  1762  
  1763  // RecognizeTextSender sends the RecognizeText request. The method will close the
  1764  // http.Response Body if it receives an error.
  1765  func (client BaseClient) RecognizeTextSender(req *http.Request) (*http.Response, error) {
  1766  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  1767  }
  1768  
  1769  // RecognizeTextResponder handles the response to the RecognizeText request. The method always
  1770  // closes the http.Response Body.
  1771  func (client BaseClient) RecognizeTextResponder(resp *http.Response) (result autorest.Response, err error) {
  1772  	err = autorest.Respond(
  1773  		resp,
  1774  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
  1775  		autorest.ByClosing())
  1776  	result.Response = resp
  1777  	return
  1778  }
  1779  
  1780  // RecognizeTextInStream recognize Text operation. When you use the Recognize Text interface, the response contains a
  1781  // field called 'Operation-Location'. The 'Operation-Location' field contains the URL that you must use for your Get
  1782  // Recognize Text Operation Result operation.
  1783  // Parameters:
  1784  // imageParameter - an image stream.
  1785  // mode - type of text to recognize.
  1786  func (client BaseClient) RecognizeTextInStream(ctx context.Context, imageParameter io.ReadCloser, mode TextRecognitionMode) (result autorest.Response, err error) {
  1787  	if tracing.IsEnabled() {
  1788  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.RecognizeTextInStream")
  1789  		defer func() {
  1790  			sc := -1
  1791  			if result.Response != nil {
  1792  				sc = result.Response.StatusCode
  1793  			}
  1794  			tracing.EndSpan(ctx, sc, err)
  1795  		}()
  1796  	}
  1797  	req, err := client.RecognizeTextInStreamPreparer(ctx, imageParameter, mode)
  1798  	if err != nil {
  1799  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizeTextInStream", nil, "Failure preparing request")
  1800  		return
  1801  	}
  1802  
  1803  	resp, err := client.RecognizeTextInStreamSender(req)
  1804  	if err != nil {
  1805  		result.Response = resp
  1806  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizeTextInStream", resp, "Failure sending request")
  1807  		return
  1808  	}
  1809  
  1810  	result, err = client.RecognizeTextInStreamResponder(resp)
  1811  	if err != nil {
  1812  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizeTextInStream", resp, "Failure responding to request")
  1813  		return
  1814  	}
  1815  
  1816  	return
  1817  }
  1818  
  1819  // RecognizeTextInStreamPreparer prepares the RecognizeTextInStream request.
  1820  func (client BaseClient) RecognizeTextInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser, mode TextRecognitionMode) (*http.Request, error) {
  1821  	urlParameters := map[string]interface{}{
  1822  		"Endpoint": client.Endpoint,
  1823  	}
  1824  
  1825  	queryParameters := map[string]interface{}{
  1826  		"mode": autorest.Encode("query", mode),
  1827  	}
  1828  
  1829  	preparer := autorest.CreatePreparer(
  1830  		autorest.AsContentType("application/octet-stream"),
  1831  		autorest.AsPost(),
  1832  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
  1833  		autorest.WithPath("/recognizeText"),
  1834  		autorest.WithFile(imageParameter),
  1835  		autorest.WithQueryParameters(queryParameters))
  1836  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1837  }
  1838  
  1839  // RecognizeTextInStreamSender sends the RecognizeTextInStream request. The method will close the
  1840  // http.Response Body if it receives an error.
  1841  func (client BaseClient) RecognizeTextInStreamSender(req *http.Request) (*http.Response, error) {
  1842  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  1843  }
  1844  
  1845  // RecognizeTextInStreamResponder handles the response to the RecognizeTextInStream request. The method always
  1846  // closes the http.Response Body.
  1847  func (client BaseClient) RecognizeTextInStreamResponder(resp *http.Response) (result autorest.Response, err error) {
  1848  	err = autorest.Respond(
  1849  		resp,
  1850  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
  1851  		autorest.ByClosing())
  1852  	result.Response = resp
  1853  	return
  1854  }
  1855  
  1856  // TagImage this operation generates a list of words, or tags, that are relevant to the content of the supplied image.
  1857  // The Computer Vision API can return tags based on objects, living beings, scenery or actions found in images. Unlike
  1858  // categories, tags are not organized according to a hierarchical classification system, but correspond to image
  1859  // content. Tags may contain hints to avoid ambiguity or provide context, for example the tag "ascomycete" may be
  1860  // accompanied by the hint "fungus".
  1861  // Two input methods are supported -- (1) Uploading an image or (2) specifying an image URL.
  1862  // A successful response will be returned in JSON. If the request failed, the response will contain an error code and a
  1863  // message to help understand what went wrong.
  1864  // Parameters:
  1865  // imageURL - a JSON document with a URL pointing to the image that is to be analyzed.
  1866  // language - the desired language for output generation. If this parameter is not specified, the default value
  1867  // is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese,
  1868  // zh - Simplified Chinese.
  1869  func (client BaseClient) TagImage(ctx context.Context, imageURL ImageURL, language string) (result TagResult, err error) {
  1870  	if tracing.IsEnabled() {
  1871  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.TagImage")
  1872  		defer func() {
  1873  			sc := -1
  1874  			if result.Response.Response != nil {
  1875  				sc = result.Response.Response.StatusCode
  1876  			}
  1877  			tracing.EndSpan(ctx, sc, err)
  1878  		}()
  1879  	}
  1880  	if err := validation.Validate([]validation.Validation{
  1881  		{TargetValue: imageURL,
  1882  			Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
  1883  		return result, validation.NewError("computervision.BaseClient", "TagImage", err.Error())
  1884  	}
  1885  
  1886  	req, err := client.TagImagePreparer(ctx, imageURL, language)
  1887  	if err != nil {
  1888  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "TagImage", nil, "Failure preparing request")
  1889  		return
  1890  	}
  1891  
  1892  	resp, err := client.TagImageSender(req)
  1893  	if err != nil {
  1894  		result.Response = autorest.Response{Response: resp}
  1895  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "TagImage", resp, "Failure sending request")
  1896  		return
  1897  	}
  1898  
  1899  	result, err = client.TagImageResponder(resp)
  1900  	if err != nil {
  1901  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "TagImage", resp, "Failure responding to request")
  1902  		return
  1903  	}
  1904  
  1905  	return
  1906  }
  1907  
  1908  // TagImagePreparer prepares the TagImage request.
  1909  func (client BaseClient) TagImagePreparer(ctx context.Context, imageURL ImageURL, language string) (*http.Request, error) {
  1910  	urlParameters := map[string]interface{}{
  1911  		"Endpoint": client.Endpoint,
  1912  	}
  1913  
  1914  	queryParameters := map[string]interface{}{}
  1915  	if len(string(language)) > 0 {
  1916  		queryParameters["language"] = autorest.Encode("query", language)
  1917  	} else {
  1918  		queryParameters["language"] = autorest.Encode("query", "en")
  1919  	}
  1920  
  1921  	preparer := autorest.CreatePreparer(
  1922  		autorest.AsContentType("application/json; charset=utf-8"),
  1923  		autorest.AsPost(),
  1924  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
  1925  		autorest.WithPath("/tag"),
  1926  		autorest.WithJSON(imageURL),
  1927  		autorest.WithQueryParameters(queryParameters))
  1928  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1929  }
  1930  
  1931  // TagImageSender sends the TagImage request. The method will close the
  1932  // http.Response Body if it receives an error.
  1933  func (client BaseClient) TagImageSender(req *http.Request) (*http.Response, error) {
  1934  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  1935  }
  1936  
  1937  // TagImageResponder handles the response to the TagImage request. The method always
  1938  // closes the http.Response Body.
  1939  func (client BaseClient) TagImageResponder(resp *http.Response) (result TagResult, err error) {
  1940  	err = autorest.Respond(
  1941  		resp,
  1942  		azure.WithErrorUnlessStatusCode(http.StatusOK),
  1943  		autorest.ByUnmarshallingJSON(&result),
  1944  		autorest.ByClosing())
  1945  	result.Response = autorest.Response{Response: resp}
  1946  	return
  1947  }
  1948  
  1949  // TagImageInStream this operation generates a list of words, or tags, that are relevant to the content of the supplied
  1950  // image. The Computer Vision API can return tags based on objects, living beings, scenery or actions found in images.
  1951  // Unlike categories, tags are not organized according to a hierarchical classification system, but correspond to image
  1952  // content. Tags may contain hints to avoid ambiguity or provide context, for example the tag "ascomycete" may be
  1953  // accompanied by the hint "fungus".
  1954  // Two input methods are supported -- (1) Uploading an image or (2) specifying an image URL.
  1955  // A successful response will be returned in JSON. If the request failed, the response will contain an error code and a
  1956  // message to help understand what went wrong.
  1957  // Parameters:
  1958  // imageParameter - an image stream.
  1959  // language - the desired language for output generation. If this parameter is not specified, the default value
  1960  // is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese,
  1961  // zh - Simplified Chinese.
  1962  func (client BaseClient) TagImageInStream(ctx context.Context, imageParameter io.ReadCloser, language string) (result TagResult, err error) {
  1963  	if tracing.IsEnabled() {
  1964  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.TagImageInStream")
  1965  		defer func() {
  1966  			sc := -1
  1967  			if result.Response.Response != nil {
  1968  				sc = result.Response.Response.StatusCode
  1969  			}
  1970  			tracing.EndSpan(ctx, sc, err)
  1971  		}()
  1972  	}
  1973  	req, err := client.TagImageInStreamPreparer(ctx, imageParameter, language)
  1974  	if err != nil {
  1975  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "TagImageInStream", nil, "Failure preparing request")
  1976  		return
  1977  	}
  1978  
  1979  	resp, err := client.TagImageInStreamSender(req)
  1980  	if err != nil {
  1981  		result.Response = autorest.Response{Response: resp}
  1982  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "TagImageInStream", resp, "Failure sending request")
  1983  		return
  1984  	}
  1985  
  1986  	result, err = client.TagImageInStreamResponder(resp)
  1987  	if err != nil {
  1988  		err = autorest.NewErrorWithError(err, "computervision.BaseClient", "TagImageInStream", resp, "Failure responding to request")
  1989  		return
  1990  	}
  1991  
  1992  	return
  1993  }
  1994  
  1995  // TagImageInStreamPreparer prepares the TagImageInStream request.
  1996  func (client BaseClient) TagImageInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser, language string) (*http.Request, error) {
  1997  	urlParameters := map[string]interface{}{
  1998  		"Endpoint": client.Endpoint,
  1999  	}
  2000  
  2001  	queryParameters := map[string]interface{}{}
  2002  	if len(string(language)) > 0 {
  2003  		queryParameters["language"] = autorest.Encode("query", language)
  2004  	} else {
  2005  		queryParameters["language"] = autorest.Encode("query", "en")
  2006  	}
  2007  
  2008  	preparer := autorest.CreatePreparer(
  2009  		autorest.AsContentType("application/octet-stream"),
  2010  		autorest.AsPost(),
  2011  		autorest.WithCustomBaseURL("{Endpoint}/vision/v2.1", urlParameters),
  2012  		autorest.WithPath("/tag"),
  2013  		autorest.WithFile(imageParameter),
  2014  		autorest.WithQueryParameters(queryParameters))
  2015  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  2016  }
  2017  
  2018  // TagImageInStreamSender sends the TagImageInStream request. The method will close the
  2019  // http.Response Body if it receives an error.
  2020  func (client BaseClient) TagImageInStreamSender(req *http.Request) (*http.Response, error) {
  2021  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  2022  }
  2023  
  2024  // TagImageInStreamResponder handles the response to the TagImageInStream request. The method always
  2025  // closes the http.Response Body.
  2026  func (client BaseClient) TagImageInStreamResponder(resp *http.Response) (result TagResult, err error) {
  2027  	err = autorest.Respond(
  2028  		resp,
  2029  		azure.WithErrorUnlessStatusCode(http.StatusOK),
  2030  		autorest.ByUnmarshallingJSON(&result),
  2031  		autorest.ByClosing())
  2032  	result.Response = autorest.Response{Response: resp}
  2033  	return
  2034  }
  2035  

View as plain text