private void cBFilters_SelectedIndexChanged(object sender, EventArgs e) { Bitmap pictureTransform = (Bitmap)pbChoose.Image; if ((string)cBFilters.SelectedItem == "HSL_Filter") { AForge.Imaging.Filters.SaturationCorrection filter = new SaturationCorrection(0.1); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Mediana") { AForge.Imaging.Filters.Median filter = new Median(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } /*if ((string)cBFilters.SelectedItem == "Fourier_Transformation") { Complex[] dst = new Complex[n]; AForge.Math.FourierTransform filter = AForge.Math.FourierTransform.DFT();// .FromBitmap(pictureTransform); Bitmap newImage = filter.Apply(); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; }*/ if ((string)cBFilters.SelectedItem == "Binarization") { pictureTransform = Grayscale.CommonAlgorithms.BT709.Apply(pictureTransform); Threshold threshold = new Threshold(127); threshold.ApplyInPlace(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = pictureTransform; } if ((string)cBFilters.SelectedItem == "Grayscale") { AForge.Imaging.Filters.Grayscale filter = new AForge.Imaging.Filters.Grayscale(0.2125, 0.7154, 0.0721); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "FillHoles") { pictureTransform = Grayscale.CommonAlgorithms.BT709.Apply(pictureTransform); Threshold threshold = new Threshold(127); threshold.ApplyInPlace(pictureTransform); AForge.Imaging.Filters.FillHoles filter = new AForge.Imaging.Filters.FillHoles(); filter.MaxHoleHeight = 5; filter.MaxHoleWidth = 15; filter.CoupledSizeFiltering = false; Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Opening") { AForge.Imaging.Filters.Opening filter = new AForge.Imaging.Filters.Opening(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Closing") { AForge.Imaging.Filters.Closing filter = new AForge.Imaging.Filters.Closing(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Erosion") { AForge.Imaging.Filters.Erosion filter = new AForge.Imaging.Filters.Erosion(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Dilatation") { AForge.Imaging.Filters.Dilatation filter = new AForge.Imaging.Filters.Dilatation(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Edges") { AForge.Imaging.Filters.Edges filter = new AForge.Imaging.Filters.Edges(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } }
protected override void ProcessFilter(UnmanagedImage image) { UnmanagedImage unmanagedImage = opening.Apply(image); subtract.UnmanagedOverlayImage = unmanagedImage; subtract.ApplyInPlace(image); unmanagedImage.Dispose(); }
/// <summary> /// Process the filter on the specified image. /// </summary> /// /// <param name="image">Source image data.</param> /// protected override unsafe void ProcessFilter(UnmanagedImage image) { // perform opening on the source image UnmanagedImage openedImage = opening.Apply(image); // subtract opened image from source image subtract.UnmanagedOverlayImage = openedImage; subtract.ApplyInPlace(image); openedImage.Dispose( ); }
internal FrameWrapper compute(Method method, Bitmap frame) { Bitmap differenceFrame = getDifference(method, frame); lastButOneFrame = lastFrame; lastFrame = frame; // if we cannot compute diffference yet, we return empty list of areas if (differenceFrame == null) { return new FrameWrapper(frame, new List<Rectangle>()); } Bitmap grayscaledFrame = transformToGrayscale(differenceFrame); Bitmap thresholdedFrame = getThresholdedFrame(grayscaledFrame); if (mainWindow.UseOpeningFilter) { //Console.WriteLine("openning openingFilter used"); Opening openingFilter = new Opening(); thresholdedFrame = openingFilter.Apply(thresholdedFrame); } List<Rectangle> areas = getAreas(thresholdedFrame); List<Rectangle> movingObjects = mergeAreas(areas); Bitmap outputFrame = null; switch (mainWindow.OutputFrameType) { case Output.Source: if (method == Method.ThreeFrame) { outputFrame = lastFrame; } else { outputFrame = frame; } break; case Output.Differenced: outputFrame = differenceFrame; break; case Output.Greyscaled: outputFrame = grayscaledFrame; break; case Output.Thresholded: outputFrame = thresholdedFrame; break; } return new FrameWrapper(outputFrame, movingObjects); }
/// <summary> /// Celem metody jest przykadrowanie otrzymanego obrazka, tak aby widok zawierał jedynie kartkę papieru, oraz zwrócenie go do metody UploadFile /// </summary> /// <param name="img"></param> /// <returns></returns> public System.Drawing.Image CropImage(System.Drawing.Image img) { //DocumentSkewChecker skewChecker = new DocumentSkewChecker(); //double angle = skewChecker.GetSkewAngle(image); //RotateBilinear rotationFilter = new RotateBilinear(-angle); //rotationFilter.FillColor = Color.White; //Bitmap rotatedImage = rotationFilter.Apply(image); Bitmap image = new Bitmap(img); UnmanagedImage grayImage = null; if (image.PixelFormat == PixelFormat.Format8bppIndexed) { grayImage = UnmanagedImage.FromManagedImage(image); } else { grayImage = UnmanagedImage.Create(image.Width, image.Height, PixelFormat.Format8bppIndexed); Grayscale.CommonAlgorithms.BT709.Apply(UnmanagedImage.FromManagedImage(image), grayImage); } CannyEdgeDetector edgeDetector = new CannyEdgeDetector(); UnmanagedImage edgesImage = edgeDetector.Apply(grayImage); OtsuThreshold thresholdFilter = new OtsuThreshold(); thresholdFilter.ApplyInPlace(edgesImage); Dilatation DilatationFilter = new Dilatation(); DilatationFilter.Apply(edgesImage); Opening OpeningFilter = new Opening(); OpeningFilter.Apply(edgesImage); BlobCounter blobCounter = new BlobCounter(); blobCounter.MinHeight = 32; blobCounter.MinWidth = 32; blobCounter.FilterBlobs = true; blobCounter.ObjectsOrder = ObjectsOrder.Size; blobCounter.ProcessImage(edgesImage); Blob[] blobs = blobCounter.GetObjectsInformation(); ExtractBiggestBlob BiggestBlob = new ExtractBiggestBlob(); Bitmap biggestBlobsImage = BiggestBlob.Apply(edgesImage.ToManagedImage()); AForge.IntPoint BiggestBlogCorners = BiggestBlob.BlobPosition; Crop cropFilter = new Crop(new Rectangle(BiggestBlogCorners.X, BiggestBlogCorners.Y, biggestBlobsImage.Width, biggestBlobsImage.Height)); Bitmap croppedImage = cropFilter.Apply(image); return croppedImage; }
private void cBFilters_SelectedIndexChanged(object sender, EventArgs e) { Bitmap pictureTransform = (Bitmap)pbChoose.Image; if ((string)cBFilters.SelectedItem == "HSL_Filter") { AForge.Imaging.Filters.SaturationCorrection filter = new SaturationCorrection(0.1); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Mediana") { AForge.Imaging.Filters.Median filter = new Median(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } /*if ((string)cBFilters.SelectedItem == "Fourier_Transformation") * { * Complex[] dst = new Complex[n]; * * AForge.Math.FourierTransform filter = AForge.Math.FourierTransform.DFT();// .FromBitmap(pictureTransform); * Bitmap newImage = filter.Apply(); * pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; * pBNew.Image = newImage; * }*/ if ((string)cBFilters.SelectedItem == "Binarization") { pictureTransform = Grayscale.CommonAlgorithms.BT709.Apply(pictureTransform); Threshold threshold = new Threshold(127); threshold.ApplyInPlace(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = pictureTransform; } if ((string)cBFilters.SelectedItem == "Grayscale") { AForge.Imaging.Filters.Grayscale filter = new AForge.Imaging.Filters.Grayscale(0.2125, 0.7154, 0.0721); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "FillHoles") { pictureTransform = Grayscale.CommonAlgorithms.BT709.Apply(pictureTransform); Threshold threshold = new Threshold(127); threshold.ApplyInPlace(pictureTransform); AForge.Imaging.Filters.FillHoles filter = new AForge.Imaging.Filters.FillHoles(); filter.MaxHoleHeight = 5; filter.MaxHoleWidth = 15; filter.CoupledSizeFiltering = false; Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Opening") { AForge.Imaging.Filters.Opening filter = new AForge.Imaging.Filters.Opening(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Closing") { AForge.Imaging.Filters.Closing filter = new AForge.Imaging.Filters.Closing(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Erosion") { AForge.Imaging.Filters.Erosion filter = new AForge.Imaging.Filters.Erosion(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Dilatation") { AForge.Imaging.Filters.Dilatation filter = new AForge.Imaging.Filters.Dilatation(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Edges") { AForge.Imaging.Filters.Edges filter = new AForge.Imaging.Filters.Edges(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } }
// opening private void button56_Click(object sender, EventArgs e) { ///////////// ini 객체 생성 시작 ///////////////////////////////////////////////////// //현재 프로그램이 실행되고 있는정보 가져오기: 디버깅 모드라면 bin/debug/프로그램명.exe FileInfo exefileinfo = new FileInfo(@"C:\Program Files\PLOCR\PLOCR.exe"); string pathini = exefileinfo.Directory.FullName.ToString(); //프로그램 실행되고 있는데 path 가져오기 string fileName = @"\PLOCRconfig.ini"; // 환경설정 파일명 string filePath = pathini + fileName; //ini 파일 경로 DocumentAnalysis.IniUtil ini = new DocumentAnalysis.IniUtil(filePath); // 만들어 놓았던 iniUtil 객체 생성(생성자 인자로 파일경로 정보 넘겨줌) //////////// ini 객체 생성 끝 ///////////////////////////////////////////////////////// Bitmap source = Global.source; Bitmap tmp = source; // convert to 24 bits per pixel source = imageProcess.Clone(tmp, PixelFormat.Format24bppRgb); // delete old image tmp.Dispose(); // create filter Opening filter = new Opening(); // apply the filter filter.Apply(source); Global.source = source; pictureBox1.Image = Global.source; pictureBox1.Refresh(); textBox27.Text = (int.Parse(textBox24.Text) + 1).ToString(); ini.SetIniValue("opening", "opening횟수", textBox27.Text.ToString()); }