public static Bitmap ApplyFilters03(Image img) { Bitmap image = new Bitmap(img); image = image.Clone(new Rectangle(0, 0, img.Width, img.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb); GaussianSharpen gs = new GaussianSharpen(); GaussianSharpen sharp = new GaussianSharpen(4, 21); 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); //FiltersSequence seq = new FiltersSequence(gs); //var filteredImage = seq.Apply(image); //var image2 = AForge.Imaging.Image.Clone(image, PixelFormat.Format8bppIndexed); //AForge.Imaging.Image.SetGrayscalePalette(image2); //SISThreshold filter = new SISThreshold(); //filter.ApplyInPlace(image2); return(image); }
private Bitmap LimparImagem(Image img) { var imagem = new Bitmap(img); imagem = imagem.Clone(new Rectangle(0, 0, img.Width, img.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb); var inverter = new Invert(); var cor = new ColorFiltering { Blue = new AForge.IntRange(200, 255), Red = new AForge.IntRange(200, 255), Green = new AForge.IntRange(200, 255) }; var open = new Opening(); var bc = new BlobsFiltering(); var gs = new GaussianSharpen(); var cc = new ContrastCorrection(); bc.MinHeight = 10; var seq = new FiltersSequence(gs, inverter, open, inverter, bc, inverter, open, cc, cor, bc, inverter); imagem = seq.Apply(imagem); return(imagem); }
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; FiltersSequence seq = new FiltersSequence(gs, inverter, open, inverter, bc, inverter, open, cc, cor, bc, inverter); imagem = seq.Apply(imagem); //imagem.Save(Directory.GetCurrentDirectory() + "\\Captcha2.png", System.Drawing.Imaging.ImageFormat.Png); string reconhecido = OCR(imagem); //string reconhecido = ocr.Principal(Directory.GetCurrentDirectory() + "\\Captcha2.png"); return(reconhecido); }
public static Bitmap ApplyFilters(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; FiltersSequence seq = new FiltersSequence(gs, inverter, open, inverter, bc, inverter, open, cc, cor, bc, inverter); var filteredImage = seq.Apply(imagem); return(filteredImage); }
public static Bitmap GaussianSharpen(Bitmap bmp, int value, int kernel) { GaussianSharpen filter = new GaussianSharpen(value, kernel); filter.ApplyInPlace(bmp); return(bmp); }
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); }
public static Task <(Bitmap, string)> DeCaptchAsync(Image img) { return((Task <(Bitmap, string)>)Task.Run(() => { string value; Bitmap bmp = new Bitmap(img); bmp = bmp.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(50, 255); //cor.Green = new AForge.IntRange(200, 255); Opening open = new Opening(); BlobsFiltering bc = new BlobsFiltering() { MinHeight = 10 }; Closing close = new Closing(); GaussianSharpen gs = new GaussianSharpen(); ContrastCorrection cc = new ContrastCorrection(); FiltersSequence seq = new FiltersSequence(gs, inverter, open, inverter, bc, inverter, open, cc, cor, bc, inverter, dilatation); Image image = seq.Apply(bmp); value = OCR((Bitmap)image); return ((Bitmap)image, value); })); }
private string reconhecerCaptcha(Image img) { Bitmap _bitmap = new Bitmap(img); _bitmap = _bitmap.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; FiltersSequence seq = new FiltersSequence(gs, inverter, open, inverter, bc, inverter, open, cc, cor, bc, inverter); pictureBox1.Image = seq.Apply(_bitmap); string recognedString = OCR((Bitmap)pictureBox1.Image); return(recognedString); }
public static Bitmap GaussianSharpen(Bitmap Imagem) { GaussianSharpen filter = new GaussianSharpen(); Imagem = Imagem.Clone(new Rectangle(0, 0, Imagem.Width, Imagem.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb); Imagem = filter.Apply(Imagem); return(Imagem); }
public void sharpen_image() { var image = (Bitmap)Bitmap.FromFile(@"C:\Users\Rosen.rusev\Pictures\Logitech Webcam\Picture 6.jpg"); GaussianSharpen filter = new GaussianSharpen(4, 11); // apply the filter filter.ApplyInPlace(image); image.Save(@"C:\Users\Rosen.rusev\Pictures\Logitech Webcam\Picture 6_1.jpg"); }
public mSharpenGaussian(int kernalSize, double sigma) { BitmapType = BitmapTypes.None; Sigma = sigma; KernalSize = kernalSize; filter = new GaussianSharpen(Sigma, KernalSize); }
/// <summary> /// Uses a Gaussian kernel to sharpen the current image. /// </summary> /// <param name="gaussianLayer"> /// The <see cref="T:ImageProcessor.Imaging.GaussianLayer"/> for applying sharpening and /// blurring methods to an image. /// </param> /// <returns> /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public ImageFactory GaussianSharpen(GaussianLayer gaussianLayer) { if (this.ShouldProcess) { GaussianSharpen gaussianSharpen = new GaussianSharpen { DynamicParameter = gaussianLayer }; this.CurrentImageFormat.ApplyProcessor(gaussianSharpen.ProcessImage, this); } return(this); }
public static Bitmap ApplyFilters02(Image img) { Bitmap imagem = new Bitmap(img); imagem = imagem.Clone(new Rectangle(0, 0, img.Width, img.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb); GaussianSharpen gs = new GaussianSharpen(); GaussianSharpen sharp = new GaussianSharpen(4, 21); FiltersSequence seq = new FiltersSequence(gs, sharp); var filteredImage = seq.Apply(imagem); return(filteredImage); }
public static Bitmap Limpar(Image img) { Bitmap imagem = new Bitmap(img); Bitmap newBitmap = new Bitmap(imagem.Width, imagem.Height); Graphics g = Graphics.FromImage(newBitmap); g.FillRectangle(Brushes.White, 0, 0, imagem.Width, imagem.Height); ColorMatrix colorMatrix = new ColorMatrix( new float[][] { new float[] { .3f, .3f, .3f, 0, 0 }, new float[] { .59f, .59f, .59f, 0, 0 }, new float[] { .11f, .11f, .11f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } }); ImageAttributes attributes = new ImageAttributes(); attributes.SetColorMatrix(colorMatrix); g.DrawImage(imagem, new Rectangle(0, (int)(imagem.Height * 0.1), imagem.Width, (int)(imagem.Height * 0.8)), 0, imagem.Height * 0.1f, imagem.Width, imagem.Height * 0.8f, GraphicsUnit.Pixel, attributes); g.Dispose(); imagem = newBitmap; 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(); GaussianSharpen gs = new GaussianSharpen(); ContrastCorrection cc = new ContrastCorrection(); bc.MinHeight = 3; FiltersSequence seq = new FiltersSequence(gs, inverter, open, inverter, bc, inverter, open, cc, cor, bc, inverter); return((Bitmap)seq.Apply(imagem)); }
private static string ResoudreItalien(Bitmap captcha) { Bitmap imagem = captcha; imagem = imagem.Clone(new Rectangle(0, 0, captcha.Width, captcha.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; FiltersSequence seq = new FiltersSequence(gs, inverter, open, inverter, bc, inverter, open, cc, cor, bc, inverter); string reconhecido = OCRItalien((Bitmap)seq.Apply(imagem)); return reconhecido; }
public static Bitmap FormatImageRecaptcha(Bitmap imagem) { imagem = imagem.Clone(new Rectangle(0, 0, imagem.Width, imagem.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb); Erosion erosion = new Erosion(); Dilatation dilatation = new Dilatation(); Closing close = new Closing(); 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(); bc.MinHeight = 30; // chỉ bắt các đối tượng có chiều cao >=30 GaussianSharpen gs = new GaussianSharpen(1, 2); // tăng độ đậm của chi tiết lên gấp đôi ContrastCorrection cc = new ContrastCorrection(); FiltersSequence seq = new FiltersSequence(gs, inverter, open, inverter, bc, open, cc, bc, cor); return(seq.Apply(imagem)); }
private string SolveCaptcha(Image img) { Bitmap imagem = new Bitmap(img); SetPixelColor(imagem, false); SetPixelColor(imagem, false); string filename = "test/" + Guid.NewGuid().ToString() + ".png"; SetPixelColor(imagem, false); imagem = ProcessImage(imagem); imagem.Save(filename); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(filename); var imageClone = bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb); Erosion erosion = new Erosion(); Dilatation dilatation = new Dilatation(); Invert inverter = new Invert(); ColorFiltering cor = new ColorFiltering(); cor.Red = new AForge.IntRange(150, 255); cor.Green = new AForge.IntRange(150, 255); cor.Blue = new AForge.IntRange(128, 255); Opening open = new Opening(); BlobsFiltering bc = new BlobsFiltering(); Closing close = new Closing(); GaussianSharpen gs = new GaussianSharpen(); ContrastCorrection cc = new ContrastCorrection(); FiltersSequence seq = new FiltersSequence(cc, gs, inverter, cor, bc, cor, cc, cor, bc); var image = seq.Apply(imageClone); var byteImg = ImageToByte(image); var result = OCR(ByteToImage(byteImg)); return(result); }
public string Post([FromBody] GaussianSharpen req) { var response = GaussianSharpen.ProcessImage(req); return(response); }
public Bitmap edgeDetection() { Bitmap colorImg = (Bitmap)videoSourcePlayer1.GetCurrentVideoFrame(); Grayscale grayfilter = new Grayscale(cr, cg, cb); GaussianBlur blurFilter = new GaussianBlur(); GaussianSharpen sharpenFilter = new GaussianSharpen(); Bitmap originalImage; if (gausianToggle == 0) { originalImage = (Bitmap)grayfilter.Apply(colorImg); } else if (gausianToggle == 1) { originalImage = sharpenFilter.Apply((Bitmap)colorImg); originalImage = (Bitmap)grayfilter.Apply(originalImage); } else { originalImage = blurFilter.Apply((Bitmap)colorImg); originalImage = (Bitmap)grayfilter.Apply(originalImage); } switch (caseValue) { case 1: //canny scrollableImagePanel1.Image = originalImage; CannyEdgeDetector edgeDectector = new CannyEdgeDetector(); edgeDectector.HighThreshold = (byte)cannyUpperThresholdSlider.Value; edgeDectector.LowThreshold = (byte)cannyLowerThresholdSlider.Value; edgeDectector.ApplyInPlace(scrollableImagePanel1.Image); return((Bitmap)scrollableImagePanel1.Image); case 2: //gray scale scrollableImagePanel3.Image = originalImage; Grayscale customGrayScale = new Grayscale((cr * (graySlider.Value / 100)), (cb * (graySlider.Value / 100)), (cg * (graySlider.Value / 100))); originalImage = customGrayScale.Apply(colorImg); return(originalImage); case 3: //Black and White scrollableImagePanel2.Image = originalImage; Threshold thresholdFilter = new Threshold(); thresholdFilter.ThresholdValue = hScrollBar1.Value; thresholdFilter.ApplyInPlace(scrollableImagePanel2.Image); return((Bitmap)scrollableImagePanel2.Image); case 4: //Mixed Color Edits scrollableImagePanel5.Image = colorImg; ChannelFiltering colorChannelFilter = new ChannelFiltering(); colorChannelFilter.Red = new IntRange(0, redSlider.Value); colorChannelFilter.Blue = new IntRange(0, blueSlider.Value); colorChannelFilter.Green = new IntRange(0, greenSlider.Value); colorChannelFilter.ApplyInPlace((Bitmap)scrollableImagePanel5.Image); return((Bitmap)scrollableImagePanel5.Image); case 5: //Specific Color edits ColorFiltering colorFilter = new ColorFiltering(); if (colorToggle == 1) { Console.WriteLine("Red disabled"); colorFilter.Red = new IntRange(0, 0); colorFilter.Blue = new IntRange(0, 255); colorFilter.Green = new IntRange(0, 255); colorFilter.Apply(colorImg); originalImage = colorImg; return(originalImage); } else if (colorToggle == 2) { Console.WriteLine("Blue disabled"); colorFilter.Red = new IntRange(0, 255); colorFilter.Blue = new IntRange(0, 0); colorFilter.Green = new IntRange(0, 255); colorFilter.Apply(colorImg); originalImage = colorImg; return(originalImage); } else if (colorToggle == 3) { Console.WriteLine("Green disabled"); colorFilter.Red = new IntRange(0, 255); colorFilter.Blue = new IntRange(0, 255); colorFilter.Green = new IntRange(0, 0); colorFilter.Apply(colorImg); originalImage = colorImg; return(originalImage); } else { return(colorImg); } } return(originalImage); }
public override Bitmap ApplyFilter(List <Bitmap> bitmap) { GaussianSharpen sharpen = new GaussianSharpen(sigma, size); return(sharpen.Apply(bitmap[0])); }
public IList <IFilter> GetFilterList(ImageProcessingSettings imageProcessingSettings) { var filterList = new List <IFilter>(); // Brightness if (imageProcessingSettings.BrightnessAdjustment.Value != 0) { BrightnessCorrection filter = new BrightnessCorrection(imageProcessingSettings.BrightnessAdjustment.Value); filterList.Add(filter); } // Contrast if (imageProcessingSettings.ContrastAdjustment.Value != 0) { ContrastCorrection filter = new ContrastCorrection(imageProcessingSettings.ContrastAdjustment.Value); filterList.Add(filter); } // Saturation if (imageProcessingSettings.SaturationAdjustment.Value != 0) { // Only use 60% of the available correction range float adjustedValue = ((float)imageProcessingSettings.SaturationAdjustment.Value / 100) * 60; float value = (float)adjustedValue / 100; SaturationCorrection filter = new SaturationCorrection(value); filterList.Add(filter); } // Sharpness if (imageProcessingSettings.SharpnessAdjustment.Value != 0) { double sigma = 1.5; GaussianSharpen filter = new GaussianSharpen(sigma, imageProcessingSettings.SharpnessAdjustment.Value); filterList.Add(filter); } // Red, Green, Blue if (imageProcessingSettings.RedAdjustment.Value != 0 || imageProcessingSettings.GreenAdjustment.Value != 0 || imageProcessingSettings.BlueAdjustment.Value != 0) { LevelsLinear filter = new LevelsLinear(); if (imageProcessingSettings.RedAdjustment.Value != 0) { float val = ((float)imageProcessingSettings.RedAdjustment.Value / 100) * 255; if (imageProcessingSettings.RedAdjustment.Value > 0) { var finalVal = 255 - (int)val; filter.InRed = new IntRange(0, finalVal); } else { val = val * -1; filter.InRed = new IntRange((int)val, 255); } } if (imageProcessingSettings.GreenAdjustment.Value != 0) { float val = ((float)imageProcessingSettings.GreenAdjustment.Value / 100) * 255; if (imageProcessingSettings.GreenAdjustment.Value > 0) { var finalVal = 255 - (int)val; filter.InGreen = new IntRange(0, finalVal); } else { val = val * -1; filter.InGreen = new IntRange((int)val, 255); } } if (imageProcessingSettings.BlueAdjustment.Value != 0) { float val = ((float)imageProcessingSettings.BlueAdjustment.Value / 100) * 255; if (imageProcessingSettings.BlueAdjustment.Value > 0) { var finalVal = 255 - (int)val; filter.InBlue = new IntRange(0, finalVal); } else { val = val * -1; filter.InBlue = new IntRange((int)val, 255); } } filterList.Add(filter); } return(filterList); }
public virtual void ProccessImage(BackgroundWorker worker) { this.worker = worker; UpdateProgress(3); //Brightness and sharpen filters BrightnessCorrection cfilter = new BrightnessCorrection(Settings.Brightness); GaussianSharpen filter = new GaussianSharpen(4, 11); //Apply filters cfilter.ApplyInPlace(sourceBitmap); UpdateProgress(15); filter.ApplyInPlace(sourceBitmap); UpdateProgress(30); //Convert to gray var tmpImage = ConvertToGrayScale(sourceBitmap); UpdateProgress(35); //Cut edges tmpImage = CutEdgesAndInvert(tmpImage); UpdateProgress(40); //Get angle for rotating image var rotateAngle = DetectRotation(tmpImage); UpdateProgress(45); if (rotateAngle != 0) { RotateBilinear rotate = new RotateBilinear(rotateAngle, true); tmpImage = rotate.Apply(tmpImage); } //Build horizontal hough lines OCRLessonReport.Imaging.HoughLineTransformation lineTransform = new OCRLessonReport.Imaging.HoughLineTransformation(); HoughLineRequestSettings settings = new HoughLineRequestSettings { HorizontalLines = true, VerticalLines = false, HorizontalDeviation = 2 }; lineTransform.ProcessImage(tmpImage, settings); //Get horizontal line HoughLine[] lines = lineTransform.GetLinesByRelativeIntensity(Settings.HorizontalSensitivity); //Get half width and height for future calculations int hWidth = tmpImage.Width / 2; int hHeight = tmpImage.Height / 2; //Get line coordinates (Y axis only - horizontal lines) var lineCoordinates = lines.Select(line => hHeight - line.Radius); //Grouping coords by delta var groupedCoordinates = ImagingHelper.GroupingCoordinates(lineCoordinates, Settings.LineGroupingDelta); if (groupedCoordinates.Count <= Settings.HeaderStartLine) { throw new Exception("Invalid source. Can't be recognized"); } int headerLineY0 = groupedCoordinates[Settings.HeaderStartLine]; int headerLineY1 = groupedCoordinates[Settings.HeaderStartLine + 1]; //Copy header to new image var headerImage = tmpImage.Copy(new Rectangle(0, headerLineY0, tmpImage.Width, headerLineY1 - headerLineY0)); //Parse header to get header lines HoughLineRequestSettings headerSettings = new HoughLineRequestSettings { HorizontalLines = false, VerticalLines = true, VerticalDeviation = 1 }; lineTransform.ProcessImage(headerImage, headerSettings); Func <HoughLine, int, int> getRadius = (l, w) => { if (l.Theta > 90 && l.Theta < 180) { return(w - l.Radius); } else { return(w + l.Radius); } }; HoughLine[] headerLines = lineTransform.GetLinesByRelativeIntensity(Settings.VerticalSensitivity); //Get header vertical lines var headerLineCoordinates = headerLines.Select(line => getRadius(line, hWidth)); //Grouped lines var groupedheaderLineCoordinates = ImagingHelper.GroupingCoordinates(headerLineCoordinates, Settings.LineGroupingDelta); //Build cell map List <TableCell> cellMap = new List <TableCell>(); UpdateProgress(50); //Use tess engine for ocr using (TesseractEngine engine = new TesseractEngine(Settings.TessdataPath, Settings.TessdataLanguage)) { //Parse top header var x0 = groupedheaderLineCoordinates.FirstOrDefault(); var x1 = groupedheaderLineCoordinates.LastOrDefault(); var y0 = groupedCoordinates[0]; var y1 = groupedCoordinates[1]; int fullProgress = (groupedheaderLineCoordinates.Count - 1) * (groupedCoordinates.Count - Settings.BottomStartLine - 1 - Settings.HeaderStartLine); int curProgress = 0; var hImage = tmpImage.Copy(new Rectangle(x0, y0, x1 - x0, y1 - y0)); hImage = ProcessCell(hImage); using (var page = engine.Process(hImage, PageSegMode.SingleBlock)) { cellMap.Add(new TableCell(0, 0, TableCellType.MainHeader, hImage, page.GetText(), false)); } //Parse table for (int i = 0; i < groupedheaderLineCoordinates.Count - 1; i++) { int subjectArea = (i < Settings.ColumnSubjectStart - 1) ? 0 : 1; for (int j = Settings.HeaderStartLine; j < groupedCoordinates.Count - Settings.BottomStartLine - 1; j++) { int headerArea = (j == Settings.HeaderStartLine) ? 2 : 0; TableCellType cellType = (TableCellType)(subjectArea + headerArea); var cellImg = tmpImage.Copy(new Rectangle(groupedheaderLineCoordinates[i], groupedCoordinates[j], groupedheaderLineCoordinates[i + 1] - groupedheaderLineCoordinates[i], groupedCoordinates[j + 1] - groupedCoordinates[j])); if (cellType == TableCellType.Text || cellType == TableCellType.Header || cellType == TableCellType.HeaderRotated) { cellImg = ProcessCell(cellImg, i == Settings.NameStartLine); string text = String.Empty; if (cellType == TableCellType.HeaderRotated) { cellImg.RotateFlip(RotateFlipType.Rotate90FlipNone); } using (var page = engine.Process(cellImg, PageSegMode.SingleBlock)) { text = page.GetText(); } cellMap.Add(new TableCell(i, j, cellType, cellImg, text, false)); } else { cellImg = ProcessCell(cellImg); BilateralSmoothing bfilter = new BilateralSmoothing(); bfilter.KernelSize = 7; bfilter.SpatialFactor = 10; bfilter.ColorFactor = 60; bfilter.ColorPower = 0.5; bfilter.ApplyInPlace(cellImg); cellImg = FilterColors(cellImg, Settings.FilteringColor, ByteColor.Black, ByteColor.White); BlobCounter bcounter = new BlobCounter(); bcounter.ProcessImage(cellImg); var blobs = bcounter.GetObjects(cellImg, false); if (blobs.Length < 1) { continue; } var biggestBlob = blobs.OrderBy(b => b.Area).LastOrDefault(); var biggestBlobsImage = biggestBlob.Image.ToManagedImage(); cellMap.Add(new TableCell(i, j, cellType, biggestBlobsImage, GetMask(biggestBlobsImage).ToString(), GetMask(biggestBlobsImage))); } curProgress++; double reportProgress = (double)curProgress / (double)fullProgress * 50 + 50; UpdateProgress((int)reportProgress); } } } this.Cells = cellMap; UpdateProgress(100); }
public static Bitmap ApplyGaussianSharpenFilter(Bitmap input, int kernelSize, double sigma) { GaussianSharpen gaussianSharpenFilter = new GaussianSharpen(sigma, kernelSize); return(gaussianSharpenFilter.Apply(input)); }
public Bitmap GaussianSharpenFilter(Bitmap img) { GaussianSharpen filter = new GaussianSharpen(4, 11); return(filter.Apply(img)); }