コード例 #1
0
        public Dictionary <int, Dictionary <string, double> > ClassifyImage(string path)
        {
            Bitmap         bitmapImage = new Bitmap(path);
            WatsonAnalizer myFilter    = (WatsonAnalizer)this.tools[18];
            Dictionary <int, Dictionary <string, double> > resultadoClasificacion = myFilter.FindClassifiers(bitmapImage);

            return(resultadoClasificacion);
        }
コード例 #2
0
        public Dictionary <string, int> SexAndAgeRecognition(Image image)
        {
            Dictionary <string, int> result = new Dictionary <string, int>()
            {
            };
            WatsonAnalizer WA = new WatsonAnalizer();
            Dictionary <int, Dictionary <string, object> > facesDict = WA.FindFaces(image.BitmapImage);
            double ageScore    = 0;
            int    maleScore   = 0;
            int    femaleScore = 0;
            int    cont        = 0;

            foreach (KeyValuePair <int, Dictionary <string, object> > pair in facesDict)
            {
                Dictionary <string, object> value = pair.Value;
                foreach (KeyValuePair <string, object> Scores in value)
                {
                    string String = Scores.Key;
                    object Object = Scores.Key;

                    switch (String)
                    {
                    case "age":
                        Age ageObj = (Age)Object;
                        ageScore += (ageObj.MaxAge - ageObj.MinAge) / 2;
                        break;

                    case "gender":
                        Gender genderObj = (Gender)Object;
                        if (genderObj.GenderLabel == "male")
                        {
                            maleScore++;
                        }
                        else
                        {
                            femaleScore++;
                        }
                        break;
                    }
                }
                cont++;
            }
            if (maleScore > femaleScore)
            {
                result.Add("Male", Convert.ToInt32(Math.Floor(ageScore / cont)));
            }
            else if (maleScore < femaleScore)
            {
                result.Add("Female", Convert.ToInt32(Math.Floor(ageScore / cont)));
            }
            else
            {
                Random   rnd     = new Random();
                string[] genders = new string[2];
                genders[0] = "Male";
                genders[1] = "Female";
                result.Add(genders[rnd.Next(0, 1)], Convert.ToInt32(Math.Floor(ageScore / cont)));
            }

            return(result);
        } // => ESTE METODO SE DEBE VOLVER A HACER