FaceClient.FindSimilar Method

Definition

Overloads

FindSimilar(Guid, IEnumerable<Guid>, Nullable<Int32>, Nullable<FindSimilarMatchMode>, CancellationToken)

Given query face's faceId, to search the similar-looking faces from a faceId array. A faceId array contains the faces created by Detect.

FindSimilar(RequestContent, RequestContext)

[Protocol Method] Given query face's faceId, to search the similar-looking faces from a faceId array. A faceId array contains the faces created by Detect.

FindSimilar(Guid, IEnumerable<Guid>, Nullable<Int32>, Nullable<FindSimilarMatchMode>, CancellationToken)

Source:
FaceClient.cs

Given query face's faceId, to search the similar-looking faces from a faceId array. A faceId array contains the faces created by Detect.

public virtual Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Vision.Face.FaceFindSimilarResult>> FindSimilar (Guid faceId, System.Collections.Generic.IEnumerable<Guid> faceIds, int? maxNumOfCandidatesReturned = default, Azure.AI.Vision.Face.FindSimilarMatchMode? mode = default, System.Threading.CancellationToken cancellationToken = default);
abstract member FindSimilar : Guid * seq<Guid> * Nullable<int> * Nullable<Azure.AI.Vision.Face.FindSimilarMatchMode> * System.Threading.CancellationToken -> Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Vision.Face.FaceFindSimilarResult>>
override this.FindSimilar : Guid * seq<Guid> * Nullable<int> * Nullable<Azure.AI.Vision.Face.FindSimilarMatchMode> * System.Threading.CancellationToken -> Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Vision.Face.FaceFindSimilarResult>>
Public Overridable Function FindSimilar (faceId As Guid, faceIds As IEnumerable(Of Guid), Optional maxNumOfCandidatesReturned As Nullable(Of Integer) = Nothing, Optional mode As Nullable(Of FindSimilarMatchMode) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Response(Of IReadOnlyList(Of FaceFindSimilarResult))

Parameters

faceId
Guid

faceId of the query face. User needs to call "Detect" first to get a valid faceId. Note that this faceId is not persisted and will expire 24 hours after the detection call.

faceIds
IEnumerable<Guid>

An array of candidate faceIds. All of them are created by "Detect" and the faceIds will expire 24 hours after the detection call. The number of faceIds is limited to 1000.

maxNumOfCandidatesReturned
Nullable<Int32>

The number of top similar faces returned. The valid range is [1, 1000]. Default value is 20.

mode
Nullable<FindSimilarMatchMode>

Similar face searching mode. It can be 'matchPerson' or 'matchFace'. Default value is 'matchPerson'.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

faceIds is null.

Examples

This sample shows how to call FindSimilar.

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

Response<IReadOnlyList<FaceFindSimilarResult>> response = client.FindSimilar(Guid.Parse("73f411fe-4f43-4b4b-9cbd-6828d8f4cf9a"), new Guid[] { Guid.Parse("73f411fe-4f43-4b4b-9cbd-6828d8f4cf9a") });

This sample shows how to call FindSimilar with all parameters.

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

Response<IReadOnlyList<FaceFindSimilarResult>> response = client.FindSimilar(Guid.Parse("73f411fe-4f43-4b4b-9cbd-6828d8f4cf9a"), new Guid[] { Guid.Parse("73f411fe-4f43-4b4b-9cbd-6828d8f4cf9a") }, maxNumOfCandidatesReturned: 1234, mode: FindSimilarMatchMode.MatchPerson);

Remarks

Depending on the input the returned similar faces list contains faceIds or persistedFaceIds ranked by similarity.

Find similar has two working modes, "matchPerson" and "matchFace". "matchPerson" is the default mode that it tries to find faces of the same person as possible by using internal same-person thresholds. It is useful to find a known person's other photos. Note that an empty list will be returned if no faces pass the internal thresholds. "matchFace" mode ignores same-person thresholds and returns ranked similar faces anyway, even the similarity is low. It can be used in the cases like searching celebrity-looking faces.

The 'recognitionModel' associated with the query faceId should be the same as the 'recognitionModel' used by the target faceId array.

Applies to

FindSimilar(RequestContent, RequestContext)

Source:
FaceClient.cs

[Protocol Method] Given query face's faceId, to search the similar-looking faces from a faceId array. A faceId array contains the faces created by Detect.

public virtual Azure.Response FindSimilar (Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member FindSimilar : Azure.Core.RequestContent * Azure.RequestContext -> Azure.Response
override this.FindSimilar : Azure.Core.RequestContent * Azure.RequestContext -> Azure.Response
Public Overridable Function FindSimilar (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 FindSimilar and parse the result.

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

using RequestContent content = RequestContent.Create(new
{
    faceId = "73f411fe-4f43-4b4b-9cbd-6828d8f4cf9a",
    faceIds = new object[]
    {
        "73f411fe-4f43-4b4b-9cbd-6828d8f4cf9a"
    },
});
Response response = client.FindSimilar(content);

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

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

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

using RequestContent content = RequestContent.Create(new
{
    faceId = "73f411fe-4f43-4b4b-9cbd-6828d8f4cf9a",
    maxNumOfCandidatesReturned = 1234,
    mode = "matchPerson",
    faceIds = new object[]
    {
        "73f411fe-4f43-4b4b-9cbd-6828d8f4cf9a"
    },
});
Response response = client.FindSimilar(content);

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

Applies to