From 3dbea3f0c95fcbf3268d97053b09732c1dac0fd2 Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Thu, 14 Jun 2018 01:59:14 +0000 Subject: [PATCH 1/3] Generated from c2567da015994dac3301f495b6c5011d28ceaffe Add post-processing directive to swap argument order for RecognizeText to position the url argument ahead of the mode argument. autorest does not generate the intended order, so we add a post-processing directive, for each target language, --- .../computervision/models.go | 12 +- .../v2.0/computervision/client.go | 1330 +++++++++++++++++ .../v2.0/computervision/models.go | 566 +++++++ .../v2.0/computervision/version.go | 30 + 4 files changed, 1937 insertions(+), 1 deletion(-) create mode 100644 services/cognitiveservices/v2.0/computervision/client.go create mode 100644 services/cognitiveservices/v2.0/computervision/models.go create mode 100644 services/cognitiveservices/v2.0/computervision/version.go diff --git a/profiles/preview/cognitiveservices/computervision/models.go b/profiles/preview/cognitiveservices/computervision/models.go index 1bb2df90a345..b4fdd1d8b59a 100644 --- a/profiles/preview/cognitiveservices/computervision/models.go +++ b/profiles/preview/cognitiveservices/computervision/models.go @@ -19,7 +19,7 @@ package computervision -import original "github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v1.0/computervision" +import original "github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v2.0/computervision" type BaseClient = original.BaseClient type AzureRegions = original.AzureRegions @@ -112,6 +112,13 @@ const ( Succeeded TextOperationStatusCodes = original.Succeeded ) +type TextRecognitionMode = original.TextRecognitionMode + +const ( + Handwritten TextRecognitionMode = original.Handwritten + Printed TextRecognitionMode = original.Printed +) + type VisualFeatureTypes = original.VisualFeatureTypes const ( @@ -181,6 +188,9 @@ func PossibleOcrLanguagesValues() []OcrLanguages { func PossibleTextOperationStatusCodesValues() []TextOperationStatusCodes { return original.PossibleTextOperationStatusCodesValues() } +func PossibleTextRecognitionModeValues() []TextRecognitionMode { + return original.PossibleTextRecognitionModeValues() +} func PossibleVisualFeatureTypesValues() []VisualFeatureTypes { return original.PossibleVisualFeatureTypesValues() } diff --git a/services/cognitiveservices/v2.0/computervision/client.go b/services/cognitiveservices/v2.0/computervision/client.go new file mode 100644 index 000000000000..93de86373be9 --- /dev/null +++ b/services/cognitiveservices/v2.0/computervision/client.go @@ -0,0 +1,1330 @@ +// Package computervision implements the Azure ARM Computervision service API version 2.0. +// +// The Computer Vision API provides state-of-the-art algorithms to process images and return information. For example, +// it can be used to determine if an image contains mature content, or it can be used to find all the faces in an +// image. It also has other features like estimating dominant and accent colors, categorizing the content of images, +// and describing an image with complete English sentences. Additionally, it can also intelligently generate images +// thumbnails for displaying large images effectively. +package computervision + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "io" + "net/http" +) + +// BaseClient is the base client for Computervision. +type BaseClient struct { + autorest.Client + AzureRegion AzureRegions +} + +// New creates an instance of the BaseClient client. +func New(azureRegion AzureRegions) BaseClient { + return NewWithoutDefaults(azureRegion) +} + +// NewWithoutDefaults creates an instance of the BaseClient client. +func NewWithoutDefaults(azureRegion AzureRegions) BaseClient { + return BaseClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + AzureRegion: azureRegion, + } +} + +// AnalyzeImage this operation extracts a rich set of visual features based on the image content. Two input methods are +// supported -- (1) Uploading an image or (2) specifying an image URL. Within your request, there is an optional +// parameter to allow you to choose which features to return. By default, image categories are returned in the +// response. +// Parameters: +// imageURL - a JSON document with a URL pointing to the image that is to be analyzed. +// visualFeatures - a string indicating what visual feature types to return. Multiple values should be +// comma-separated. Valid visual feature types include:Categories - categorizes image content according to a +// taxonomy defined in documentation. Tags - tags the image with a detailed list of words related to the image +// content. Description - describes the image content with a complete English sentence. Faces - detects if +// faces are present. If present, generate coordinates, gender and age. ImageType - detects if image is clipart +// or a line drawing. Color - determines the accent color, dominant color, and whether an image is +// black&white.Adult - detects if the image is pornographic in nature (depicts nudity or a sex act). Sexually +// suggestive content is also detected. +// details - a string indicating which domain-specific details to return. Multiple values should be +// comma-separated. Valid visual feature types include:Celebrities - identifies celebrities if detected in the +// image. +// language - the desired language for output generation. If this parameter is not specified, the default value +// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified +// Chinese. +func (client BaseClient) AnalyzeImage(ctx context.Context, imageURL ImageURL, visualFeatures []VisualFeatureTypes, details []Details, language string) (result ImageAnalysis, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: imageURL, + Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("computervision.BaseClient", "AnalyzeImage", err.Error()) + } + + req, err := client.AnalyzeImagePreparer(ctx, imageURL, visualFeatures, details, language) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImage", nil, "Failure preparing request") + return + } + + resp, err := client.AnalyzeImageSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImage", resp, "Failure sending request") + return + } + + result, err = client.AnalyzeImageResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImage", resp, "Failure responding to request") + } + + return +} + +// AnalyzeImagePreparer prepares the AnalyzeImage request. +func (client BaseClient) AnalyzeImagePreparer(ctx context.Context, imageURL ImageURL, visualFeatures []VisualFeatureTypes, details []Details, language string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + queryParameters := map[string]interface{}{} + if visualFeatures != nil && len(visualFeatures) > 0 { + queryParameters["visualFeatures"] = autorest.Encode("query", visualFeatures, ",") + } + if details != nil && len(details) > 0 { + queryParameters["details"] = autorest.Encode("query", details, ",") + } + if len(string(language)) > 0 { + queryParameters["language"] = autorest.Encode("query", language) + } else { + queryParameters["language"] = autorest.Encode("query", "en") + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPath("/analyze"), + autorest.WithJSON(imageURL), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// AnalyzeImageSender sends the AnalyzeImage request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) AnalyzeImageSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// AnalyzeImageResponder handles the response to the AnalyzeImage request. The method always +// closes the http.Response Body. +func (client BaseClient) AnalyzeImageResponder(resp *http.Response) (result ImageAnalysis, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// AnalyzeImageByDomain this operation recognizes content within an image by applying a domain-specific model. The +// list of domain-specific models that are supported by the Computer Vision API can be retrieved using the /models GET +// request. Currently, the API only provides a single domain-specific model: celebrities. Two input methods are +// supported -- (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. +// If the request failed, the response will contain an error code and a message to help understand what went wrong. +// Parameters: +// model - the domain-specific content to recognize. +// imageURL - a JSON document with a URL pointing to the image that is to be analyzed. +// language - the desired language for output generation. If this parameter is not specified, the default value +// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified +// Chinese. +func (client BaseClient) AnalyzeImageByDomain(ctx context.Context, model string, imageURL ImageURL, language string) (result DomainModelResults, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: imageURL, + Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("computervision.BaseClient", "AnalyzeImageByDomain", err.Error()) + } + + req, err := client.AnalyzeImageByDomainPreparer(ctx, model, imageURL, language) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageByDomain", nil, "Failure preparing request") + return + } + + resp, err := client.AnalyzeImageByDomainSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageByDomain", resp, "Failure sending request") + return + } + + result, err = client.AnalyzeImageByDomainResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageByDomain", resp, "Failure responding to request") + } + + return +} + +// AnalyzeImageByDomainPreparer prepares the AnalyzeImageByDomain request. +func (client BaseClient) AnalyzeImageByDomainPreparer(ctx context.Context, model string, imageURL ImageURL, language string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + pathParameters := map[string]interface{}{ + "model": autorest.Encode("path", model), + } + + queryParameters := map[string]interface{}{} + if len(string(language)) > 0 { + queryParameters["language"] = autorest.Encode("query", language) + } else { + queryParameters["language"] = autorest.Encode("query", "en") + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPathParameters("/models/{model}/analyze", pathParameters), + autorest.WithJSON(imageURL), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// AnalyzeImageByDomainSender sends the AnalyzeImageByDomain request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) AnalyzeImageByDomainSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// AnalyzeImageByDomainResponder handles the response to the AnalyzeImageByDomain request. The method always +// closes the http.Response Body. +func (client BaseClient) AnalyzeImageByDomainResponder(resp *http.Response) (result DomainModelResults, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// AnalyzeImageByDomainInStream this operation recognizes content within an image by applying a domain-specific model. +// The list of domain-specific models that are supported by the Computer Vision API can be retrieved using the /models +// GET request. Currently, the API only provides a single domain-specific model: celebrities. Two input methods are +// supported -- (1) Uploading an image or (2) specifying an image URL. A successful response will be returned in JSON. +// If the request failed, the response will contain an error code and a message to help understand what went wrong. +// Parameters: +// model - the domain-specific content to recognize. +// imageParameter - an image stream. +// language - the desired language for output generation. If this parameter is not specified, the default value +// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified +// Chinese. +func (client BaseClient) AnalyzeImageByDomainInStream(ctx context.Context, model string, imageParameter io.ReadCloser, language string) (result DomainModelResults, err error) { + req, err := client.AnalyzeImageByDomainInStreamPreparer(ctx, model, imageParameter, language) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageByDomainInStream", nil, "Failure preparing request") + return + } + + resp, err := client.AnalyzeImageByDomainInStreamSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageByDomainInStream", resp, "Failure sending request") + return + } + + result, err = client.AnalyzeImageByDomainInStreamResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageByDomainInStream", resp, "Failure responding to request") + } + + return +} + +// AnalyzeImageByDomainInStreamPreparer prepares the AnalyzeImageByDomainInStream request. +func (client BaseClient) AnalyzeImageByDomainInStreamPreparer(ctx context.Context, model string, imageParameter io.ReadCloser, language string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + pathParameters := map[string]interface{}{ + "model": autorest.Encode("path", model), + } + + queryParameters := map[string]interface{}{} + if len(string(language)) > 0 { + queryParameters["language"] = autorest.Encode("query", language) + } else { + queryParameters["language"] = autorest.Encode("query", "en") + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/octet-stream"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPathParameters("/models/{model}/analyze", pathParameters), + autorest.WithFile(imageParameter), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// AnalyzeImageByDomainInStreamSender sends the AnalyzeImageByDomainInStream request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) AnalyzeImageByDomainInStreamSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// AnalyzeImageByDomainInStreamResponder handles the response to the AnalyzeImageByDomainInStream request. The method always +// closes the http.Response Body. +func (client BaseClient) AnalyzeImageByDomainInStreamResponder(resp *http.Response) (result DomainModelResults, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// AnalyzeImageInStream this operation extracts a rich set of visual features based on the image content. +// Parameters: +// imageParameter - an image stream. +// visualFeatures - a string indicating what visual feature types to return. Multiple values should be +// comma-separated. Valid visual feature types include:Categories - categorizes image content according to a +// taxonomy defined in documentation. Tags - tags the image with a detailed list of words related to the image +// content. Description - describes the image content with a complete English sentence. Faces - detects if +// faces are present. If present, generate coordinates, gender and age. ImageType - detects if image is clipart +// or a line drawing. Color - determines the accent color, dominant color, and whether an image is +// black&white.Adult - detects if the image is pornographic in nature (depicts nudity or a sex act). Sexually +// suggestive content is also detected. +// details - a string indicating which domain-specific details to return. Multiple values should be +// comma-separated. Valid visual feature types include:Celebrities - identifies celebrities if detected in the +// image. +// language - the desired language for output generation. If this parameter is not specified, the default value +// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified +// Chinese. +func (client BaseClient) AnalyzeImageInStream(ctx context.Context, imageParameter io.ReadCloser, visualFeatures []VisualFeatureTypes, details string, language string) (result ImageAnalysis, err error) { + req, err := client.AnalyzeImageInStreamPreparer(ctx, imageParameter, visualFeatures, details, language) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageInStream", nil, "Failure preparing request") + return + } + + resp, err := client.AnalyzeImageInStreamSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageInStream", resp, "Failure sending request") + return + } + + result, err = client.AnalyzeImageInStreamResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageInStream", resp, "Failure responding to request") + } + + return +} + +// AnalyzeImageInStreamPreparer prepares the AnalyzeImageInStream request. +func (client BaseClient) AnalyzeImageInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser, visualFeatures []VisualFeatureTypes, details string, language string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + queryParameters := map[string]interface{}{} + if visualFeatures != nil && len(visualFeatures) > 0 { + queryParameters["visualFeatures"] = autorest.Encode("query", visualFeatures, ",") + } + if len(string(details)) > 0 { + queryParameters["details"] = autorest.Encode("query", details) + } + if len(string(language)) > 0 { + queryParameters["language"] = autorest.Encode("query", language) + } else { + queryParameters["language"] = autorest.Encode("query", "en") + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/octet-stream"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPath("/analyze"), + autorest.WithFile(imageParameter), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// AnalyzeImageInStreamSender sends the AnalyzeImageInStream request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) AnalyzeImageInStreamSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// AnalyzeImageInStreamResponder handles the response to the AnalyzeImageInStream request. The method always +// closes the http.Response Body. +func (client BaseClient) AnalyzeImageInStreamResponder(resp *http.Response) (result ImageAnalysis, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// DescribeImage this operation generates a description of an image in human readable language with complete sentences. +// The description is based on a collection of content tags, which are also returned by the operation. More than one +// description can be generated for each image. Descriptions are ordered by their confidence score. All descriptions +// are in English. Two input methods are supported -- (1) Uploading an image or (2) specifying an image URL.A +// successful response will be returned in JSON. If the request failed, the response will contain an error code and a +// message to help understand what went wrong. +// Parameters: +// imageURL - a JSON document with a URL pointing to the image that is to be analyzed. +// maxCandidates - maximum number of candidate descriptions to be returned. The default is 1. +// language - the desired language for output generation. If this parameter is not specified, the default value +// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified +// Chinese. +func (client BaseClient) DescribeImage(ctx context.Context, imageURL ImageURL, maxCandidates string, language string) (result ImageDescription, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: imageURL, + Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("computervision.BaseClient", "DescribeImage", err.Error()) + } + + req, err := client.DescribeImagePreparer(ctx, imageURL, maxCandidates, language) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DescribeImage", nil, "Failure preparing request") + return + } + + resp, err := client.DescribeImageSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DescribeImage", resp, "Failure sending request") + return + } + + result, err = client.DescribeImageResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DescribeImage", resp, "Failure responding to request") + } + + return +} + +// DescribeImagePreparer prepares the DescribeImage request. +func (client BaseClient) DescribeImagePreparer(ctx context.Context, imageURL ImageURL, maxCandidates string, language string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + queryParameters := map[string]interface{}{} + if len(maxCandidates) > 0 { + queryParameters["maxCandidates"] = autorest.Encode("query", maxCandidates) + } else { + queryParameters["maxCandidates"] = autorest.Encode("query", "1") + } + if len(string(language)) > 0 { + queryParameters["language"] = autorest.Encode("query", language) + } else { + queryParameters["language"] = autorest.Encode("query", "en") + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPath("/describe"), + autorest.WithJSON(imageURL), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DescribeImageSender sends the DescribeImage request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) DescribeImageSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// DescribeImageResponder handles the response to the DescribeImage request. The method always +// closes the http.Response Body. +func (client BaseClient) DescribeImageResponder(resp *http.Response) (result ImageDescription, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// DescribeImageInStream this operation generates a description of an image in human readable language with complete +// sentences. The description is based on a collection of content tags, which are also returned by the operation. More +// than one description can be generated for each image. Descriptions are ordered by their confidence score. All +// descriptions are in English. Two input methods are supported -- (1) Uploading an image or (2) specifying an image +// URL.A successful response will be returned in JSON. If the request failed, the response will contain an error code +// and a message to help understand what went wrong. +// Parameters: +// imageParameter - an image stream. +// maxCandidates - maximum number of candidate descriptions to be returned. The default is 1. +// language - the desired language for output generation. If this parameter is not specified, the default value +// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified +// Chinese. +func (client BaseClient) DescribeImageInStream(ctx context.Context, imageParameter io.ReadCloser, maxCandidates string, language string) (result ImageDescription, err error) { + req, err := client.DescribeImageInStreamPreparer(ctx, imageParameter, maxCandidates, language) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DescribeImageInStream", nil, "Failure preparing request") + return + } + + resp, err := client.DescribeImageInStreamSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DescribeImageInStream", resp, "Failure sending request") + return + } + + result, err = client.DescribeImageInStreamResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "DescribeImageInStream", resp, "Failure responding to request") + } + + return +} + +// DescribeImageInStreamPreparer prepares the DescribeImageInStream request. +func (client BaseClient) DescribeImageInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser, maxCandidates string, language string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + queryParameters := map[string]interface{}{} + if len(maxCandidates) > 0 { + queryParameters["maxCandidates"] = autorest.Encode("query", maxCandidates) + } else { + queryParameters["maxCandidates"] = autorest.Encode("query", "1") + } + if len(string(language)) > 0 { + queryParameters["language"] = autorest.Encode("query", language) + } else { + queryParameters["language"] = autorest.Encode("query", "en") + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/octet-stream"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPath("/describe"), + autorest.WithFile(imageParameter), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DescribeImageInStreamSender sends the DescribeImageInStream request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) DescribeImageInStreamSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// DescribeImageInStreamResponder handles the response to the DescribeImageInStream request. The method always +// closes the http.Response Body. +func (client BaseClient) DescribeImageInStreamResponder(resp *http.Response) (result ImageDescription, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GenerateThumbnail this operation generates a thumbnail image with the user-specified width and height. By default, +// the service analyzes the image, identifies the region of interest (ROI), and generates smart cropping coordinates +// based on the ROI. Smart cropping helps when you specify an aspect ratio that differs from that of the input image. A +// successful response contains the thumbnail image binary. If the request failed, the response contains an error code +// and a message to help determine what went wrong. +// Parameters: +// width - width of the thumbnail. It must be between 1 and 1024. Recommended minimum of 50. +// height - height of the thumbnail. It must be between 1 and 1024. Recommended minimum of 50. +// imageURL - a JSON document with a URL pointing to the image that is to be analyzed. +// smartCropping - boolean flag for enabling smart cropping. +func (client BaseClient) GenerateThumbnail(ctx context.Context, width int32, height int32, imageURL ImageURL, smartCropping *bool) (result ReadCloser, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: width, + Constraints: []validation.Constraint{{Target: "width", Name: validation.InclusiveMaximum, Rule: 1023, Chain: nil}, + {Target: "width", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}, + {TargetValue: height, + Constraints: []validation.Constraint{{Target: "height", Name: validation.InclusiveMaximum, Rule: 1023, Chain: nil}, + {Target: "height", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}, + {TargetValue: imageURL, + Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("computervision.BaseClient", "GenerateThumbnail", err.Error()) + } + + req, err := client.GenerateThumbnailPreparer(ctx, width, height, imageURL, smartCropping) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GenerateThumbnail", nil, "Failure preparing request") + return + } + + resp, err := client.GenerateThumbnailSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GenerateThumbnail", resp, "Failure sending request") + return + } + + result, err = client.GenerateThumbnailResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GenerateThumbnail", resp, "Failure responding to request") + } + + return +} + +// GenerateThumbnailPreparer prepares the GenerateThumbnail request. +func (client BaseClient) GenerateThumbnailPreparer(ctx context.Context, width int32, height int32, imageURL ImageURL, smartCropping *bool) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + queryParameters := map[string]interface{}{ + "height": autorest.Encode("query", height), + "width": autorest.Encode("query", width), + } + if smartCropping != nil { + queryParameters["smartCropping"] = autorest.Encode("query", *smartCropping) + } else { + queryParameters["smartCropping"] = autorest.Encode("query", false) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPath("/generateThumbnail"), + autorest.WithJSON(imageURL), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GenerateThumbnailSender sends the GenerateThumbnail request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) GenerateThumbnailSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GenerateThumbnailResponder handles the response to the GenerateThumbnail request. The method always +// closes the http.Response Body. +func (client BaseClient) GenerateThumbnailResponder(resp *http.Response) (result ReadCloser, err error) { + result.Value = &resp.Body + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK)) + result.Response = autorest.Response{Response: resp} + return +} + +// GenerateThumbnailInStream this operation generates a thumbnail image with the user-specified width and height. By +// default, the service analyzes the image, identifies the region of interest (ROI), and generates smart cropping +// coordinates based on the ROI. Smart cropping helps when you specify an aspect ratio that differs from that of the +// input image. A successful response contains the thumbnail image binary. If the request failed, the response contains +// an error code and a message to help determine what went wrong. +// Parameters: +// width - width of the thumbnail. It must be between 1 and 1024. Recommended minimum of 50. +// height - height of the thumbnail. It must be between 1 and 1024. Recommended minimum of 50. +// imageParameter - an image stream. +// smartCropping - boolean flag for enabling smart cropping. +func (client BaseClient) GenerateThumbnailInStream(ctx context.Context, width int32, height int32, imageParameter io.ReadCloser, smartCropping *bool) (result ReadCloser, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: width, + Constraints: []validation.Constraint{{Target: "width", Name: validation.InclusiveMaximum, Rule: 1023, Chain: nil}, + {Target: "width", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}, + {TargetValue: height, + Constraints: []validation.Constraint{{Target: "height", Name: validation.InclusiveMaximum, Rule: 1023, Chain: nil}, + {Target: "height", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("computervision.BaseClient", "GenerateThumbnailInStream", err.Error()) + } + + req, err := client.GenerateThumbnailInStreamPreparer(ctx, width, height, imageParameter, smartCropping) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GenerateThumbnailInStream", nil, "Failure preparing request") + return + } + + resp, err := client.GenerateThumbnailInStreamSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GenerateThumbnailInStream", resp, "Failure sending request") + return + } + + result, err = client.GenerateThumbnailInStreamResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GenerateThumbnailInStream", resp, "Failure responding to request") + } + + return +} + +// GenerateThumbnailInStreamPreparer prepares the GenerateThumbnailInStream request. +func (client BaseClient) GenerateThumbnailInStreamPreparer(ctx context.Context, width int32, height int32, imageParameter io.ReadCloser, smartCropping *bool) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + queryParameters := map[string]interface{}{ + "height": autorest.Encode("query", height), + "width": autorest.Encode("query", width), + } + if smartCropping != nil { + queryParameters["smartCropping"] = autorest.Encode("query", *smartCropping) + } else { + queryParameters["smartCropping"] = autorest.Encode("query", false) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/octet-stream"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPath("/generateThumbnail"), + autorest.WithFile(imageParameter), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GenerateThumbnailInStreamSender sends the GenerateThumbnailInStream request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) GenerateThumbnailInStreamSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GenerateThumbnailInStreamResponder handles the response to the GenerateThumbnailInStream request. The method always +// closes the http.Response Body. +func (client BaseClient) GenerateThumbnailInStreamResponder(resp *http.Response) (result ReadCloser, err error) { + result.Value = &resp.Body + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK)) + result.Response = autorest.Response{Response: resp} + return +} + +// GetTextOperationResult this interface is used for getting text operation result. The URL to this interface should be +// retrieved from 'Operation-Location' field returned from Recognize Text interface. +// Parameters: +// operationID - id of the text operation returned in the response of the 'Recognize Text' +func (client BaseClient) GetTextOperationResult(ctx context.Context, operationID string) (result TextOperationResult, err error) { + req, err := client.GetTextOperationResultPreparer(ctx, operationID) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GetTextOperationResult", nil, "Failure preparing request") + return + } + + resp, err := client.GetTextOperationResultSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GetTextOperationResult", resp, "Failure sending request") + return + } + + result, err = client.GetTextOperationResultResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "GetTextOperationResult", resp, "Failure responding to request") + } + + return +} + +// GetTextOperationResultPreparer prepares the GetTextOperationResult request. +func (client BaseClient) GetTextOperationResultPreparer(ctx context.Context, operationID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + pathParameters := map[string]interface{}{ + "operationId": autorest.Encode("path", operationID), + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPathParameters("/textOperations/{operationId}", pathParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetTextOperationResultSender sends the GetTextOperationResult request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) GetTextOperationResultSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetTextOperationResultResponder handles the response to the GetTextOperationResult request. The method always +// closes the http.Response Body. +func (client BaseClient) GetTextOperationResultResponder(resp *http.Response) (result TextOperationResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListModels this operation returns the list of domain-specific models that are supported by the Computer Vision API. +// Currently, the API only supports one domain-specific model: a celebrity recognizer. A successful response will be +// returned in JSON. If the request failed, the response will contain an error code and a message to help understand +// what went wrong. +func (client BaseClient) ListModels(ctx context.Context) (result ListModelsResult, err error) { + req, err := client.ListModelsPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "ListModels", nil, "Failure preparing request") + return + } + + resp, err := client.ListModelsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "ListModels", resp, "Failure sending request") + return + } + + result, err = client.ListModelsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "ListModels", resp, "Failure responding to request") + } + + return +} + +// ListModelsPreparer prepares the ListModels request. +func (client BaseClient) ListModelsPreparer(ctx context.Context) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPath("/models")) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListModelsSender sends the ListModels request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) ListModelsSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListModelsResponder handles the response to the ListModels request. The method always +// closes the http.Response Body. +func (client BaseClient) ListModelsResponder(resp *http.Response) (result ListModelsResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// RecognizePrintedText optical Character Recognition (OCR) detects printed text in an image and extracts the +// recognized characters into a machine-usable character stream. Upon success, the OCR results will be returned. Upon +// failure, the error code together with an error message will be returned. The error code can be one of +// InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, NotSupportedLanguage, or +// InternalServerError. +// Parameters: +// detectOrientation - whether detect the text orientation in the image. With detectOrientation=true the OCR +// service tries to detect the image orientation and correct it before further processing (e.g. if it's +// upside-down). +// imageURL - a JSON document with a URL pointing to the image that is to be analyzed. +// language - the BCP-47 language code of the text to be detected in the image. The default value is 'unk' +func (client BaseClient) RecognizePrintedText(ctx context.Context, detectOrientation bool, imageURL ImageURL, language OcrLanguages) (result OcrResult, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: imageURL, + Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("computervision.BaseClient", "RecognizePrintedText", err.Error()) + } + + req, err := client.RecognizePrintedTextPreparer(ctx, detectOrientation, imageURL, language) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizePrintedText", nil, "Failure preparing request") + return + } + + resp, err := client.RecognizePrintedTextSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizePrintedText", resp, "Failure sending request") + return + } + + result, err = client.RecognizePrintedTextResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizePrintedText", resp, "Failure responding to request") + } + + return +} + +// RecognizePrintedTextPreparer prepares the RecognizePrintedText request. +func (client BaseClient) RecognizePrintedTextPreparer(ctx context.Context, detectOrientation bool, imageURL ImageURL, language OcrLanguages) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + queryParameters := map[string]interface{}{ + "detectOrientation": autorest.Encode("query", detectOrientation), + } + if len(string(language)) > 0 { + queryParameters["language"] = autorest.Encode("query", language) + } else { + queryParameters["language"] = autorest.Encode("query", "unk") + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPath("/ocr"), + autorest.WithJSON(imageURL), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RecognizePrintedTextSender sends the RecognizePrintedText request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) RecognizePrintedTextSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RecognizePrintedTextResponder handles the response to the RecognizePrintedText request. The method always +// closes the http.Response Body. +func (client BaseClient) RecognizePrintedTextResponder(resp *http.Response) (result OcrResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// RecognizePrintedTextInStream optical Character Recognition (OCR) detects printed text in an image and extracts the +// recognized characters into a machine-usable character stream. Upon success, the OCR results will be returned. Upon +// failure, the error code together with an error message will be returned. The error code can be one of +// InvalidImageUrl, InvalidImageFormat, InvalidImageSize, NotSupportedImage, NotSupportedLanguage, or +// InternalServerError. +// Parameters: +// detectOrientation - whether detect the text orientation in the image. With detectOrientation=true the OCR +// service tries to detect the image orientation and correct it before further processing (e.g. if it's +// upside-down). +// imageParameter - an image stream. +// language - the BCP-47 language code of the text to be detected in the image. The default value is 'unk' +func (client BaseClient) RecognizePrintedTextInStream(ctx context.Context, detectOrientation bool, imageParameter io.ReadCloser, language OcrLanguages) (result OcrResult, err error) { + req, err := client.RecognizePrintedTextInStreamPreparer(ctx, detectOrientation, imageParameter, language) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizePrintedTextInStream", nil, "Failure preparing request") + return + } + + resp, err := client.RecognizePrintedTextInStreamSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizePrintedTextInStream", resp, "Failure sending request") + return + } + + result, err = client.RecognizePrintedTextInStreamResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizePrintedTextInStream", resp, "Failure responding to request") + } + + return +} + +// RecognizePrintedTextInStreamPreparer prepares the RecognizePrintedTextInStream request. +func (client BaseClient) RecognizePrintedTextInStreamPreparer(ctx context.Context, detectOrientation bool, imageParameter io.ReadCloser, language OcrLanguages) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + queryParameters := map[string]interface{}{ + "detectOrientation": autorest.Encode("query", detectOrientation), + } + if len(string(language)) > 0 { + queryParameters["language"] = autorest.Encode("query", language) + } else { + queryParameters["language"] = autorest.Encode("query", "unk") + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/octet-stream"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPath("/ocr"), + autorest.WithFile(imageParameter), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RecognizePrintedTextInStreamSender sends the RecognizePrintedTextInStream request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) RecognizePrintedTextInStreamSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RecognizePrintedTextInStreamResponder handles the response to the RecognizePrintedTextInStream request. The method always +// closes the http.Response Body. +func (client BaseClient) RecognizePrintedTextInStreamResponder(resp *http.Response) (result OcrResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// RecognizeText recognize Text operation. When you use the Recognize Text interface, the response contains a field +// called 'Operation-Location'. The 'Operation-Location' field contains the URL that you must use for your Get +// Recognize Text Operation Result operation. +// Parameters: +// imageURL - a JSON document with a URL pointing to the image that is to be analyzed. +// mode - type of text to recognize. +func (client BaseClient) RecognizeText(ctx context.Context, imageURL ImageURL, mode TextRecognitionMode) (result autorest.Response, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: imageURL, + Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("computervision.BaseClient", "RecognizeText", err.Error()) + } + + req, err := client.RecognizeTextPreparer(ctx, imageURL, mode) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizeText", nil, "Failure preparing request") + return + } + + resp, err := client.RecognizeTextSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizeText", resp, "Failure sending request") + return + } + + result, err = client.RecognizeTextResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizeText", resp, "Failure responding to request") + } + + return +} + +// RecognizeTextPreparer prepares the RecognizeText request. +func (client BaseClient) RecognizeTextPreparer(ctx context.Context, imageURL ImageURL, mode TextRecognitionMode) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + queryParameters := map[string]interface{}{ + "mode": autorest.Encode("query", mode), + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPath("/recognizeText"), + autorest.WithJSON(imageURL), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RecognizeTextSender sends the RecognizeText request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) RecognizeTextSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RecognizeTextResponder handles the response to the RecognizeText request. The method always +// closes the http.Response Body. +func (client BaseClient) RecognizeTextResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + +// RecognizeTextInStream recognize Text operation. When you use the Recognize Text interface, the response contains a +// field called 'Operation-Location'. The 'Operation-Location' field contains the URL that you must use for your Get +// Recognize Text Operation Result operation. +// Parameters: +// imageParameter - an image stream. +// mode - type of text to recognize. +func (client BaseClient) RecognizeTextInStream(ctx context.Context, imageParameter io.ReadCloser, mode TextRecognitionMode) (result autorest.Response, err error) { + req, err := client.RecognizeTextInStreamPreparer(ctx, imageParameter, mode) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizeTextInStream", nil, "Failure preparing request") + return + } + + resp, err := client.RecognizeTextInStreamSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizeTextInStream", resp, "Failure sending request") + return + } + + result, err = client.RecognizeTextInStreamResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "RecognizeTextInStream", resp, "Failure responding to request") + } + + return +} + +// RecognizeTextInStreamPreparer prepares the RecognizeTextInStream request. +func (client BaseClient) RecognizeTextInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser, mode TextRecognitionMode) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + queryParameters := map[string]interface{}{ + "mode": autorest.Encode("query", mode), + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/octet-stream"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPath("/recognizeText"), + autorest.WithFile(imageParameter), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RecognizeTextInStreamSender sends the RecognizeTextInStream request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) RecognizeTextInStreamSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RecognizeTextInStreamResponder handles the response to the RecognizeTextInStream request. The method always +// closes the http.Response Body. +func (client BaseClient) RecognizeTextInStreamResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + +// TagImage this operation generates a list of words, or tags, that are relevant to the content of the supplied image. +// The Computer Vision API can return tags based on objects, living beings, scenery or actions found in images. Unlike +// categories, tags are not organized according to a hierarchical classification system, but correspond to image +// content. Tags may contain hints to avoid ambiguity or provide context, for example the tag 'cello' may be +// accompanied by the hint 'musical instrument'. All tags are in English. +// Parameters: +// imageURL - a JSON document with a URL pointing to the image that is to be analyzed. +// language - the desired language for output generation. If this parameter is not specified, the default value +// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified +// Chinese. +func (client BaseClient) TagImage(ctx context.Context, imageURL ImageURL, language string) (result TagResult, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: imageURL, + Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("computervision.BaseClient", "TagImage", err.Error()) + } + + req, err := client.TagImagePreparer(ctx, imageURL, language) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "TagImage", nil, "Failure preparing request") + return + } + + resp, err := client.TagImageSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "TagImage", resp, "Failure sending request") + return + } + + result, err = client.TagImageResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "TagImage", resp, "Failure responding to request") + } + + return +} + +// TagImagePreparer prepares the TagImage request. +func (client BaseClient) TagImagePreparer(ctx context.Context, imageURL ImageURL, language string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + queryParameters := map[string]interface{}{} + if len(string(language)) > 0 { + queryParameters["language"] = autorest.Encode("query", language) + } else { + queryParameters["language"] = autorest.Encode("query", "en") + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPath("/tag"), + autorest.WithJSON(imageURL), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// TagImageSender sends the TagImage request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) TagImageSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// TagImageResponder handles the response to the TagImage request. The method always +// closes the http.Response Body. +func (client BaseClient) TagImageResponder(resp *http.Response) (result TagResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// TagImageInStream this operation generates a list of words, or tags, that are relevant to the content of the supplied +// image. The Computer Vision API can return tags based on objects, living beings, scenery or actions found in images. +// Unlike categories, tags are not organized according to a hierarchical classification system, but correspond to image +// content. Tags may contain hints to avoid ambiguity or provide context, for example the tag 'cello' may be +// accompanied by the hint 'musical instrument'. All tags are in English. +// Parameters: +// imageParameter - an image stream. +// language - the desired language for output generation. If this parameter is not specified, the default value +// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified +// Chinese. +func (client BaseClient) TagImageInStream(ctx context.Context, imageParameter io.ReadCloser, language string) (result TagResult, err error) { + req, err := client.TagImageInStreamPreparer(ctx, imageParameter, language) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "TagImageInStream", nil, "Failure preparing request") + return + } + + resp, err := client.TagImageInStreamSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "TagImageInStream", resp, "Failure sending request") + return + } + + result, err = client.TagImageInStreamResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "computervision.BaseClient", "TagImageInStream", resp, "Failure responding to request") + } + + return +} + +// TagImageInStreamPreparer prepares the TagImageInStream request. +func (client BaseClient) TagImageInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser, language string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "AzureRegion": client.AzureRegion, + } + + queryParameters := map[string]interface{}{} + if len(string(language)) > 0 { + queryParameters["language"] = autorest.Encode("query", language) + } else { + queryParameters["language"] = autorest.Encode("query", "en") + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/octet-stream"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v2.0", urlParameters), + autorest.WithPath("/tag"), + autorest.WithFile(imageParameter), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// TagImageInStreamSender sends the TagImageInStream request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) TagImageInStreamSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// TagImageInStreamResponder handles the response to the TagImageInStream request. The method always +// closes the http.Response Body. +func (client BaseClient) TagImageInStreamResponder(resp *http.Response) (result TagResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/cognitiveservices/v2.0/computervision/models.go b/services/cognitiveservices/v2.0/computervision/models.go new file mode 100644 index 000000000000..eef6a245a7d1 --- /dev/null +++ b/services/cognitiveservices/v2.0/computervision/models.go @@ -0,0 +1,566 @@ +package computervision + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "encoding/json" + "github.com/Azure/go-autorest/autorest" + "io" +) + +// AzureRegions enumerates the values for azure regions. +type AzureRegions string + +const ( + // Australiaeast ... + Australiaeast AzureRegions = "australiaeast" + // Brazilsouth ... + Brazilsouth AzureRegions = "brazilsouth" + // Eastasia ... + Eastasia AzureRegions = "eastasia" + // Eastus ... + Eastus AzureRegions = "eastus" + // Eastus2 ... + Eastus2 AzureRegions = "eastus2" + // Northeurope ... + Northeurope AzureRegions = "northeurope" + // Southcentralus ... + Southcentralus AzureRegions = "southcentralus" + // Southeastasia ... + Southeastasia AzureRegions = "southeastasia" + // Westcentralus ... + Westcentralus AzureRegions = "westcentralus" + // Westeurope ... + Westeurope AzureRegions = "westeurope" + // Westus ... + Westus AzureRegions = "westus" + // Westus2 ... + Westus2 AzureRegions = "westus2" +) + +// PossibleAzureRegionsValues returns an array of possible values for the AzureRegions const type. +func PossibleAzureRegionsValues() []AzureRegions { + return []AzureRegions{Australiaeast, Brazilsouth, Eastasia, Eastus, Eastus2, Northeurope, Southcentralus, Southeastasia, Westcentralus, Westeurope, Westus, Westus2} +} + +// Details enumerates the values for details. +type Details string + +const ( + // Celebrities ... + Celebrities Details = "Celebrities" + // Landmarks ... + Landmarks Details = "Landmarks" +) + +// PossibleDetailsValues returns an array of possible values for the Details const type. +func PossibleDetailsValues() []Details { + return []Details{Celebrities, Landmarks} +} + +// ErrorCodes enumerates the values for error codes. +type ErrorCodes string + +const ( + // BadArgument ... + BadArgument ErrorCodes = "BadArgument" + // FailedToProcess ... + FailedToProcess ErrorCodes = "FailedToProcess" + // InternalServerError ... + InternalServerError ErrorCodes = "InternalServerError" + // InvalidDetails ... + InvalidDetails ErrorCodes = "InvalidDetails" + // InvalidImageFormat ... + InvalidImageFormat ErrorCodes = "InvalidImageFormat" + // InvalidImageSize ... + InvalidImageSize ErrorCodes = "InvalidImageSize" + // InvalidImageURL ... + InvalidImageURL ErrorCodes = "InvalidImageUrl" + // NotSupportedImage ... + NotSupportedImage ErrorCodes = "NotSupportedImage" + // NotSupportedLanguage ... + NotSupportedLanguage ErrorCodes = "NotSupportedLanguage" + // NotSupportedVisualFeature ... + NotSupportedVisualFeature ErrorCodes = "NotSupportedVisualFeature" + // StorageException ... + StorageException ErrorCodes = "StorageException" + // Timeout ... + Timeout ErrorCodes = "Timeout" + // Unspecified ... + Unspecified ErrorCodes = "Unspecified" +) + +// PossibleErrorCodesValues returns an array of possible values for the ErrorCodes const type. +func PossibleErrorCodesValues() []ErrorCodes { + return []ErrorCodes{BadArgument, FailedToProcess, InternalServerError, InvalidDetails, InvalidImageFormat, InvalidImageSize, InvalidImageURL, NotSupportedImage, NotSupportedLanguage, NotSupportedVisualFeature, StorageException, Timeout, Unspecified} +} + +// Gender enumerates the values for gender. +type Gender string + +const ( + // Female ... + Female Gender = "Female" + // Male ... + Male Gender = "Male" +) + +// PossibleGenderValues returns an array of possible values for the Gender const type. +func PossibleGenderValues() []Gender { + return []Gender{Female, Male} +} + +// OcrLanguages enumerates the values for ocr languages. +type OcrLanguages string + +const ( + // Ar ... + Ar OcrLanguages = "ar" + // Cs ... + Cs OcrLanguages = "cs" + // Da ... + Da OcrLanguages = "da" + // De ... + De OcrLanguages = "de" + // El ... + El OcrLanguages = "el" + // En ... + En OcrLanguages = "en" + // Es ... + Es OcrLanguages = "es" + // Fi ... + Fi OcrLanguages = "fi" + // Fr ... + Fr OcrLanguages = "fr" + // Hu ... + Hu OcrLanguages = "hu" + // It ... + It OcrLanguages = "it" + // Ja ... + Ja OcrLanguages = "ja" + // Ko ... + Ko OcrLanguages = "ko" + // Nb ... + Nb OcrLanguages = "nb" + // Nl ... + Nl OcrLanguages = "nl" + // Pl ... + Pl OcrLanguages = "pl" + // Pt ... + Pt OcrLanguages = "pt" + // Ro ... + Ro OcrLanguages = "ro" + // Ru ... + Ru OcrLanguages = "ru" + // Sk ... + Sk OcrLanguages = "sk" + // SrCyrl ... + SrCyrl OcrLanguages = "sr-Cyrl" + // SrLatn ... + SrLatn OcrLanguages = "sr-Latn" + // Sv ... + Sv OcrLanguages = "sv" + // Tr ... + Tr OcrLanguages = "tr" + // Unk ... + Unk OcrLanguages = "unk" + // ZhHans ... + ZhHans OcrLanguages = "zh-Hans" + // ZhHant ... + ZhHant OcrLanguages = "zh-Hant" +) + +// PossibleOcrLanguagesValues returns an array of possible values for the OcrLanguages const type. +func PossibleOcrLanguagesValues() []OcrLanguages { + return []OcrLanguages{Ar, Cs, Da, De, El, En, Es, Fi, Fr, Hu, It, Ja, Ko, Nb, Nl, Pl, Pt, Ro, Ru, Sk, SrCyrl, SrLatn, Sv, Tr, Unk, ZhHans, ZhHant} +} + +// TextOperationStatusCodes enumerates the values for text operation status codes. +type TextOperationStatusCodes string + +const ( + // Failed ... + Failed TextOperationStatusCodes = "Failed" + // NotStarted ... + NotStarted TextOperationStatusCodes = "Not Started" + // Running ... + Running TextOperationStatusCodes = "Running" + // Succeeded ... + Succeeded TextOperationStatusCodes = "Succeeded" +) + +// PossibleTextOperationStatusCodesValues returns an array of possible values for the TextOperationStatusCodes const type. +func PossibleTextOperationStatusCodesValues() []TextOperationStatusCodes { + return []TextOperationStatusCodes{Failed, NotStarted, Running, Succeeded} +} + +// TextRecognitionMode enumerates the values for text recognition mode. +type TextRecognitionMode string + +const ( + // Handwritten ... + Handwritten TextRecognitionMode = "Handwritten" + // Printed ... + Printed TextRecognitionMode = "Printed" +) + +// PossibleTextRecognitionModeValues returns an array of possible values for the TextRecognitionMode const type. +func PossibleTextRecognitionModeValues() []TextRecognitionMode { + return []TextRecognitionMode{Handwritten, Printed} +} + +// VisualFeatureTypes enumerates the values for visual feature types. +type VisualFeatureTypes string + +const ( + // VisualFeatureTypesAdult ... + VisualFeatureTypesAdult VisualFeatureTypes = "Adult" + // VisualFeatureTypesCategories ... + VisualFeatureTypesCategories VisualFeatureTypes = "Categories" + // VisualFeatureTypesColor ... + VisualFeatureTypesColor VisualFeatureTypes = "Color" + // VisualFeatureTypesDescription ... + VisualFeatureTypesDescription VisualFeatureTypes = "Description" + // VisualFeatureTypesFaces ... + VisualFeatureTypesFaces VisualFeatureTypes = "Faces" + // VisualFeatureTypesImageType ... + VisualFeatureTypesImageType VisualFeatureTypes = "ImageType" + // VisualFeatureTypesTags ... + VisualFeatureTypesTags VisualFeatureTypes = "Tags" +) + +// PossibleVisualFeatureTypesValues returns an array of possible values for the VisualFeatureTypes const type. +func PossibleVisualFeatureTypesValues() []VisualFeatureTypes { + return []VisualFeatureTypes{VisualFeatureTypesAdult, VisualFeatureTypesCategories, VisualFeatureTypesColor, VisualFeatureTypesDescription, VisualFeatureTypesFaces, VisualFeatureTypesImageType, VisualFeatureTypesTags} +} + +// AdultInfo an object describing whether the image contains adult-oriented content and/or is racy. +type AdultInfo struct { + // IsAdultContent - A value indicating if the image contains adult-oriented content. + IsAdultContent *bool `json:"isAdultContent,omitempty"` + // IsRacyContent - A value indicating if the image is race. + IsRacyContent *bool `json:"isRacyContent,omitempty"` + // AdultScore - Score from 0 to 1 that indicates how much of adult content is within the image. + AdultScore *float64 `json:"adultScore,omitempty"` + // RacyScore - Score from 0 to 1 that indicates how suggestive is the image. + RacyScore *float64 `json:"racyScore,omitempty"` +} + +// Category an object describing identified category. +type Category struct { + // Name - Name of the category. + Name *string `json:"name,omitempty"` + // Score - Scoring of the category. + Score *float64 `json:"score,omitempty"` + Detail *CategoryDetail `json:"detail,omitempty"` +} + +// CategoryDetail an object describing additional category details. +type CategoryDetail struct { + // Celebrities - An array of celebrities if any identified. + Celebrities *[]CelebritiesModel `json:"celebrities,omitempty"` +} + +// CelebritiesModel an object describing possible celebrity identification. +type CelebritiesModel struct { + // Name - Name of the celebrity. + Name *string `json:"name,omitempty"` + // Confidence - Level of confidence ranging from 0 to 1. + Confidence *float64 `json:"confidence,omitempty"` + FaceRectangle *FaceRectangle `json:"faceRectangle,omitempty"` +} + +// CelebrityResults list of celebrities recognized in the image. +type CelebrityResults struct { + Celebrities *[]CelebritiesModel `json:"celebrities,omitempty"` + // RequestID - Id of the REST API request. + RequestID *string `json:"requestId,omitempty"` + Metadata *ImageMetadata `json:"metadata,omitempty"` +} + +// ColorInfo an object providing additional metadata describing color attributes. +type ColorInfo struct { + // DominantColorForeground - Possible dominant foreground color. + DominantColorForeground *string `json:"dominantColorForeground,omitempty"` + // DominantColorBackground - Possible dominant background color. + DominantColorBackground *string `json:"dominantColorBackground,omitempty"` + // DominantColors - An array of possible dominant colors. + DominantColors *[]string `json:"dominantColors,omitempty"` + // AccentColor - Possible accent color. + AccentColor *string `json:"accentColor,omitempty"` + // IsBWImg - A value indicating if the image is black and white. + IsBWImg *bool `json:"isBWImg,omitempty"` +} + +// DomainModelResults result of image analysis using a specific domain model including additional metadata. +type DomainModelResults struct { + autorest.Response `json:"-"` + // Result - Model-specific response + Result interface{} `json:"result,omitempty"` + // RequestID - Id of the REST API request. + RequestID *string `json:"requestId,omitempty"` + Metadata *ImageMetadata `json:"metadata,omitempty"` +} + +// Error ... +type Error struct { + // Code - The error code. Possible values include: 'InvalidImageURL', 'InvalidImageFormat', 'InvalidImageSize', 'NotSupportedVisualFeature', 'NotSupportedImage', 'InvalidDetails', 'NotSupportedLanguage', 'BadArgument', 'FailedToProcess', 'Timeout', 'InternalServerError', 'Unspecified', 'StorageException' + Code ErrorCodes `json:"code,omitempty"` + // Message - A message explaining the error reported by the service. + Message *string `json:"message,omitempty"` + // RequestID - A unique request identifier. + RequestID *string `json:"requestId,omitempty"` +} + +// FaceDescription an object describing a face identified in the image. +type FaceDescription struct { + // Age - Possible age of the face. + Age *int32 `json:"age,omitempty"` + // Gender - Possible gender of the face. Possible values include: 'Male', 'Female' + Gender Gender `json:"gender,omitempty"` + FaceRectangle *FaceRectangle `json:"faceRectangle,omitempty"` +} + +// FaceRectangle an object describing face rectangle. +type FaceRectangle struct { + // Left - X-coordinate of the top left point of the face. + Left *int32 `json:"left,omitempty"` + // Top - Y-coordinate of the top left point of the face. + Top *int32 `json:"top,omitempty"` + // Width - Width measured from the top-left point of the face. + Width *int32 `json:"width,omitempty"` + // Height - Height measured from the top-left point of the face. + Height *int32 `json:"height,omitempty"` +} + +// ImageAnalysis result of AnalyzeImage operation. +type ImageAnalysis struct { + autorest.Response `json:"-"` + // Categories - An array indicating identified categories. + Categories *[]Category `json:"categories,omitempty"` + Adult *AdultInfo `json:"adult,omitempty"` + Color *ColorInfo `json:"color,omitempty"` + ImageType *ImageType `json:"imageType,omitempty"` + // Tags - A list of tags with confidence level. + Tags *[]ImageTag `json:"tags,omitempty"` + Description *ImageDescriptionDetails `json:"description,omitempty"` + // Faces - An array of possible faces within the image. + Faces *[]FaceDescription `json:"faces,omitempty"` + // RequestID - Id of the request for tracking purposes. + RequestID *string `json:"requestId,omitempty"` + Metadata *ImageMetadata `json:"metadata,omitempty"` +} + +// ImageCaption an image caption, i.e. a brief description of what the image depicts. +type ImageCaption struct { + // Text - The text of the caption + Text *string `json:"text,omitempty"` + // Confidence - The level of confidence the service has in the caption + Confidence *float64 `json:"confidence,omitempty"` +} + +// ImageDescription a collection of content tags, along with a list of captions sorted by confidence level, and +// image metadata. +type ImageDescription struct { + autorest.Response `json:"-"` + *ImageDescriptionDetails `json:"description,omitempty"` +} + +// MarshalJSON is the custom marshaler for ImageDescription. +func (ID ImageDescription) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ID.ImageDescriptionDetails != nil { + objectMap["description"] = ID.ImageDescriptionDetails + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for ImageDescription struct. +func (ID *ImageDescription) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "description": + if v != nil { + var imageDescriptionDetails ImageDescriptionDetails + err = json.Unmarshal(*v, &imageDescriptionDetails) + if err != nil { + return err + } + ID.ImageDescriptionDetails = &imageDescriptionDetails + } + } + } + + return nil +} + +// ImageDescriptionDetails a collection of content tags, along with a list of captions sorted by confidence level, +// and image metadata. +type ImageDescriptionDetails struct { + // Tags - A collection of image tags. + Tags *[]string `json:"tags,omitempty"` + // Captions - A list of captions, sorted by confidence level. + Captions *[]ImageCaption `json:"captions,omitempty"` + // RequestID - Id of the REST API request. + RequestID *string `json:"requestId,omitempty"` + Metadata *ImageMetadata `json:"metadata,omitempty"` +} + +// ImageMetadata image metadata +type ImageMetadata struct { + // Width - Image width + Width *int32 `json:"width,omitempty"` + // Height - Image height + Height *int32 `json:"height,omitempty"` + // Format - Image format + Format *string `json:"format,omitempty"` +} + +// ImageTag an image caption, i.e. a brief description of what the image depicts. +type ImageTag struct { + // Name - The tag value + Name *string `json:"name,omitempty"` + // Confidence - The level of confidence the service has in the caption + Confidence *float64 `json:"confidence,omitempty"` +} + +// ImageType an object providing possible image types and matching confidence levels. +type ImageType struct { + // ClipArtType - Confidence level that the image is a clip art. + ClipArtType *float64 `json:"clipArtType,omitempty"` + // LineDrawingType - Confidence level that the image is a line drawing. + LineDrawingType *float64 `json:"lineDrawingType,omitempty"` +} + +// ImageURL ... +type ImageURL struct { + // URL - Publicly reachable URL of an image + URL *string `json:"url,omitempty"` +} + +// LandmarkResults list of landmarks recognized in the image. +type LandmarkResults struct { + Landmarks *[]LandmarkResultsLandmarksItem `json:"landmarks,omitempty"` + // RequestID - Id of the REST API request. + RequestID *string `json:"requestId,omitempty"` + Metadata *ImageMetadata `json:"metadata,omitempty"` +} + +// LandmarkResultsLandmarksItem a landmark recognized in the image +type LandmarkResultsLandmarksItem struct { + // Name - Name of the landmark. + Name *string `json:"name,omitempty"` + // Confidence - Confidence level for the landmark recognition. + Confidence *float64 `json:"confidence,omitempty"` +} + +// Line ... +type Line struct { + BoundingBox *[]int32 `json:"boundingBox,omitempty"` + Text *string `json:"text,omitempty"` + Words *[]Word `json:"words,omitempty"` +} + +// ListModelsResult result of the List Domain Models operation. +type ListModelsResult struct { + autorest.Response `json:"-"` + // ModelsProperty - An array of supported models. + ModelsProperty *[]ModelDescription `json:"models,omitempty"` +} + +// ModelDescription an object describing supported model by name and categories. +type ModelDescription struct { + Name *string `json:"name,omitempty"` + Categories *[]string `json:"categories,omitempty"` +} + +// OcrLine an object describing a single recognized line of text. +type OcrLine struct { + // BoundingBox - Bounding box of a recognized line. The four integers represent the x-coordinate of the left edge, the y-coordinate of the top edge, width, and height of the bounding box, in the coordinate system of the input image, after it has been rotated around its center according to the detected text angle (see textAngle property), with the origin at the top-left corner, and the y-axis pointing down. + BoundingBox *string `json:"boundingBox,omitempty"` + // Words - An array of objects, where each object represents a recognized word. + Words *[]OcrWord `json:"words,omitempty"` +} + +// OcrRegion a region consists of multiple lines (e.g. a column of text in a multi-column document). +type OcrRegion struct { + // BoundingBox - Bounding box of a recognized region. The four integers represent the x-coordinate of the left edge, the y-coordinate of the top edge, width, and height of the bounding box, in the coordinate system of the input image, after it has been rotated around its center according to the detected text angle (see textAngle property), with the origin at the top-left corner, and the y-axis pointing down. + BoundingBox *string `json:"boundingBox,omitempty"` + Lines *[]OcrLine `json:"lines,omitempty"` +} + +// OcrResult ... +type OcrResult struct { + autorest.Response `json:"-"` + // Language - The BCP-47 language code of the text in the image. + Language *string `json:"language,omitempty"` + // TextAngle - The angle, in degrees, of the detected text with respect to the closest horizontal or vertical direction. After rotating the input image clockwise by this angle, the recognized text lines become horizontal or vertical. In combination with the orientation property it can be used to overlay recognition results correctly on the original image, by rotating either the original image or recognition results by a suitable angle around the center of the original image. If the angle cannot be confidently detected, this property is not present. If the image contains text at different angles, only part of the text will be recognized correctly. + TextAngle *float64 `json:"textAngle,omitempty"` + // Orientation - Orientation of the text recognized in the image. The value (up,down,left, or right) refers to the direction that the top of the recognized text is facing, after the image has been rotated around its center according to the detected text angle (see textAngle property). + Orientation *string `json:"orientation,omitempty"` + // Regions - An array of objects, where each object represents a region of recognized text. + Regions *[]OcrRegion `json:"regions,omitempty"` +} + +// OcrWord information on a recognized word. +type OcrWord struct { + // BoundingBox - Bounding box of a recognized word. The four integers represent the x-coordinate of the left edge, the y-coordinate of the top edge, width, and height of the bounding box, in the coordinate system of the input image, after it has been rotated around its center according to the detected text angle (see textAngle property), with the origin at the top-left corner, and the y-axis pointing down. + BoundingBox *string `json:"boundingBox,omitempty"` + // Text - String value of a recognized word. + Text *string `json:"text,omitempty"` +} + +// ReadCloser ... +type ReadCloser struct { + autorest.Response `json:"-"` + Value *io.ReadCloser `json:"value,omitempty"` +} + +// RecognitionResult ... +type RecognitionResult struct { + Lines *[]Line `json:"lines,omitempty"` +} + +// TagResult the results of a image tag operation, including any tags and image metadata. +type TagResult struct { + autorest.Response `json:"-"` + // Tags - A list of tags with confidence level. + Tags *[]ImageTag `json:"tags,omitempty"` + // RequestID - Id of the REST API request. + RequestID *string `json:"requestId,omitempty"` + Metadata *ImageMetadata `json:"metadata,omitempty"` +} + +// TextOperationResult ... +type TextOperationResult struct { + autorest.Response `json:"-"` + // Status - Status of the text operation. Possible values include: 'NotStarted', 'Running', 'Failed', 'Succeeded' + Status TextOperationStatusCodes `json:"status,omitempty"` + RecognitionResult *RecognitionResult `json:"recognitionResult,omitempty"` +} + +// Word ... +type Word struct { + BoundingBox *[]int32 `json:"boundingBox,omitempty"` + Text *string `json:"text,omitempty"` +} diff --git a/services/cognitiveservices/v2.0/computervision/version.go b/services/cognitiveservices/v2.0/computervision/version.go new file mode 100644 index 000000000000..e5fe9ed326ff --- /dev/null +++ b/services/cognitiveservices/v2.0/computervision/version.go @@ -0,0 +1,30 @@ +package computervision + +import "github.com/Azure/azure-sdk-for-go/version" + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// UserAgent returns the UserAgent string to use when sending http.Requests. +func UserAgent() string { + return "Azure-SDK-For-Go/" + version.Number + " computervision/2.0" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return version.Number +} From 80d1fa72e602e22342582e490a15cf7ee8e26f34 Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Thu, 14 Jun 2018 20:28:21 +0000 Subject: [PATCH 2/3] Generated from 973322cfd6ec2ced60a732f53b5318ceded5de7b Fix validation errors --- .../computervision/models.go | 2 +- .../v2.0/computervision/models.go | 38 ++++++++++++++++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/profiles/preview/cognitiveservices/computervision/models.go b/profiles/preview/cognitiveservices/computervision/models.go index b4fdd1d8b59a..ba35b2280cb3 100644 --- a/profiles/preview/cognitiveservices/computervision/models.go +++ b/profiles/preview/cognitiveservices/computervision/models.go @@ -150,7 +150,7 @@ type ImageTag = original.ImageTag type ImageType = original.ImageType type ImageURL = original.ImageURL type LandmarkResults = original.LandmarkResults -type LandmarkResultsLandmarksItem = original.LandmarkResultsLandmarksItem +type LandmarksModel = original.LandmarksModel type Line = original.Line type ListModelsResult = original.ListModelsResult type ModelDescription = original.ModelDescription diff --git a/services/cognitiveservices/v2.0/computervision/models.go b/services/cognitiveservices/v2.0/computervision/models.go index eef6a245a7d1..d4a2db5d0268 100644 --- a/services/cognitiveservices/v2.0/computervision/models.go +++ b/services/cognitiveservices/v2.0/computervision/models.go @@ -274,6 +274,8 @@ type Category struct { type CategoryDetail struct { // Celebrities - An array of celebrities if any identified. Celebrities *[]CelebritiesModel `json:"celebrities,omitempty"` + // Landmarks - An array of landmarks if any identified. + Landmarks *[]LandmarksModel `json:"landmarks,omitempty"` } // CelebritiesModel an object describing possible celebrity identification. @@ -379,6 +381,9 @@ type ImageCaption struct { type ImageDescription struct { autorest.Response `json:"-"` *ImageDescriptionDetails `json:"description,omitempty"` + // RequestID - Id of the REST API request. + RequestID *string `json:"requestId,omitempty"` + Metadata *ImageMetadata `json:"metadata,omitempty"` } // MarshalJSON is the custom marshaler for ImageDescription. @@ -387,6 +392,12 @@ func (ID ImageDescription) MarshalJSON() ([]byte, error) { if ID.ImageDescriptionDetails != nil { objectMap["description"] = ID.ImageDescriptionDetails } + if ID.RequestID != nil { + objectMap["requestId"] = ID.RequestID + } + if ID.Metadata != nil { + objectMap["metadata"] = ID.Metadata + } return json.Marshal(objectMap) } @@ -408,6 +419,24 @@ func (ID *ImageDescription) UnmarshalJSON(body []byte) error { } ID.ImageDescriptionDetails = &imageDescriptionDetails } + case "requestId": + if v != nil { + var requestID string + err = json.Unmarshal(*v, &requestID) + if err != nil { + return err + } + ID.RequestID = &requestID + } + case "metadata": + if v != nil { + var metadata ImageMetadata + err = json.Unmarshal(*v, &metadata) + if err != nil { + return err + } + ID.Metadata = &metadata + } } } @@ -421,9 +450,6 @@ type ImageDescriptionDetails struct { Tags *[]string `json:"tags,omitempty"` // Captions - A list of captions, sorted by confidence level. Captions *[]ImageCaption `json:"captions,omitempty"` - // RequestID - Id of the REST API request. - RequestID *string `json:"requestId,omitempty"` - Metadata *ImageMetadata `json:"metadata,omitempty"` } // ImageMetadata image metadata @@ -460,14 +486,14 @@ type ImageURL struct { // LandmarkResults list of landmarks recognized in the image. type LandmarkResults struct { - Landmarks *[]LandmarkResultsLandmarksItem `json:"landmarks,omitempty"` + Landmarks *[]LandmarksModel `json:"landmarks,omitempty"` // RequestID - Id of the REST API request. RequestID *string `json:"requestId,omitempty"` Metadata *ImageMetadata `json:"metadata,omitempty"` } -// LandmarkResultsLandmarksItem a landmark recognized in the image -type LandmarkResultsLandmarksItem struct { +// LandmarksModel a landmark recognized in the image +type LandmarksModel struct { // Name - Name of the landmark. Name *string `json:"name,omitempty"` // Confidence - Confidence level for the landmark recognition. From 09965712c234c33d6502127e2dd11c223d7d963d Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Thu, 14 Jun 2018 20:59:23 +0000 Subject: [PATCH 3/3] Generated from 70efe042d607cbd973734e432da395ed35191a03 Add Spanish support for ServiceLanguage This is for parity with V1. --- .../v2.0/computervision/client.go | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/services/cognitiveservices/v2.0/computervision/client.go b/services/cognitiveservices/v2.0/computervision/client.go index 93de86373be9..a5791fad8cb7 100644 --- a/services/cognitiveservices/v2.0/computervision/client.go +++ b/services/cognitiveservices/v2.0/computervision/client.go @@ -70,8 +70,8 @@ func NewWithoutDefaults(azureRegion AzureRegions) BaseClient { // comma-separated. Valid visual feature types include:Celebrities - identifies celebrities if detected in the // image. // language - the desired language for output generation. If this parameter is not specified, the default value -// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified -// Chinese. +// is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, +// zh - Simplified Chinese. func (client BaseClient) AnalyzeImage(ctx context.Context, imageURL ImageURL, visualFeatures []VisualFeatureTypes, details []Details, language string) (result ImageAnalysis, err error) { if err := validation.Validate([]validation.Validation{ {TargetValue: imageURL, @@ -158,8 +158,8 @@ func (client BaseClient) AnalyzeImageResponder(resp *http.Response) (result Imag // model - the domain-specific content to recognize. // imageURL - a JSON document with a URL pointing to the image that is to be analyzed. // language - the desired language for output generation. If this parameter is not specified, the default value -// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified -// Chinese. +// is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, +// zh - Simplified Chinese. func (client BaseClient) AnalyzeImageByDomain(ctx context.Context, model string, imageURL ImageURL, language string) (result DomainModelResults, err error) { if err := validation.Validate([]validation.Validation{ {TargetValue: imageURL, @@ -244,8 +244,8 @@ func (client BaseClient) AnalyzeImageByDomainResponder(resp *http.Response) (res // model - the domain-specific content to recognize. // imageParameter - an image stream. // language - the desired language for output generation. If this parameter is not specified, the default value -// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified -// Chinese. +// is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, +// zh - Simplified Chinese. func (client BaseClient) AnalyzeImageByDomainInStream(ctx context.Context, model string, imageParameter io.ReadCloser, language string) (result DomainModelResults, err error) { req, err := client.AnalyzeImageByDomainInStreamPreparer(ctx, model, imageParameter, language) if err != nil { @@ -330,8 +330,8 @@ func (client BaseClient) AnalyzeImageByDomainInStreamResponder(resp *http.Respon // comma-separated. Valid visual feature types include:Celebrities - identifies celebrities if detected in the // image. // language - the desired language for output generation. If this parameter is not specified, the default value -// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified -// Chinese. +// is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, +// zh - Simplified Chinese. func (client BaseClient) AnalyzeImageInStream(ctx context.Context, imageParameter io.ReadCloser, visualFeatures []VisualFeatureTypes, details string, language string) (result ImageAnalysis, err error) { req, err := client.AnalyzeImageInStreamPreparer(ctx, imageParameter, visualFeatures, details, language) if err != nil { @@ -413,8 +413,8 @@ func (client BaseClient) AnalyzeImageInStreamResponder(resp *http.Response) (res // imageURL - a JSON document with a URL pointing to the image that is to be analyzed. // maxCandidates - maximum number of candidate descriptions to be returned. The default is 1. // language - the desired language for output generation. If this parameter is not specified, the default value -// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified -// Chinese. +// is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, +// zh - Simplified Chinese. func (client BaseClient) DescribeImage(ctx context.Context, imageURL ImageURL, maxCandidates string, language string) (result ImageDescription, err error) { if err := validation.Validate([]validation.Validation{ {TargetValue: imageURL, @@ -501,8 +501,8 @@ func (client BaseClient) DescribeImageResponder(resp *http.Response) (result Ima // imageParameter - an image stream. // maxCandidates - maximum number of candidate descriptions to be returned. The default is 1. // language - the desired language for output generation. If this parameter is not specified, the default value -// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified -// Chinese. +// is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, +// zh - Simplified Chinese. func (client BaseClient) DescribeImageInStream(ctx context.Context, imageParameter io.ReadCloser, maxCandidates string, language string) (result ImageDescription, err error) { req, err := client.DescribeImageInStreamPreparer(ctx, imageParameter, maxCandidates, language) if err != nil { @@ -1181,8 +1181,8 @@ func (client BaseClient) RecognizeTextInStreamResponder(resp *http.Response) (re // Parameters: // imageURL - a JSON document with a URL pointing to the image that is to be analyzed. // language - the desired language for output generation. If this parameter is not specified, the default value -// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified -// Chinese. +// is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, +// zh - Simplified Chinese. func (client BaseClient) TagImage(ctx context.Context, imageURL ImageURL, language string) (result TagResult, err error) { if err := validation.Validate([]validation.Validation{ {TargetValue: imageURL, @@ -1262,8 +1262,8 @@ func (client BaseClient) TagImageResponder(resp *http.Response) (result TagResul // Parameters: // imageParameter - an image stream. // language - the desired language for output generation. If this parameter is not specified, the default value -// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified -// Chinese. +// is "en".Supported languages:en - English, Default. es - Spanish, ja - Japanese, pt - Portuguese, +// zh - Simplified Chinese. func (client BaseClient) TagImageInStream(ctx context.Context, imageParameter io.ReadCloser, language string) (result TagResult, err error) { req, err := client.TagImageInStreamPreparer(ctx, imageParameter, language) if err != nil {