/// <summary> Function which submits a frame to the Face API. </summary> /// <param name="frame"> The video frame to submit. </param> /// <returns> A <see cref="Task{LiveCameraResult}"/> representing the asynchronous API call, /// and containing the faces returned by the API. </returns> private async Task <LiveCameraResult> FacesAnalysisFunction(VideoFrame frame) { // Encode image. var jpg = frame.Image.ToMemoryStream(".jpg", s_jpegParams); // Submit image to API. var detectWithStreamCmd = new DetectWithStreamCmd(); var faces = await detectWithStreamCmd.DetectWithStreamAsync(jpg); // Count the API call. Properties.Settings.Default.FaceAPICallCount++; // Output. return(new LiveCameraResult { Faces = faces.ToArray(), VideoFrame = frame }); }
public async Task <bool> FindSimilar(LiveCameraResult liveCameraResult) { try { if (string.IsNullOrWhiteSpace(DocumentImagePath)) { return(false); } IList <Guid?> targetFaceIds = new List <Guid?>(); using (var jpg = File.OpenRead(DocumentImagePath)) { // Detect faces from load image. var detectWithStreamCmd = new DetectWithStreamCmd(); var faces = await detectWithStreamCmd.DetectWithStreamAsync(jpg); //// Add detected faceId to list of GUIDs. if (faces.Count <= 0) { MessageArea.Text = $"No se detectaron rostros en la imagen."; return(false); } targetFaceIds.Add(faces[0].FaceId.Value); } var verifyFaceToFaceCmd = new VerifyFaceToFaceCmd(); var similarResults = await verifyFaceToFaceCmd.VerifyFaceToFaceAsync(liveCameraResult.Faces.First().FaceId.Value, targetFaceIds.First().Value); if (similarResults.IsIdentical) { RightImage.Source = VisualizeResult(liveCameraResult.VideoFrame); MessageArea.Text = $"Los rostros son similares con una confianza de: {similarResults.Confidence}."; return(true); } else { MessageArea.Text = $"Los rostros no son identicos."; return(true); } } catch (Exception ex) { MessageArea.Text = $"Se ha presentado un error: {ex.Message}"; return(false); } }