Beispiel #1
0
        public async void Identify(string imagePath)
        {
            try
            {
                using (Stream imageStream = File.OpenRead(imagePath))
                {
                    var faces = await faceClient.Face.DetectWithStreamAsync(imageStream);

                    var faceIds = faces.Where(x => x.FaceId.HasValue).Select(face => face.FaceId.Value).ToArray();

                    var results = await faceClient.Face.IdentifyAsync(faceIds, friendGroup);

                    foreach (var result in results)
                    {
                        if (result.Candidates.ToArray().Length == 0) // no match found
                        {
                            string message = "Hello, An unknown person is waiting at your door";
                            WhatsappSender.Send(message);
                            SpeechProcessor.SpeechProcessorGS.Speak(message);
                        }
                        else // match(es) found
                        {
                            // Get top 1 among all candidates returned
                            var bestMatch = result.Candidates[0];
                            var person    = await faceClient.PersonGroupPerson.GetAsync(friendGroup, bestMatch.PersonId);

                            var message = $"{person.Name} is waiting at your door with {(int)(bestMatch.Confidence * 100)}% confidence";
                            WhatsappSender.Send(message);
                            SpeechProcessor.SpeechProcessorGS.Speak(message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #2
0
        public async void Identify(string imagePath)
        {
            using (Stream s = File.OpenRead(imagePath))
            {
                var faces = await faceClient.Face.DetectWithStreamAsync(s);

                var faceIds = faces.Where(x => x.FaceId.HasValue).Select(face => face.FaceId.Value).ToArray();

                var results = await faceClient.Face.IdentifyAsync(faceIds, friendGroup);

                foreach (var identifyResult in results)
                {
                    Console.WriteLine("Result of face: {0}", identifyResult.FaceId);
                    if (identifyResult.Candidates.ToArray().Length == 0)
                    {
                        Console.WriteLine("No one identified");
                        string message = "Hello, An unknown person is waiting at your door";
                        SpeechProcessor.SpeechProcessorGS.Speak(message);

                        WhatsappSender.Send("");
                    }
                    else
                    {
                        // Get top 1 among all candidates returned
                        var candidateId = identifyResult.Candidates[0].PersonId;
                        var person      = await faceClient.PersonGroupPerson.GetAsync(friendGroup, candidateId);

                        string message = $"Hello, {person.Name} is waiting at your door";
                        SpeechProcessor.SpeechProcessorGS.Speak(message);

                        Console.WriteLine("Identified as {0}", person.Name);
                        WhatsappSender.Send(person.Name);
                    }
                }
            }
        }