private void UpdateDemographics(SimilarFaceMatch item)
        {
            AgeDistribution genderBasedAgeDistribution = null;

            switch (item.Face.FaceAttributes.Gender)
            {
            case Microsoft.Azure.CognitiveServices.Vision.Face.Models.Gender.Male:
                this.demographics.OverallMaleCount++;
                genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.MaleDistribution;
                break;

            case Microsoft.Azure.CognitiveServices.Vision.Face.Models.Gender.Female:
                this.demographics.OverallFemaleCount++;
                genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.FemaleDistribution;
                break;
            }

            if (item.Face.FaceAttributes.Age < 16)
            {
                genderBasedAgeDistribution.Age0To15++;
            }
            else if (item.Face.FaceAttributes.Age < 20)
            {
                genderBasedAgeDistribution.Age16To19++;
            }
            else if (item.Face.FaceAttributes.Age < 30)
            {
                genderBasedAgeDistribution.Age20s++;
            }
            else if (item.Face.FaceAttributes.Age < 40)
            {
                genderBasedAgeDistribution.Age30s++;
            }
            else if (item.Face.FaceAttributes.Age < 50)
            {
                genderBasedAgeDistribution.Age40s++;
            }
            else
            {
                genderBasedAgeDistribution.Age50sAndOlder++;
            }
        }
Пример #2
0
        private void UpdateDemographics(SimilarFaceMatch item)
        {
            AgeDistribution genderBasedAgeDistribution = null;

            if (string.Compare(item.Face.FaceAttributes.Gender, "male", StringComparison.OrdinalIgnoreCase) == 0)
            {
                this.demographics.OverallMaleCount++;
                genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.MaleDistribution;
            }
            else
            {
                this.demographics.OverallFemaleCount++;
                genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.FemaleDistribution;
            }

            if (item.Face.FaceAttributes.Age < 16)
            {
                genderBasedAgeDistribution.Age0To15++;
            }
            else if (item.Face.FaceAttributes.Age < 20)
            {
                genderBasedAgeDistribution.Age16To19++;
            }
            else if (item.Face.FaceAttributes.Age < 30)
            {
                genderBasedAgeDistribution.Age20s++;
            }
            else if (item.Face.FaceAttributes.Age < 40)
            {
                genderBasedAgeDistribution.Age30s++;
            }
            else if (item.Face.FaceAttributes.Age < 50)
            {
                genderBasedAgeDistribution.Age40s++;
            }
            else
            {
                genderBasedAgeDistribution.Age50sAndOlder++;
            }
        }
        private void UpdateDemographics(ImageAnalyzer img)
        {
            if (this.lastSimilarPersistedFaceSample != null)
            {
                bool demographicsChanged = false;
                // Update the Visitor collection (either add new entry or update existing)
                foreach (var item in this.lastSimilarPersistedFaceSample)
                {
                    Visitor visitor;
                    Guid    persistedFaceId = item.SimilarPersistedFace.PersistedFaceId.GetValueOrDefault();
                    if (this.visitors.TryGetValue(persistedFaceId, out visitor))
                    {
                        visitor.Count++;
                    }
                    else
                    {
                        demographicsChanged = true;

                        visitor = new Visitor {
                            UniqueId = persistedFaceId, Count = 1
                        };
                        this.visitors.Add(visitor.UniqueId, visitor);
                        this.demographics.Visitors.Add(visitor);

                        // Update the demographics stats. We only do it for new visitors to avoid double counting.
                        AgeDistribution genderBasedAgeDistribution = null;
                        if (item.Face.FaceAttributes.Gender == Gender.Male)
                        {
                            this.demographics.OverallMaleCount++;
                            genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.MaleDistribution;
                        }
                        else
                        {
                            this.demographics.OverallFemaleCount++;
                            genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.FemaleDistribution;
                        }

                        if (item.Face.FaceAttributes.Age < 16)
                        {
                            genderBasedAgeDistribution.Age0To15++;
                        }
                        else if (item.Face.FaceAttributes.Age < 20)
                        {
                            genderBasedAgeDistribution.Age16To19++;
                        }
                        else if (item.Face.FaceAttributes.Age < 30)
                        {
                            genderBasedAgeDistribution.Age20s++;
                        }
                        else if (item.Face.FaceAttributes.Age < 40)
                        {
                            genderBasedAgeDistribution.Age30s++;
                        }
                        else if (item.Face.FaceAttributes.Age < 50)
                        {
                            genderBasedAgeDistribution.Age40s++;
                        }
                        else
                        {
                            genderBasedAgeDistribution.Age50sAndOlder++;
                        }
                    }
                }

                if (demographicsChanged)
                {
                    this.ageGenderDistributionControl.UpdateData(this.demographics);
                }

                this.overallStatsControl.UpdateData(this.demographics);
            }
        }
        private async void UpdateDemographics(ImageAnalyzer img)
        {
            if (this.lastSimilarPersistedFaceSample != null)
            {
                bool demographicsChanged = false;
                // Update the Visitor collection (either add new entry or update existing)
                foreach (var item in this.lastSimilarPersistedFaceSample)
                {
                    Visitor visitor;
                    String  unique = "1";
                    if (this.visitors.TryGetValue(item.SimilarPersistedFace.PersistedFaceId, out visitor))
                    {
                        visitor.Count++;
                        unique = "0";
                    }
                    else
                    {
                        demographicsChanged = true;

                        visitor = new Visitor {
                            UniqueId = item.SimilarPersistedFace.PersistedFaceId, Count = 1
                        };
                        this.visitors.Add(visitor.UniqueId, visitor);
                        this.demographics.Visitors.Add(visitor);

                        // Update the demographics stats. We only do it for new visitors to avoid double counting.
                        AgeDistribution genderBasedAgeDistribution = null;
                        if (string.Compare(item.Face.FaceAttributes.Gender, "male", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            this.demographics.OverallMaleCount++;
                            genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.MaleDistribution;
                        }
                        else
                        {
                            this.demographics.OverallFemaleCount++;
                            genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.FemaleDistribution;
                        }

                        if (item.Face.FaceAttributes.Age < 16)
                        {
                            genderBasedAgeDistribution.Age0To15++;
                        }
                        else if (item.Face.FaceAttributes.Age < 20)
                        {
                            genderBasedAgeDistribution.Age16To19++;
                        }
                        else if (item.Face.FaceAttributes.Age < 30)
                        {
                            genderBasedAgeDistribution.Age20s++;
                        }
                        else if (item.Face.FaceAttributes.Age < 40)
                        {
                            genderBasedAgeDistribution.Age30s++;
                        }
                        else if (item.Face.FaceAttributes.Age < 50)
                        {
                            genderBasedAgeDistribution.Age40s++;
                        }
                        else
                        {
                            genderBasedAgeDistribution.Age50sAndOlder++;
                        }
                    }
                    if (lastEmotionSample != null)
                    {
                        Random rand = new Random();
                        Dictionary <String, String> dictionary = new Dictionary <String, String>();

                        dictionary["id"]        = item.SimilarPersistedFace.PersistedFaceId.ToString();
                        dictionary["gender"]    = item.Face.FaceAttributes.Gender.ToString();
                        dictionary["age"]       = item.Face.FaceAttributes.Age.ToString();
                        dictionary["date"]      = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                        dictionary["smile"]     = item.Face.FaceAttributes.Smile.ToString();
                        dictionary["glasses"]   = item.Face.FaceAttributes.Glasses.ToString();
                        dictionary["avgs"]      = rand.Next(5, 8).ToString();
                        dictionary["avgrank"]   = (3 + rand.NextDouble() * 1.5).ToString();
                        dictionary["isunique"]  = unique;
                        dictionary["anger"]     = lastEmotionSample.First().Scores.Anger.ToString();
                        dictionary["contempt"]  = lastEmotionSample.First().Scores.Contempt.ToString();
                        dictionary["disgust"]   = lastEmotionSample.First().Scores.Disgust.ToString();
                        dictionary["fear"]      = lastEmotionSample.First().Scores.Fear.ToString();
                        dictionary["happiness"] = lastEmotionSample.First().Scores.Happiness.ToString();
                        dictionary["neutral"]   = lastEmotionSample.First().Scores.Neutral.ToString();
                        dictionary["sadness"]   = lastEmotionSample.First().Scores.Sadness.ToString();
                        dictionary["surprise"]  = lastEmotionSample.First().Scores.Surprise.ToString();

                        //#pragma warning restore 4014
                        System.Diagnostics.Debug.WriteLine("here!!!!!!!!");
                        var name   = "null";
                        var person = "";
                        System.Diagnostics.Debug.WriteLine("Identify? : " + lastIdentifiedPersonSample == null);
                        if (null != lastIdentifiedPersonSample)
                        {
                            name   = lastIdentifiedPersonSample.First().Item2.Person.Name.ToString();
                            person = lastIdentifiedPersonSample.First().Item2.Person.PersonId.ToString();
                        }
                        System.Diagnostics.Debug.WriteLine("Name: " + name);
                        System.Diagnostics.Debug.WriteLine("ID: " + person);
                        dictionary["personid"]   = person;
                        dictionary["personname"] = name;
                        ////#pragma warning disable 4014
                        String str = SettingsHelper.Instance.IoTHubConnectString;
                        await IoTClient.Start(dictionary, SettingsHelper.Instance.IoTHubConnectString);
                    }
                }

                if (demographicsChanged)
                {
                    this.ageGenderDistributionControl.UpdateData(this.demographics);
                }

                this.overallStatsControl.UpdateData(this.demographics);
            }
        }
Пример #5
0
        private void UpdateDemographics(ImageAnalyzer img)
        {
            if (this.lastSimilarPersistedFaceSample != null)
            {
                bool demographicsChanged = false;
                // Update the Visitor collection (either add new entry or update existing)
                int temp_count = 0;
                foreach (var item in this.lastSimilarPersistedFaceSample)
                {
                    Visitor visitor;
                    var     CurTime = DateTime.Now;
                    if (this.visitors.TryGetValue(item.SimilarPersistedFace.PersistedFaceId, out visitor))
                    {
                        try
                        {
                            visitor.Date = CurTime.Date.ToString("yyyy/MM/dd");
                            visitor.Hour = CurTime.Hour;
                            visitor.Count++;
                            if (this.lastIdentifiedPersonSample != null && this.lastIdentifiedPersonSample.Count() > temp_count && this.lastIdentifiedPersonSample.ElementAt(temp_count) != null && this.lastIdentifiedPersonSample.ElementAt(temp_count).Item2 != null && this.lastIdentifiedPersonSample.ElementAt(temp_count).Item2.Person != null)
                            {
                                visitor.Name = this.lastIdentifiedPersonSample.ElementAt(temp_count).Item2.Person.Name;
                            }
                            if (this.lastEmotionSample != null && this.lastEmotionSample.Count() > temp_count && this.lastEmotionSample.ElementAt(temp_count) != null)
                            {
                                Emotion emo = this.lastEmotionSample.ElementAt(temp_count);
                                visitor.Smile = Math.Round(emo.Scores.Happiness, 4);
                            }
                            var messageString = JsonConvert.SerializeObject(visitor);
                            Task.Run(async() => { await AzureIoTHub.SendSQLToCloudMessageAsync(messageString); });
                        }
                        catch (NullReferenceException e)
                        {
                            this.debugText.Text = string.Format("NullRefenrenceException source at 1: {0}", e.Source);
                            log.WriteToFile(DateTime.Now.ToString("G", tw) + " Error at getting visitor informations\n");
                        }
                    }
                    else
                    {
                        try
                        {
                            demographicsChanged = true;
                            double smile = 0;
                            if (this.lastEmotionSample != null && this.lastEmotionSample.Count() > temp_count && this.lastEmotionSample.ElementAt(temp_count) != null)
                            {
                                Emotion emo = this.lastEmotionSample.ElementAt(temp_count);
                                smile = Math.Round(emo.Scores.Happiness, 4);
                            }
                            else
                            {
                                smile = 0;
                            }
                            int    male = 1;
                            double age  = item.Face.FaceAttributes.Age;
                            if (string.Compare(item.Face.FaceAttributes.Gender, "male", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                male = 0;
                            }
                            if (this.lastIdentifiedPersonSample != null && this.lastIdentifiedPersonSample.Count() > temp_count && this.lastIdentifiedPersonSample.ElementAt(temp_count) != null && this.lastIdentifiedPersonSample.ElementAt(temp_count).Item2 != null && this.lastIdentifiedPersonSample.ElementAt(temp_count).Item2.Person != null)
                            {
                                string name = this.lastIdentifiedPersonSample.ElementAt(temp_count).Item2.Person.Name;
                                if (name != null)
                                {
                                    visitor = new Visitor {
                                        UniqueId = item.SimilarPersistedFace.PersistedFaceId, Count = 1, Gender = male, Age = age, Smile = smile, Date = CurTime.Date.ToString("yyyy/MM/dd"), Hour = CurTime.Hour, Name = name, Device = deviceName
                                    };
                                }
                                else
                                {
                                    visitor = new Visitor {
                                        UniqueId = item.SimilarPersistedFace.PersistedFaceId, Count = 1, Gender = male, Age = age, Smile = smile, Date = CurTime.Date.ToString("yyyy/MM/dd"), Hour = CurTime.Hour, Name = name, Device = deviceName
                                    };
                                }
                            }
                            else
                            {
                                visitor = new Visitor {
                                    UniqueId = item.SimilarPersistedFace.PersistedFaceId, Count = 1, Gender = male, Age = age, Smile = smile, Date = CurTime.Date.ToString("yyyy/MM/dd"), Hour = CurTime.Hour, Name = null, Device = deviceName
                                };
                            }
                            this.visitors.Add(visitor.UniqueId, visitor);
                            this.demographics.Visitors.Add(visitor);

                            // Update the demographics stats. We only do it for new visitors to avoid double counting.
                            AgeDistribution genderBasedAgeDistribution = null;
                            if (string.Compare(item.Face.FaceAttributes.Gender, "male", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                this.demographics.OverallMaleCount++;
                                genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.MaleDistribution;
                            }
                            else
                            {
                                this.demographics.OverallFemaleCount++;
                                genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.FemaleDistribution;
                            }

                            if (item.Face.FaceAttributes.Age < 16)
                            {
                                genderBasedAgeDistribution.Age0To15++;
                            }
                            else if (item.Face.FaceAttributes.Age < 20)
                            {
                                genderBasedAgeDistribution.Age16To19++;
                            }
                            else if (item.Face.FaceAttributes.Age < 30)
                            {
                                genderBasedAgeDistribution.Age20s++;
                            }
                            else if (item.Face.FaceAttributes.Age < 40)
                            {
                                genderBasedAgeDistribution.Age30s++;
                            }
                            else if (item.Face.FaceAttributes.Age < 50)
                            {
                                genderBasedAgeDistribution.Age40s++;
                            }
                            else
                            {
                                genderBasedAgeDistribution.Age50sAndOlder++;
                            }

                            var messageString = JsonConvert.SerializeObject(visitor);
                            Task.Run(async() => { await AzureIoTHub.SendSQLToCloudMessageAsync(messageString); });
                        }
                        catch (NullReferenceException e)
                        {
                            this.debugText.Text = string.Format("NullRefenrenceException source at 2: {0}", e.Source);
                            log.WriteToFile(DateTime.Now.ToString("G", tw) + " Error at getting visitor informations\n");
                        }
                    }

                    temp_count++;
                }

                if (demographicsChanged)
                {
                    this.ageGenderDistributionControl.UpdateData(this.demographics);
                }

                this.overallStatsControl.UpdateData(this.demographics);
            }
        }
Пример #6
0
        private void UpdateDemographics(ImageAnalyzer img)
        {
            if (this.lastSimilarPersistedFaceSample != null)
            {
                bool demographicsChanged = false;
                // Update the Visitor collection (either add new entry or update existing)
                foreach (var item in this.lastSimilarPersistedFaceSample)
                {
                    Visitor visitor;
                    if (this.visitors.TryGetValue(item.SimilarPersistedFace.PersistedFaceId, out visitor))
                    {
                        visitor.Count++;
                    }
                    else
                    {
                        demographicsChanged = true;

                        visitor = new Visitor {
                            UniqueId = item.SimilarPersistedFace.PersistedFaceId, Count = 1
                        };
                        this.visitors.Add(visitor.UniqueId, visitor);
                        this.demographics.Visitors.Add(visitor);

                        // Update the demographics stats. We only do it for new visitors to avoid double counting.
                        AgeDistribution genderBasedAgeDistribution = null;
                        if (string.Compare(item.Face.FaceAttributes.Gender, "male", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            this.demographics.OverallMaleCount++;
                            genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.MaleDistribution;
                        }
                        else
                        {
                            this.demographics.OverallFemaleCount++;
                            genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.FemaleDistribution;
                        }

                        if (item.Face.FaceAttributes.Age < 16)
                        {
                            genderBasedAgeDistribution.Age0To15++;
                        }
                        else if (item.Face.FaceAttributes.Age < 20)
                        {
                            genderBasedAgeDistribution.Age16To19++;
                        }
                        else if (item.Face.FaceAttributes.Age < 30)
                        {
                            genderBasedAgeDistribution.Age20s++;
                        }
                        else if (item.Face.FaceAttributes.Age < 40)
                        {
                            genderBasedAgeDistribution.Age30s++;
                        }
                        else if (item.Face.FaceAttributes.Age < 50)
                        {
                            genderBasedAgeDistribution.Age40s++;
                        }
                        else
                        {
                            genderBasedAgeDistribution.Age50sAndOlder++;
                        }
                    }

                    visitor.Count = this.demographics.Visitors.Count;
                    System.Threading.Timer timer = null;
                    timer = new System.Threading.Timer((obj) =>
                    {
                        MongoCreateAsync(visitor);
                        timer.Dispose();
                    },
                                                       null, 50000, System.Threading.Timeout.Infinite);
                }

                if (demographicsChanged)
                {
                    this.ageGenderDistributionControl.UpdateData(this.demographics);
                }
                this.overallStatsControl.UpdateData(this.demographics);
            }
        }