Exemplo n.º 1
0
        private string reconhecerCaptcha(Image img)
        {
            Bitmap imagem = new Bitmap(img);

            imagem = imagem.Clone(new Rectangle(0, 0, img.Width, img.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            Erosion        erosion    = new Erosion();
            Dilatation     dilatation = new Dilatation();
            Invert         inverter   = new Invert();
            ColorFiltering cor        = new ColorFiltering();

            cor.Blue  = new AForge.IntRange(200, 255);
            cor.Red   = new AForge.IntRange(200, 255);
            cor.Green = new AForge.IntRange(200, 255);
            Opening            open  = new Opening();
            BlobsFiltering     bc    = new BlobsFiltering();
            Closing            close = new Closing();
            GaussianSharpen    gs    = new GaussianSharpen();
            ContrastCorrection cc    = new ContrastCorrection();

            bc.MinHeight = 10;
            GrayscaleRMY    gray = new GrayscaleRMY();
            Threshold       thr  = new Threshold(200);
            Difference      diff = new Difference(dilatation.Apply(imagem));
            FiltersSequence seq  = new FiltersSequence(diff, inverter, erosion, gray, thr, cc);

            pictureBox.Image = seq.Apply(imagem);
            string reconhecido = OCR((Bitmap)pictureBox.Image);

            return(reconhecido);
        }
Exemplo n.º 2
0
        public Bitmap ToGrayscaleRMY(Bitmap Im)
        {
            AForge.Imaging.Filters.GrayscaleRMY Img = new GrayscaleRMY();
            Bitmap bmImage = AForge.Imaging.Image.Clone(new Bitmap(Im), PixelFormat.Format24bppRgb);

            return(Img.Apply(bmImage));
        }
Exemplo n.º 3
0
        public static byte[] ApplyFilter(byte[] imageBytes, ImageProcessingFilters filter, ImageFormat format = null)
        {
            IFilter baseFilter = null;

            switch (filter)
            {
            case ImageProcessingFilters.Default:
                return(imageBytes);

            case ImageProcessingFilters.GrayscaleBT709:
                baseFilter = new GrayscaleBT709();
                break;

            case ImageProcessingFilters.GrayscaleRMY:
                baseFilter = new GrayscaleRMY();
                break;

            case ImageProcessingFilters.GrayscaleY:
                baseFilter = new GrayscaleY();
                break;

            case ImageProcessingFilters.BayerFilter:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new ExtractChannel(RGB.B));
                ((FiltersSequence)baseFilter).Add(new BayerFilter());
                break;

            /*
             * case ImageProcessingFilters.ImageWarp:
             * baseFilter = new ImageWarp(
             * break;
             * */
            case ImageProcessingFilters.Channel_Red:
                baseFilter = new ExtractChannel(RGB.R);
                break;

            case ImageProcessingFilters.Channel_Green:
                baseFilter = new ExtractChannel(RGB.G);
                break;

            case ImageProcessingFilters.Channel_Blue:
                baseFilter = new ExtractChannel(RGB.B);
                break;

            case ImageProcessingFilters.WaterWave:
                baseFilter = new WaterWave();
                ((WaterWave)baseFilter).HorizontalWavesCount     = 10;
                ((WaterWave)baseFilter).HorizontalWavesAmplitude = 5;
                ((WaterWave)baseFilter).VerticalWavesCount       = 3;
                ((WaterWave)baseFilter).VerticalWavesAmplitude   = 15;
                break;

            case ImageProcessingFilters.Sepia:
                baseFilter = new Sepia();
                break;

            case ImageProcessingFilters.BrightnessCorrection:
                baseFilter = new BrightnessCorrection(-50);
                break;

            case ImageProcessingFilters.ContrastCorrection:
                baseFilter = new ContrastCorrection(15);
                break;

            case ImageProcessingFilters.SaturationCorrection1:
                baseFilter = new SaturationCorrection(-0.5f);
                break;

            case ImageProcessingFilters.SaturationCorrection2:
                baseFilter = new SaturationCorrection(-.25f);
                break;

            case ImageProcessingFilters.SaturationCorrection3:
                baseFilter = new SaturationCorrection(+0.5f);
                break;

            case ImageProcessingFilters.Invert:
                baseFilter = new Invert();
                break;

            case ImageProcessingFilters.Blur:
                baseFilter = new Blur();
                break;

            case ImageProcessingFilters.RotateChannels:
                baseFilter = new RotateChannels();
                break;

            case ImageProcessingFilters.RotateChannels2:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new RotateChannels());
                ((FiltersSequence)baseFilter).Add(new RotateChannels());
                break;

            case ImageProcessingFilters.AdditiveNoise:
                IRandomNumberGenerator generator = new UniformGenerator(new Range(-50, 50));
                baseFilter = new AdditiveNoise(generator);
                break;

            case ImageProcessingFilters.GammaCorrection:
                baseFilter = new GammaCorrection(0.5);
                break;

            case ImageProcessingFilters.HistogramEqualization:
                baseFilter = new HistogramEqualization();
                break;

            case ImageProcessingFilters.OrderedDithering:
                byte[,] matrix = new byte[4, 4]
                {
                    { 95, 233, 127, 255 },
                    { 159, 31, 191, 63 },
                    { 111, 239, 79, 207 },
                    { 175, 47, 143, 15 }
                };
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new GrayscaleBT709());
                ((FiltersSequence)baseFilter).Add(new OrderedDithering(matrix));
                break;

            case ImageProcessingFilters.Pixallete:
                baseFilter = new Pixellate();
                break;

            case ImageProcessingFilters.SimplePosterization:
                baseFilter = new SimplePosterization();
                break;

            case ImageProcessingFilters.Texturer_Textile:
                baseFilter = new Texturer(new AForge.Imaging.Textures.TextileTexture(), 0.3, 0.7);
                break;

            case ImageProcessingFilters.Texturer_Cloud:
                baseFilter = new Texturer(new AForge.Imaging.Textures.CloudsTexture(), 0.3, 0.7);
                break;

            case ImageProcessingFilters.Texturer_Marble:
                baseFilter = new Texturer(new AForge.Imaging.Textures.MarbleTexture(), 0.3, 0.7);
                break;

            case ImageProcessingFilters.Texturer_Wood:
                baseFilter = new Texturer(new AForge.Imaging.Textures.WoodTexture(), 0.3, 0.7);
                break;

            case ImageProcessingFilters.Texturer_Labyrinth:
                baseFilter = new Texturer(new AForge.Imaging.Textures.LabyrinthTexture(), 0.3, 0.7);
                break;

            case ImageProcessingFilters.SobelEdgeDetector:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new ExtractChannel(RGB.R));
                ((FiltersSequence)baseFilter).Add(new SobelEdgeDetector());
                break;

            case ImageProcessingFilters.SobelEdgeDetectorInvert:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new ExtractChannel(RGB.R));
                ((FiltersSequence)baseFilter).Add(new SobelEdgeDetector());
                ((FiltersSequence)baseFilter).Add(new Invert());
                break;

            case ImageProcessingFilters.SobelEdgeDetectorSepia:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new ExtractChannel(RGB.R));
                ((FiltersSequence)baseFilter).Add(new SobelEdgeDetector());
                ((FiltersSequence)baseFilter).Add(new GrayscaleToRGB());
                ((FiltersSequence)baseFilter).Add(new Sepia());
                break;

            case ImageProcessingFilters.SobelEdgeDetectorSepiaCanvas:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new ExtractChannel(RGB.R));
                ((FiltersSequence)baseFilter).Add(new SobelEdgeDetector());
                ((FiltersSequence)baseFilter).Add(new GrayscaleToRGB());
                ((FiltersSequence)baseFilter).Add(new Sepia());
                ((FiltersSequence)baseFilter).Add(new SimplePosterization());
                ((FiltersSequence)baseFilter).Add(new Texturer(new AForge.Imaging.Textures.TextileTexture(), 0.3, 0.7));
                break;

            case ImageProcessingFilters.Drawing:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new GrayscaleBT709());
                ((FiltersSequence)baseFilter).Add(new SobelEdgeDetector());
                ((FiltersSequence)baseFilter).Add(new Invert());
                ((FiltersSequence)baseFilter).Add(new SimplePosterization());
                break;

            case ImageProcessingFilters.DrawingSepia:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new GrayscaleBT709());
                ((FiltersSequence)baseFilter).Add(new SobelEdgeDetector());
                ((FiltersSequence)baseFilter).Add(new Invert());
                ((FiltersSequence)baseFilter).Add(new SimplePosterization());
                ((FiltersSequence)baseFilter).Add(new GrayscaleToRGB());
                ((FiltersSequence)baseFilter).Add(new Sepia());
                break;

            case ImageProcessingFilters.OilCanvas:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new SimplePosterization());
                ((FiltersSequence)baseFilter).Add(new Texturer(new AForge.Imaging.Textures.TextileTexture(), 0.3, 0.7));
                break;

            case ImageProcessingFilters.OilCanvasGray:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new SimplePosterization());
                ((FiltersSequence)baseFilter).Add(new Texturer(new AForge.Imaging.Textures.TextileTexture(), 0.3, 0.7));
                ((FiltersSequence)baseFilter).Add(new GrayscaleBT709());
                break;

            case ImageProcessingFilters.OilCanvasSepia:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new SimplePosterization());
                ((FiltersSequence)baseFilter).Add(new Texturer(new AForge.Imaging.Textures.TextileTexture(), 0.3, 0.7));
                ((FiltersSequence)baseFilter).Add(new Sepia());
                break;
            }

            if (baseFilter == null)
            {
                return(null);
            }

            return(ApplyFilter(imageBytes, baseFilter, format));
        }
Exemplo n.º 4
0
        private void grayScaleRMYToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GrayscaleRMY rmyobject = new GrayscaleRMY();

            pictureBox2.Image = rmyobject.Apply((Bitmap)pictureBox1.Image);
        }
Exemplo n.º 5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo goo   = null;
            Image   image = new Image();

            if (!DA.GetData(0, ref goo))
            {
                return;
            }
            if (!goo.TryGetImage(ref image))
            {
                return;
            }

            int mode = 0;

            DA.GetData(1, ref mode);

            double numValA = 1.0;

            DA.GetData(2, ref numValA);

            double numValB = 1.0;

            DA.GetData(3, ref numValB);

            double numValC = 1.0;

            DA.GetData(3, ref numValC);

            Filter filter = new Filter();

            int[] indices = new int[] { 2, 3, 4 };

            switch ((FilterModes)mode)
            {
            case FilterModes.BT709:
                ClearParameter(indices);
                filter = new GrayscaleBT709();
                image.Filters.Add(new GrayscaleBT709());
                break;

            case FilterModes.RMY:
                ClearParameter(indices);
                filter = new GrayscaleRMY();
                image.Filters.Add(new GrayscaleRMY());
                break;

            case FilterModes.Y:
                ClearParameter(indices);
                filter = new GrayscaleY();
                image.Filters.Add(new GrayscaleY());
                break;

            case FilterModes.Simple:
                SetParameter(2, "R", "Red", "The Red coefficient");
                SetParameter(3, "G", "Green", "The Green coefficient");
                SetParameter(4, "B", "Blue", "The Blue coefficient");
                filter = new Simple(numValA, numValB, numValC);
                image.Filters.Add(new Simple(numValA, numValB, numValC));
                break;
            }

            message = ((FilterModes)mode).ToString();
            UpdateMessage();

            DA.SetData(0, image);
            DA.SetData(1, filter);
        }