public static async Task <List <UserViewModel> > RecognizeAsync(byte[] imgdata) { try { //var imageCandidates = (await InitAzureOxfordFace().DetectAsync(new MemoryStream(imgdata))).Select(c => new UserViewModel(c.FaceId)).ToList(); var imageCandidates = (await InitAzureOfficialFace().Face.DetectWithStreamAsync(new MemoryStream(imgdata), recognitionModel: RecognitionModel.Recognition02)).ToList(); List <UserViewModel> users = new List <UserViewModel>(); if (imageCandidates.Any()) { //var response = await InitAzureOxfordFace().IdentifyAsync(groupId, imageCandidates.Select(c => c.Id).ToArray(), (float)0.65, 1); List <string> faceIds = imageCandidates.Select(c => c.FaceId.Value.ToString()).ToList(); //var response = await InitAzureOfficialFace().Face.IdentifyAsync(faceIds, groupId, null, 1, 0.5); var requestModel = new IdentifyRequestModel { PersonGroupId = groupId, FaceIds = faceIds.ToArray(), MaxNumOfCandidatesReturned = 1, ConfidenceThreshold = 0.5 }; var response = await AzureFaceRestClient.IdentifyAsync(SUBSCRIPTION_KEY, ENDPOINT, requestModel); //var persons = await GetAllAsync(); foreach (var item in response) { var current = item.Candidates.FirstOrDefault(); if (current != null) { var candidate = await GetAllAsync(Guid.Parse(current.PersonId)); candidate.Confidence = current.Confidence; users.Add(candidate); } } } return(users.Where(c => c.Confidence.HasValue).ToList()); } catch (Exception ex) { throw ex; } }
public static async Task <List <IdentifyResponseModel> > IdentifyAsync(string subscriptionKey, string endpoint, IdentifyRequestModel model) { try { string uriBase = $"{endpoint}/face/v1.0/identify"; HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey); var json = JsonConvert.SerializeObject(model); HttpResponseMessage response; var data = new StringContent(json, Encoding.UTF8, "application/json"); response = await client.PostAsync(uriBase, data); string result = response.Content.ReadAsStringAsync().Result; return(JsonConvert.DeserializeObject <List <IdentifyResponseModel> >(result)); } catch (Exception ex) { throw ex; } }