public async Task <NamedFace[]> AnalyzeImageUsingHelper(Stream stream)
        {
            Face[] faces = await faceDetector.DetectAsync(stream, false, true, true, false);

            NamedFace[] namedFaces = new NamedFace[faces.Length];

            //Copy to named faces vector.
            for (int i = 0; i < faces.Length; i++)
            {
                namedFaces[i] = new NamedFace(faces[i]);
            }



            // TODO: Is this the right place to get the images from???
            bool identifyFaces;

            bool.TryParse(ConfigurationManager.AppSettings["IdentifySpecificPeople"] ?? "false", out identifyFaces);

            if (identifyFaces && faces.Length > 0)
            {
                var faceIds = faces.Select(face => face.FaceId).ToArray();

                var results = await faceDetector.IdentityAsync("coworkers", faceIds);

                foreach (var identifyResult in results)
                {
                    Console.WriteLine("Result of face: {0}", identifyResult.FaceId);

                    if (identifyResult.Candidates.Length == 0)
                    {
                        Console.WriteLine("No one identified");
                    }
                    else
                    {
                        var candidateId = identifyResult.Candidates[0].PersonId;
                        var person      = await faceDetector.GetPersonAsync("coworkers", candidateId);

                        if (identifyResult.Candidates[0].Confidence > 0.5)
                        {
                            for (int i = 0; i < namedFaces.Length; i++)
                            {
                                if (namedFaces[i].FaceId == identifyResult.FaceId)
                                {
                                    // Set name.
                                    namedFaces[i].Name = person.Name;
                                }
                            }

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

            return(namedFaces);
        }
        public async Task<NamedFace[]> AnalyzeImageUsingHelper(Stream stream)
        {
            Face[] faces = await faceDetector.DetectAsync(stream, false, true, true, false);
            
            NamedFace[] namedFaces = new NamedFace[faces.Length];

            //Copy to named faces vector.           
            for (int i = 0; i < faces.Length; i++)
            {
                namedFaces[i] = new NamedFace(faces[i]);
            }

            

            // TODO: Is this the right place to get the images from???
            bool identifyFaces;
            bool.TryParse(ConfigurationManager.AppSettings["IdentifySpecificPeople"] ?? "false", out identifyFaces);

            if (identifyFaces && faces.Length > 0)
            {
                var faceIds = faces.Select(face => face.FaceId).ToArray();

                var results = await faceDetector.IdentityAsync("coworkers", faceIds);

                foreach (var identifyResult in results)
                {
                    Console.WriteLine("Result of face: {0}", identifyResult.FaceId);

                    if (identifyResult.Candidates.Length == 0)
                    {
                        Console.WriteLine("No one identified");
                    }
                    else
                    {
                        var candidateId = identifyResult.Candidates[0].PersonId;
                        var person = await faceDetector.GetPersonAsync("coworkers", candidateId);

                        if (identifyResult.Candidates[0].Confidence > 0.5)
                        {
                            for (int i=0; i<namedFaces.Length; i++)
                            {
                                if (namedFaces[i].FaceId == identifyResult.FaceId)
                                {
                                    // Set name.
                                    namedFaces[i].Name=person.Name;
                                }
                            }

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

            return namedFaces;
        }
Пример #3
0
        public FaceMarker(NamedFace face)
        {
            this.HairlineColor = new SolidColorBrush(Colors.Red);
            InitializeComponent();

            if (face.Name == "Scott")
            {
                Age    = "40";
                Gender = "male";
            }
            else if (face.Name == "Kevin")
            {
                Age    = "49";
                Gender = "male";
            }
            else
            {
                Age    = face.Attributes.Age.ToString();
                Gender = face.Attributes.Gender;
            }
        }
        public FaceMarker(NamedFace face)
        {
            this.HairlineColor = new SolidColorBrush(Colors.Red);
            InitializeComponent();

            if (face.Name == "Scott")
            {
                Age = "40";
                Gender = "male";
            }
            else if (face.Name == "Kevin")
            {
                Age = "49";
                Gender = "male";
            }
            else
            {
                Age = face.Attributes.Age.ToString();
                Gender = face.Attributes.Gender;
            }
 
        }
        /// <summary>
        /// Analyze the image and show a recommended URL given age/gender.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnAnalyzeImage(object sender, RoutedEventArgs e)
        {
            StatusText.Text = "Analyzing...";

            RecognizedFaces = await ProcessImage();

            userInput.Text = "";


            string url = "";

            if (RecognizedFaces == null)
            {
                StatusText.Text = "Null returned";
                return;
            }


            if (RecognizedFaces.Length == 1)
            {
                // A single person.

                Face singleFace = RecognizedFaces[0];

                NamedFace namedFace = singleFace as NamedFace;
                if (namedFace.Name == "Scott")
                {
                    url = "http://www.sephora.com/polo-red-P380994";
                }
                else if (namedFace.Name == "Kevin")
                {
                    url = @"http://www.mcdonalds.com/us/en/food.html";
                }
                else if (String.Compare(singleFace.Attributes.Gender, "male", true) == 0)
                {
                    // male single person
                    if (singleFace.Attributes.Age < 12)
                    {
                        // a single child?
                        url = confCollection["MaleYoungerThan12"].Value;
                    }
                    else if (singleFace.Attributes.Age < 18)
                    {
                        url = confCollection["MaleYoungerThan18"].Value;
                    }
                    else if (singleFace.Attributes.Age < 25)
                    {
                        url = confCollection["MaleYoungerThan25"].Value;
                    }
                    else if (singleFace.Attributes.Age < 32)
                    {
                        url = confCollection["MaleYoungerThan32"].Value;
                    }
                    else if (singleFace.Attributes.Age < 40)
                    {
                        url = confCollection["MaleYoungerThan40"].Value;
                    }
                    else if (singleFace.Attributes.Age < 50)
                    {
                        url = confCollection["MaleYoungerThan50"].Value;
                    }
                    else if (singleFace.Attributes.Age < 55)
                    {
                        url = confCollection["MaleYoungerThan55"].Value;
                    }
                    else if (singleFace.Attributes.Age < 60)
                    {
                        url = confCollection["MaleYoungerThan60"].Value;
                    }
                    else
                    {
                        url = confCollection["MaleOlder"].Value;
                    }
                }
                else
                {
                    // female single person
                    if (singleFace.Attributes.Age < 12)
                    {
                        url = confCollection["FemaleYoungerThan12"].Value;
                    }
                    else if (singleFace.Attributes.Age < 18)
                    {
                        url = confCollection["FemaleYoungerThan18"].Value;
                    }
                    else if (singleFace.Attributes.Age < 25)
                    {
                        url = confCollection["FemaleYoungerThan25"].Value;
                    }
                    else if (singleFace.Attributes.Age < 32)
                    {
                        // female single person
                        url = confCollection["FemaleYoungerThan32"].Value;
                    }
                    else if (singleFace.Attributes.Age < 40)
                    {
                        url = confCollection["FemaleYoungerThan40"].Value;
                    }
                    else if (singleFace.Attributes.Age < 50)
                    {
                        url = confCollection["FemaleYoungerThan50"].Value;
                    }
                    else if (singleFace.Attributes.Age < 60)
                    {
                        url = confCollection["FemaleYoungerThan60"].Value;
                    }
                    else
                    {
                        url = confCollection["FemaleOlder"].Value;
                    }
                }
            }

            if (RecognizedFaces.Length >= 2)
            {
                bool isChildPresent = false;
                foreach (Face face in RecognizedFaces)
                {
                    if (face.Attributes.Age <= 12)
                    {
                        isChildPresent = true;
                    }
                }

                if (isChildPresent)
                {
                    // There is a family here.
                    url = confCollection["MorethanOnePersonAndChild"].Value;
                }
                else
                {
                    // at least two adult friends.
                    url = confCollection["TwoOrMoreAdults"].Value;
                }
            }

            browser1.Navigate(url);
            StatusText.Text = "Done";
        }