...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v3.0/computervision

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

View as plain text