Ejemplo n.º 1
0
        public async Task <IActionResult> Search(FaceSearchModel model)
        {
            var         matches = new Dictionary <string, float>();
            List <Face> detectedFaces;

            if (!string.IsNullOrEmpty(model.Url))
            {
                detectedFaces = await _faceRecognition.Detect(new Uri(model.Url));
            }
            else if (model.Face != null)
            {
                detectedFaces = await _faceRecognition.Detect(model.Face.OpenReadStream());
            }
            else
            {
                return(BadRequest());
            }

            foreach (var detectedFace in detectedFaces)
            {
                Dictionary <string, float> found = await _faceRecognition.Search(model.ListId, detectedFace.Id.ToString(), new Dictionary <string, object>
                {
                    { "largeFaceListId", model.ListId }
                });

                foreach (var match in found)
                {
                    matches.Add(match.Key, match.Value);
                }
            }

            return(Ok(matches));
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public async Task <bool> Authenticate(string email, Stream faceStream)
        {
            var document = await LoadUserData();

            var  node     = document.SelectSingleNode($"/users/user[@email='{email}']");
            Guid personId = Guid.Parse(node.Attributes["id"].Value);

            // Detect faces in the image and use the first one for authentication
            List <Face> faces = await _faceRecognition.Detect(faceStream);

            float confidence = await _faceRecognition.Verify(_group, faces[0].Id.ToString(), new Dictionary <string, object>
            {
                { "largePersonGroupId", _group.ToLower().Replace(' ', '-') },
                { "personId", personId.ToString() }
            });

            return(confidence > float.Parse(_configuration["Identity:Verification Threshold"]));
        }