FaceClient.FindSimilarAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
FindSimilarAsync(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.
|
FindSimilarAsync(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. |
FindSimilarAsync(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.
- This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
- Please try the simpler FindSimilarAsync(Guid, IEnumerable<Guid>, Nullable<Int32>, Nullable<FindSimilarMatchMode>, CancellationToken) convenience overload with strongly typed models first.
public virtual System.Threading.Tasks.Task<Azure.Response> FindSimilarAsync (Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member FindSimilarAsync : Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.FindSimilarAsync : Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function FindSimilarAsync (content As RequestContent, Optional context As RequestContext = Nothing) As Task(Of 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 FindSimilarAsync and parse the result.
Uri endpoint = new Uri("<endpoint>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
FaceClient client = new FaceClient(endpoint, credential);
using RequestContent content = RequestContent.Create(new
{
faceId = "c5c24a82-6845-4031-9d5d-978df9175426",
maxNumOfCandidatesReturned = 3,
mode = "matchPerson",
faceIds = new object[]
{
"015839fb-fbd9-4f79-ace9-7675fc2f1dd9",
"be386ab3-af91-4104-9e6d-4dae4c9fddb7"
},
});
Response response = await client.FindSimilarAsync(content);
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result[0].GetProperty("confidence").ToString());
Applies to
FindSimilarAsync(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 System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Vision.Face.FaceFindSimilarResult>>> FindSimilarAsync (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 FindSimilarAsync : Guid * seq<Guid> * Nullable<int> * Nullable<Azure.AI.Vision.Face.FindSimilarMatchMode> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Vision.Face.FaceFindSimilarResult>>>
override this.FindSimilarAsync : Guid * seq<Guid> * Nullable<int> * Nullable<Azure.AI.Vision.Face.FindSimilarMatchMode> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Vision.Face.FaceFindSimilarResult>>>
Public Overridable Function FindSimilarAsync (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 Task(Of 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.
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 FindSimilarAsync.
Uri endpoint = new Uri("<endpoint>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
FaceClient client = new FaceClient(endpoint, credential);
Response<IReadOnlyList<FaceFindSimilarResult>> response = await client.FindSimilarAsync(Guid.Parse("c5c24a82-6845-4031-9d5d-978df9175426"), new Guid[] { Guid.Parse("015839fb-fbd9-4f79-ace9-7675fc2f1dd9"), Guid.Parse("be386ab3-af91-4104-9e6d-4dae4c9fddb7") });
Remarks
Please refer to https://zcusa.951200.xyz/rest/api/face/face-recognition-operations/find-similar for more details.
Applies to
Azure SDK for .NET