Esempio n. 1
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);
        }
Esempio n. 2
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);
        }