예제 #1
0
        public async Task <bool> ContinueTopic(DetectiveBotContext context)
        {
            switch (State)
            {
            case TopicState.askedTopic:
                return(await HandleSelectedTopic(context));

            case TopicState.unknown:
            default:
                return(await StartTopic(context));
            }
        }
        private async Task <bool> AskSex(DetectiveBotContext context)
        {
            Age = context.Request.Text;

            var reply = BotReplies.ReplyWithOptions("What is the sex of the suspect?", new List <string>()
            {
                "male", "female"
            }, context);
            await context.SendActivity(reply);

            State = TopicState.askedSex;

            return(true);
        }
        private async Task <bool> AskFacialHair(DetectiveBotContext context)
        {
            HairColor = context.Request.Text;

            var reply = BotReplies.ReplyWithOptions("Does the suspect have facial hair", new List <string>()
            {
                Intents.Yes, Intents.No
            }, context);
            await context.SendActivity(reply);

            State = TopicState.askedFacialHair;

            return(true);
        }
        private async Task <bool> AskHairColor(DetectiveBotContext context)
        {
            Sex = context.Request.Text;

            var reply = BotReplies.ReplyWithOptions("What is the hair color of the suspect", new List <string>()
            {
                "Blond", "Brown", "Black", "Red", "Gray", "Bald"
            }, context);
            await context.SendActivity(reply);

            State = TopicState.askedHairColor;

            return(true);
        }
예제 #5
0
        private async Task <bool> HandleSelectedTopic(DetectiveBotContext context)
        {
            State = TopicState.unknown;
            switch (context.RecognizedIntents.TopIntent?.Name)
            {
            case Intents.Suspects:
                context.ConversationState.ActiveTopic = new TrainSuspectsTopic(faceRecognitionService);
                return(await context.ConversationState.ActiveTopic.StartTopic(context));

            default:
                var reply = context.Request.CreateReply("Sorry i can't help you with that");
                await context.SendActivity(reply);

                return(false);
            }
        }
        private async Task <bool> CheckForAnother(DetectiveBotContext context)
        {
            if (context.RecognizedIntents.TopIntent?.Name == Intents.Yes)
            {
                State = TopicState.started;
                return(await this.ContinueTopic(context));
            }
            else
            {
                var reply = context.Request.CreateReply("I'll be training the newly added pictures in the background.");
                await context.SendActivity(reply);

                await faceRecognitionService.TrainModel();

                return(false);
            }
        }
        private async Task <bool> SaveName(DetectiveBotContext context)
        {
            var name   = context.Request.Text;
            var result = await faceRecognitionService.AddNewPerson(name, LatestImage);

            var reply = context.Request.CreateReply($"Added person {name}");
            await context.SendActivity(reply);

            var reply2 = BotReplies.ReplyWithOptions("Would you like to add another?", new List <string>()
            {
                Intents.Yes, Intents.No
            }, context);
            await context.SendActivity(reply2);

            State = TopicState.finished;

            return(true);
        }
        private async Task <bool> SubjectSummary(DetectiveBotContext context)
        {
            bool result = false;

            bool.TryParse(context.Request.Text, out result);

            FacialHair = result;

            await context.SendActivity(context.Request.CreateReply($"Ok Suspect description is:"));

            await context.SendActivity(context.Request.CreateReply($"Age: {Age}"));

            await context.SendActivity(context.Request.CreateReply($"Sex {Sex}"));

            await context.SendActivity(context.Request.CreateReply($"Hair color: {HairColor}"));

            await context.SendActivity(context.Request.CreateReply($"Facial Hair {FacialHair.ToString()}"));

            State = TopicState.checkSuspectPicture;

            return(await ContinueTopic(context));
        }
        public async Task <bool> ContinueTopic(DetectiveBotContext context)
        {
            if (context.Request.Attachments != null && context.Request.Attachments.Count > 0)
            {
                var result = await faceRecognitionService.GetFaceAttributes(context.Request.Attachments[0].ContentUrl);

                if (result != null)
                {
                    var resultReply = context.Request.CreateReply($"Age: {result.FaceAttributes.Age},Gender: {result.FaceAttributes.Gender},Smile: {result.FaceAttributes.Smile}");
                    await context.SendActivity(resultReply);
                }
                else
                {
                    var resultReply = context.Request.CreateReply($"I can't see any person in here");
                    await context.SendActivity(resultReply);
                }
            }

            var reply = context.Request.CreateReply("Please send me a picture and i'll identify the person \"Quit\" to stop");
            await context.SendActivity(reply);

            return(true);
        }
예제 #10
0
        public async Task <bool> ContinueTopic(DetectiveBotContext context)
        {
            if (context.Request.Attachments != null && context.Request.Attachments.Count > 0)
            {
                var result = await faceRecognitionService.IdentifyPerson(context.Request.Attachments[0].ContentUrl);

                if (result != null)
                {
                    var resultReply = context.Request.CreateReply($"I think it is {result.Name}");
                    await context.SendActivity(resultReply);
                }
                else
                {
                    var resultReply = context.Request.CreateReply($"I'm not sure who this is");
                    await context.SendActivity(resultReply);
                }
            }

            var reply = context.Request.CreateReply("Please send me a picture to identify the next person or type \"Quit\" to stop");
            await context.SendActivity(reply);

            return(true);
        }
        public async Task <bool> ContinueTopic(DetectiveBotContext context)
        {
            switch (State)
            {
            case TopicState.started:
                return(await AskForPicture(context));

            case TopicState.askedForPicture:
                return(await CheckPictureAndAskForName(context));

            case TopicState.checkEsistingPerson:
                return(await CheckExistingPerson(context));

            case TopicState.askedForName:
                return(await SaveName(context));

            case TopicState.finished:
                return(await CheckForAnother(context));

            case TopicState.unknown:
            default:
                return(await StartTopic(context));
            }
        }
 public async Task<bool> StartTopic(DetectiveBotContext context)
 {
     return await this.ContinueTopic(context);
 }
        private async Task <bool> CheckSuspectPicture(DetectiveBotContext context)
        {
            if (context.Request.Attachments?.Count > 0)
            {
                try
                {
                    var match = 0;
                    var face  = await faceRecognitionService.GetFaceAttributes(context.Request.Attachments[0].ContentUrl);

                    if (face != null)
                    {
                        //check sex
                        if (face.FaceAttributes.Gender.ToLower() == Sex.ToLower())
                        {
                            match += 25;
                        }

                        //check age
                        switch ((int)Math.Round(face.FaceAttributes.Age))
                        {
                        case int n when(n <= 20):
                            if (Age == "<20")
                            {
                                match += 25;
                            }
                            break;

                        case int n when(n > 20 && n <= 30):
                            if (Age == "20-30")
                            {
                                match += 25;
                            }
                            break;

                        case int n when(n > 30 && n <= 40):
                            if (Age == "31-40")
                            {
                                match += 25;
                            }
                            break;

                        case int n when(n > 40 && n <= 50):
                            if (Age == "41-50")
                            {
                                match += 25;
                            }
                            break;

                        case int n when(n > 50):
                            if (Age == ">50")
                            {
                                match += 25;
                            }
                            break;
                        }

                        //check hair color
                        if (HairColor.ToLower() == "bald" && (face.FaceAttributes.Hair.Bald > 0.7))
                        {
                            match += 25;
                        }
                        else
                        {
                            if (face.FaceAttributes.Hair.HairColor != null &&
                                face.FaceAttributes.Hair.HairColor.Any(color => color.Color == (HairColorType)Enum.Parse(typeof(HairColorType), HairColor) &&
                                                                       color.Confidence > 0.7))
                            {
                                match += 25;
                            }
                        }

                        //check facial hair
                        if (FacialHair && (face.FaceAttributes.FacialHair.Beard > 0.7 ||
                                           face.FaceAttributes.FacialHair.Moustache > 0.7 ||
                                           face.FaceAttributes.FacialHair.Sideburns > 0.7))
                        {
                            match += 25;
                        }
                        else
                        {
                            if (!FacialHair && (face.FaceAttributes.FacialHair.Beard < 0.5 &&
                                                face.FaceAttributes.FacialHair.Moustache < 0.5 &&
                                                face.FaceAttributes.FacialHair.Sideburns < 0.5))
                            {
                                match += 25;
                            }
                        }
                    }

                    await context.SendActivity(context.Request.CreateReply($"This person matches the description for {match.ToString()}%"));
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine($"Exception: {ex.Message}");
                    await context.SendActivity(context.Request.CreateReply($"Error processing this image. Are you sure it contained a face?"));
                }
            }
            await context.SendActivity(context.Request.CreateReply($"Take a picture of a suspect and i'll check how far it matches the description"));

            State = TopicState.checkSuspectPicture;

            return(true);
        }
 public async Task <bool> ResumeTopic(DetectiveBotContext context)
 {
     return(await this.ContinueTopic(context));
 }
예제 #15
0
 public async Task <bool> ResumeTopic(DetectiveBotContext context)
 {
     throw new NotImplementedException();
 }