public async Task <List <FaceMetadata> > DetectFacesAsync(Stream stream) { var faceServiceClient = _faceService.CreateAzureClient(); stream.Seek(0, SeekOrigin.Begin); var faces = await faceServiceClient.DetectAsync(stream, true, true); return(faces.Select(i => new FaceMetadata() { UniqueId = i.FaceId, FacePosition = new Rectangle(i.FaceRectangle.Left, i.FaceRectangle.Top, i.FaceRectangle.Width, i.FaceRectangle.Height), CreatedDate = DateTime.Now }).ToList()); }
public async Task <List <IdentifiedPerson> > IdentifyAsync(List <FaceMetadata> faces, Stream stream) { var personRoot = _faceService.GetPersonGroup(); var persons = _faceService.GetAllPersons(); try { using (var faceServiceClient = _faceService.CreateAzureClient()) { var detectResult2 = await faceServiceClient.IdentifyAsync( personRoot.PersonGroupId.ToLowerInvariant(), faces.Select(i => i.UniqueId).ToArray(), 0.5f, 3); var result = new List <IdentifiedPerson>(); foreach (var person in detectResult2) { result.AddRange(person.Candidates.Select(i => new IdentifiedPerson() { FaceId = person.FaceId, Id = i.PersonId, Confidence = i.Confidence, Data = persons.FirstOrDefault( f => !string.IsNullOrEmpty(f.AzureId) && Guid.Parse(f.AzureId) == i.PersonId) }).ToList()); } return(result); } } catch (FaceAPIException faceEx) { Log.Info("Face exception " + faceEx.ErrorMessage, this); } catch (Exception e) { Log.Info("Exception during detection + " + e, this); } return(new List <IdentifiedPerson>()); }