コード例 #1
0
        public static ImageFeatureVector LoadFromFile(String fileName)
        {
            String             data = File.ReadAllText(fileName);
            ImageFeatureVector fv   = JsonConvert.DeserializeObject <ImageFeatureVector>(data);

            return(fv);
        }
コード例 #2
0
        public void AddFromFile(String fileName)
        {
            ImageFeatureVector fv = ImageFeatureVector.LoadFromFile(fileName);

            Console.WriteLine("SimpleImageClassifier: AddFromFile " + fileName + " " + fv.Count);
            features.Add(Path.GetFileNameWithoutExtension(fileName), fv);
        }
コード例 #3
0
        public ImageFeatureVector MaskBitmap(Bitmap bmp)
        {
            ImageFeatureVector ret = new ImageFeatureVector();

            foreach (ImageFeatureVectorData data in this)
            {
                Color color = bmp.GetPixel(data.pos.X, data.pos.Y);
                ret.Add(new ImageFeatureVectorData()
                {
                    pos = data.pos, color = color
                });
            }
            return(ret);
        }
コード例 #4
0
        private void averageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ImageFeatureVector fv = screenClassifier.AverageFeature(dataPath + cmbScreenType.Text + @"\");

            if (fv != null)
            {
                fv.SaveToFile(dataPath + cmbScreenType.Text + ".txt");
                Bitmap bmpMask = (Bitmap)Bitmap.FromFile(dataPath + cmbScreenType.Text + @"\mask.png");
                fv.ToBitmap(bmpMask).Save(dataPath + "avg.png");
                logDebug("avg done");
            }
            else
            {
                logDebug("mask not found");
            }
        }
コード例 #5
0
        public ImageFeatureVector CreateFeatureVector(String folder)
        {
            ImageFeatureVector ret = null;
            DirectoryInfo      d   = new DirectoryInfo(folder);

            FileInfo[] Files = d.GetFiles("*.png");
            Bitmap     main  = null;

            foreach (FileInfo file in Files)
            {
                Console.WriteLine(file.FullName);
                Bitmap bmp = (Bitmap)Bitmap.FromFile(file.FullName);
                if (main == null)
                {
                    main = bmp;
                }
                else
                {
                    //main.Save(@"D:\Data\Linage2\diff.png");
                    if (ret == null)
                    {
                        main = DiffBitmap(main, bmp);
                        ret  = new ImageFeatureVector();
                        //ret.LoadFromDiffBitmap(main,new Rectangle(new Point(85,30),new Size(main.Width-85,main.Height-30)));
                        ret.LoadFromDiffBitmap(main, new Rectangle(new Point(0, 0), new Size(main.Width, main.Height)));
                    }
                    else
                    {
                        //ret = ret.ApplyBitmap(bmp, new Rectangle(new Point(85, 30), new Size(main.Width-85, main.Height-30)));
                        ret = ret.ApplyBitmap(bmp, new Rectangle(new Point(0, 0), new Size(main.Width, main.Height)));
                    }
                }
            }
            main = ret.ToBitmap(main);
            //main.Save(@"D:\Data\Linage2\diff.png");
            ret = AverageFeature(folder, main);
            if (ret != null)
            {
                //ret.ToBitmap(main).Save(@"D:\Data\Linage2\avg.png");
            }
            return(ret);
        }
コード例 #6
0
        public ImageFeatureVector AverageFeature(String folder, Bitmap bmpMask = null)
        {
            ImageFeatureVector mask = null;

            if (File.Exists(folder + "mask.png"))
            {
                mask = new ImageFeatureVector();
                if (bmpMask == null)
                {
                    bmpMask = (Bitmap)Bitmap.FromFile(folder + "mask.png");
                }
                mask.LoadFromDiffBitmap(bmpMask, new Rectangle(new Point(0, 0), bmpMask.Size));
                List <ImageFeatureVector> fvs = new List <ImageFeatureVector>();
                DirectoryInfo             d   = new DirectoryInfo(folder);
                FileInfo[] Files = d.GetFiles("*.png");
                foreach (FileInfo file in Files)
                {
                    Bitmap             bmp = (Bitmap)Bitmap.FromFile(file.FullName);
                    ImageFeatureVector fv  = mask.MaskBitmap(bmp);
                    fvs.Add(fv);
                }
                for (int i = 0; i < mask.Count; i++)
                {
                    double r = 0;
                    double g = 0;
                    double b = 0;
                    foreach (ImageFeatureVector fv in fvs)
                    {
                        r += fv[i].color.R;
                        g += fv[i].color.G;
                        b += fv[i].color.B;
                    }
                    mask[i].color = Color.FromArgb((byte)(r / fvs.Count), (byte)(g / fvs.Count), (byte)(b / fvs.Count));
                }
            }
            else
            {
                Console.WriteLine("ERROR: mask.png not found");
            }
            return(mask);
        }
コード例 #7
0
        public ImageFeatureVector ApplyBitmap(Bitmap bmp, Rectangle rect)
        {
            if (rect.IsEmpty)
            {
                rect = new Rectangle(new Point(0, 0), bmp.Size);
            }
            ImageFeatureVector ret = new ImageFeatureVector();

            foreach (ImageFeatureVectorData data in this)
            {
                if (rect.Contains(data.pos))
                {
                    Color color = bmp.GetPixel(data.pos.X, data.pos.Y);
                    if (Utils.ColourDistance(color, data.color) < SimpleImageClassifierConfig.maxColorDiff)
                    {
                        ret.Add(data);
                    }
                }
            }
            return(ret);
        }
コード例 #8
0
        public ClassifyResult[] Classifies(Bitmap bmp, double minScore = 0.60)
        {
            List <ClassifyResult> ret       = new List <ClassifyResult>();
            Stopwatch             stopWatch = new Stopwatch();

            classifyDetail.Clear();
            foreach (String key in features.Keys)
            {
                ImageFeatureVector fv    = features[key];
                double             score = fv.Match(bmp);
                classifyDetail.Add(key, score);
                if (score > minScore)
                {
                    ClassifyResult tmp = new ClassifyResult()
                    {
                        label = key, score = score, evalTime = 0
                    };
                    ret.Add(tmp);
                }
            }
            return(ret.ToArray());
        }
コード例 #9
0
 private void createToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (cmbScreenType.Text != "")
     {
         SimpleImageClassifier imgClassifier = new SimpleImageClassifier();
         ImageFeatureVector    fv            = imgClassifier.CreateFeatureVector(dataPath + cmbScreenType.Text + @"\");
         if (fv == null)
         {
             logDebug("fv=null");
         }
         else
         {
             logDebug("fv=" + fv.Count);
             fv.SaveToFile(dataPath + cmbScreenType.Text + ".txt");
             logDebug("Save to " + dataPath + cmbScreenType.Text + ".txt");
         }
     }
     else
     {
         logDebug("ScreenType not select");
     }
 }