private void SetOilC(object obj) { Bitmap bmp = null; try { bmp = (Bitmap)Images.Instance.CurrentBitmap.Clone(); } catch { } Bitmap bmpselected = null; try { bmpselected = (Bitmap)Images.Instance.SelectedBitmap.Clone(); } catch { } if (partarea == true && bmpselected != null) { oilFilter.ApplyInPlace(bmpselected); Graphics newImage = Graphics.FromImage(bmp); newImage.DrawImage(bmpselected, SelectedPoints.selectPointForEfX, SelectedPoints.selectPointForEfY, bmpselected.Width, bmpselected.Height); } else if (bmp != null) { oilFilter.ApplyInPlace(bmp); } Images.Instance.CurrentBitmap = bmp; Images.Instance.NotifyImages(); this.Temporary = bmp; }
private void Oil_Filter_Process() { var filter = new OilPainting(15); AddLog("filtr OilPainting na " + _view.CurrentFile); filter.ApplyInPlace(_image); Thread.Sleep(200); }
private void Oil_Filter_Process(object callback) { var filter = new OilPainting(15); AddLog("filtr OilPainting na " + _view.CurrentFile); filter.ApplyInPlace(_image); Thread.Sleep(200); ((AutoResetEvent)callback).Set(); }
private void button2_Click(object sender, EventArgs e) { button2.Text = "处理中"; switch (comboBox4.SelectedIndex) { case 0: { Bitmap temp = (Bitmap)pictureBox1.Image; OilPainting filter3 = new OilPainting(10); // apply the filter filter3.ApplyInPlace(temp); this.pictureBox2.Image = ResizeBitmap(temp); break; } case 1: { Bitmap temp = (Bitmap)pictureBox1.Image; temp = new Grayscale(0.2125, 0.7154, 0.0721).Apply(temp); DifferenceEdgeDetector edgeDetector = new DifferenceEdgeDetector(); temp = edgeDetector.Apply(temp); temp = new Threshold((int)numericUpDown1.Value).Apply(temp); //FillHoles filter2 = new FillHoles(); //filter2.MaxHoleHeight = MinHeight; //filter2.MaxHoleWidth = MaxWidth; //filter2.CoupledSizeFiltering = false; // apply the filter //temp = filter2.Apply(temp); //HorizontalRunLengthSmoothing hrls = new HorizontalRunLengthSmoothing(40); // apply the filter //hrls.ApplyInPlace(temp); /*AForge.Imaging.Filters.BlobsFiltering filter = new AForge.Imaging.Filters.BlobsFiltering(); * // 设置过滤条件(对象长、宽至少为70) * filter.CoupledSizeFiltering = true; * filter.MaxWidth = (int)numericUpDown3.Value; * filter.MaxHeight = (int)numericUpDown4.Value; * filter.MinWidth = (int)numericUpDown5.Value; * filter.MinHeight = (int)numericUpDown6.Value; * filter.ApplyInPlace(temp);*/ BlobCounter blobCounter = new BlobCounter(); blobCounter.MinHeight = 32; blobCounter.MinWidth = 32; blobCounter.FilterBlobs = true; blobCounter.ObjectsOrder = ObjectsOrder.Size; // 4 - find all stand alone blobs blobCounter.ProcessImage(temp); Blob[] blobs = blobCounter.GetObjectsInformation(); SimpleShapeChecker shapeChecker = new SimpleShapeChecker(); List <IntPoint> corners = null; List <IntPoint> corners2 = null; for (int i = 0, n = blobs.Length; i < n; i++) { List <IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]); // does it look like a quadrilateral ? if (shapeChecker.IsQuadrilateral(edgePoints, out corners)) { // get edge points on the left and on the right side List <IntPoint> leftEdgePoints, rightEdgePoints; blobCounter.GetBlobsLeftAndRightEdges(blobs[i], out leftEdgePoints, out rightEdgePoints); listBox1.DataSource = leftEdgePoints; listBox2.DataSource = rightEdgePoints; } } //listBox1.DataSource = corners; //listBox2.DataSource = corners2; this.pictureBox1.Image = temp; break; } case 2: { Bitmap bt2 = new Bitmap(@"D:\TCL条码\截图01.bmp"); Bitmap bt1 = new Bitmap(@"D:\TCL条码\截图03.bmp"); //Bitmap bt1 = new Bitmap(pictureBox2.Image); ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0.80f); //基于一定的相似性阈值获得匹配块 TemplateMatch[] matchings = tm.ProcessImage(bt1, bt2); BitmapData data = bt1.LockBits( new Rectangle(0, 0, bt1.Width, bt1.Height), ImageLockMode.ReadWrite, bt1.PixelFormat); foreach (TemplateMatch m in matchings) { Drawing.Rectangle(data, m.Rectangle, Color.Red); } bt1.UnlockBits(data); pictureBox2.Image = bt1; break; } case 3: { Bitmap bt2 = new Bitmap(@"D:\TCL条码\Canny算法.png"); AForge.Imaging.Filters.BlobsFiltering filter = new AForge.Imaging.Filters.BlobsFiltering(); // 设置过滤条件(对象长、宽至少为70) filter.CoupledSizeFiltering = true; filter.MaxWidth = (int)numericUpDown3.Value; filter.MaxHeight = (int)numericUpDown4.Value; filter.MinWidth = (int)numericUpDown5.Value; filter.MinHeight = (int)numericUpDown6.Value; filter.ApplyInPlace(bt2); pictureBox1.Image = bt2; byte[] RESULT = BitmapToBytes(bt2); break; } case 4: { Bitmap temp = (Bitmap)pictureBox1.Image; temp = new Grayscale(0.2125, 0.7154, 0.0721).Apply(temp); AForge.Imaging.Filters.CannyEdgeDetector filter = new AForge.Imaging.Filters.CannyEdgeDetector(); filter.ApplyInPlace(temp); pictureBox2.Image = temp; break; } } button2.Text = "处理"; }