Share via


ContentSafetyClient.AnalyzeImage Method

Definition

Overloads

AnalyzeImage(AnalyzeImageOptions, CancellationToken)

Analyze Image.

AnalyzeImage(Uri, CancellationToken)

Analyze Image with Blob URI.

AnalyzeImage(RequestContent, RequestContext)

[Protocol Method] Analyze Image

AnalyzeImage(BinaryData, CancellationToken)

Analyze Image with Binary Data.

AnalyzeImage(AnalyzeImageOptions, CancellationToken)

Source:
ContentSafetyClient.cs
Source:
ContentSafetyClient.cs

Analyze Image.

public virtual Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult> AnalyzeImage (Azure.AI.ContentSafety.AnalyzeImageOptions options, System.Threading.CancellationToken cancellationToken = default);
public virtual Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult> AnalyzeImage (Azure.AI.ContentSafety.AnalyzeImageOptions body, System.Threading.CancellationToken cancellationToken = default);
abstract member AnalyzeImage : Azure.AI.ContentSafety.AnalyzeImageOptions * System.Threading.CancellationToken -> Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>
override this.AnalyzeImage : Azure.AI.ContentSafety.AnalyzeImageOptions * System.Threading.CancellationToken -> Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>
abstract member AnalyzeImage : Azure.AI.ContentSafety.AnalyzeImageOptions * System.Threading.CancellationToken -> Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>
override this.AnalyzeImage : Azure.AI.ContentSafety.AnalyzeImageOptions * System.Threading.CancellationToken -> Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>
Public Overridable Function AnalyzeImage (options As AnalyzeImageOptions, Optional cancellationToken As CancellationToken = Nothing) As Response(Of AnalyzeImageResult)
Public Overridable Function AnalyzeImage (body As AnalyzeImageOptions, Optional cancellationToken As CancellationToken = Nothing) As Response(Of AnalyzeImageResult)

Parameters

optionsbody
AnalyzeImageOptions

The image analysis request.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

options is null.

Examples

This sample shows how to call AnalyzeImage.

Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
ContentSafetyClient client = new ContentSafetyClient(endpoint, credential);

AnalyzeImageOptions options = new AnalyzeImageOptions(new ContentSafetyImageData());
Response<AnalyzeImageResult> response = client.AnalyzeImage(options);

This sample shows how to call AnalyzeImage with all parameters.

Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
ContentSafetyClient client = new ContentSafetyClient(endpoint, credential);

AnalyzeImageOptions options = new AnalyzeImageOptions(new ContentSafetyImageData())
{
    Categories = { ImageCategory.Hate },
    OutputType = AnalyzeImageOutputType.FourSeverityLevels,
};
Response<AnalyzeImageResult> response = client.AnalyzeImage(options);

Remarks

A synchronous API for the analysis of potentially harmful image content. Currently, it supports four categories: Hate, SelfHarm, Sexual, and Violence.

Applies to

AnalyzeImage(Uri, CancellationToken)

Source:
ContentSafetyClient.cs

Analyze Image with Blob URI.

public virtual Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult> AnalyzeImage (Uri blobUri, System.Threading.CancellationToken cancellationToken = default);
abstract member AnalyzeImage : Uri * System.Threading.CancellationToken -> Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>
override this.AnalyzeImage : Uri * System.Threading.CancellationToken -> Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>
Public Overridable Function AnalyzeImage (blobUri As Uri, Optional cancellationToken As CancellationToken = Nothing) As Response(Of AnalyzeImageResult)

Parameters

blobUri
Uri
cancellationToken
CancellationToken

Returns

Applies to

AnalyzeImage(RequestContent, RequestContext)

Source:
ContentSafetyClient.cs
Source:
ContentSafetyClient.cs

[Protocol Method] Analyze Image

public virtual Azure.Response AnalyzeImage (Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member AnalyzeImage : Azure.Core.RequestContent * Azure.RequestContext -> Azure.Response
override this.AnalyzeImage : Azure.Core.RequestContent * Azure.RequestContext -> Azure.Response
Public Overridable Function AnalyzeImage (content As RequestContent, Optional context As RequestContext = Nothing) As Response

Parameters

content
RequestContent

The content to send as the body of the request.

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The response returned from the service.

Exceptions

content is null.

Service returned a non-success status code.

Examples

This sample shows how to call AnalyzeImage and parse the result.

Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
ContentSafetyClient client = new ContentSafetyClient(endpoint, credential);

using RequestContent content = RequestContent.Create(new
{
    image = new object(),
});
Response response = client.AnalyzeImage(content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("category").ToString());

This sample shows how to call AnalyzeImage with all request content and parse the result.

Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
ContentSafetyClient client = new ContentSafetyClient(endpoint, credential);

using RequestContent content = RequestContent.Create(new
{
    image = new
    {
        content = new object(),
        blobUrl = "http://localhost:3000",
    },
    categories = new object[]
    {
        "Hate"
    },
    outputType = "FourSeverityLevels",
});
Response response = client.AnalyzeImage(content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("category").ToString());
Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("severity").ToString());

Applies to

AnalyzeImage(BinaryData, CancellationToken)

Source:
ContentSafetyClient.cs

Analyze Image with Binary Data.

public virtual Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult> AnalyzeImage (BinaryData content, System.Threading.CancellationToken cancellationToken = default);
abstract member AnalyzeImage : BinaryData * System.Threading.CancellationToken -> Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>
override this.AnalyzeImage : BinaryData * System.Threading.CancellationToken -> Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>
Public Overridable Function AnalyzeImage (content As BinaryData, Optional cancellationToken As CancellationToken = Nothing) As Response(Of AnalyzeImageResult)

Parameters

content
BinaryData
cancellationToken
CancellationToken

Returns

Applies to