Ejemplo n.º 1
0
        private void Sliding_Window_Scan(List <Image <Gray, byte> > InputImage, System.Drawing.Size patchSize, string path)

        {
            Image <Gray, byte> ImagePatch  = new Image <Gray, byte>(patchSize);
            Image <Gray, byte> OutputImage = new Image <Gray, byte>(512, 424);

            System.Drawing.Rectangle subrect = new System.Drawing.Rectangle(0, 0, patchSize.Width, patchSize.Height);
            var newHelp = 0;

            foreach (var IMG in InputImage)
            {
                CvInvoke.MedianBlur(IMG, IMG, 5);

                for (int h = 0; h <= (IMG.Height - patchSize.Height); h += 35)
                {
                    for (int w = 0; w <= (IMG.Width - patchSize.Width); w += 32)
                    {
                        subrect.X  = w;
                        subrect.Y  = h;
                        ImagePatch = IMG.GetSubRect(subrect).Copy();



                        var Count = ImagePatch.Bytes.Where(x => x != 0).Count();

                        if (Count > 100)
                        {
                            ImagePatch.Save(path + newHelp + ".png");

                            BitmapSource bitmapSource = BitmapSourceConvert.ToBitmapSource(ImagePatch);
                            Actual_Picker.Items.Add(new System.Windows.Controls.Image()
                            {
                                Source = bitmapSource, Height = 50, Width = 50
                            });
                            newHelp++;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private List <System.Drawing.Rectangle> Sliding_Window(List <Image <Gray, byte> > InputImage, System.Drawing.Size patchSize)

        {
            List <System.Drawing.Rectangle> Outrectangles = new List <System.Drawing.Rectangle>();
            Image <Gray, byte> ImagePatch  = new Image <Gray, byte>(patchSize);
            Image <Gray, byte> OutputImage = new Image <Gray, byte>(512, 424);

            System.Drawing.Rectangle subrect = new System.Drawing.Rectangle(0, 0, patchSize.Width, patchSize.Height);
            var help = 0;

            foreach (var IMG in InputImage)
            {
                CvInvoke.MedianBlur(IMG, IMG, 5);

                for (int h = 0; h <= (IMG.Height - patchSize.Height); h += 35)
                {
                    for (int w = 0; w <= (IMG.Width - patchSize.Width); w += 32)
                    {
                        subrect.X  = w;
                        subrect.Y  = h;
                        ImagePatch = IMG.GetSubRect(subrect).Copy();



                        help++;

                        if (ImagePatch.Bytes.Where(x => x != 0).Count() != 0)
                        {
                            List <float[]>          newRegion = new List <float[]>();
                            byte[]                  Pixels;
                            System.Drawing.PointF[] centers;
                            System.Drawing.Point[]  contour;
                            VectorOfVectorOfPoint   dasd = new VectorOfVectorOfPoint();


                            //ImagePatch.Save("C:/Users/CPT Danko/Desktop/Test/" + help + ".png");
                            (Pixels, centers, contour) = ProceessImage(ImagePatch);


                            var Kmeans  = FrameObj.Calculate_Kmeans(centers, Pixels, ImagePatch.Size);
                            var Regions = FrameObj.CalculateRegions(Kmeans);

                            newRegion.Add(Regions.ToArray());

                            Matrix <float> matrixk = new Matrix <float>(Object.To2D <float>(newRegion.ToArray()));

                            var prediction = KNN.Predict(matrixk);



                            if (clsses.Contains((int)prediction))
                            {
                                Outrectangles.Add(subrect);
                            }
                        }
                    }
                }
            }


            return(Outrectangles);
        }