private Bitmap processImage(Bitmap img) { //Generate closing structural element short[,] structEl = new short[13, 13]; for (int i = 0; i < 13; i++) for (int j = 0; j < 13; j++) if ((i - 6) * (i - 6) + (j - 6) * (j - 6) < 64) structEl[i, j] = 1; else structEl[i, j] = -1; //Initialize filters HSLFiltering borderFind = new HSLFiltering(); Closing borderClose = new Closing(structEl); Invert invert = new Invert(); Grayscale grayFilter = new Grayscale(0, 0, 1.0); Threshold bwFilter = new Threshold(1); PointedColorFloodFill blackout = new PointedColorFloodFill(); blackout.Tolerance = Color.FromArgb(0, 0, 0); blackout.FillColor = Color.FromArgb(0, 0, 0); ExtractBiggestBlob getgame = new ExtractBiggestBlob(); getgame.OriginalImage = new Bitmap(img); GrayscaleToRGB colorFilter = new GrayscaleToRGB(); //Color determined with ColorProbe. borderFind.Hue = new IntRange(190, 200); borderFind.Saturation = new Range(0.6f, 0.8f); borderFind.Luminance = new Range(0.6f, 1.0f); borderFind.ApplyInPlace(img); borderClose.ApplyInPlace(img); img = grayFilter.Apply(img); bwFilter.ApplyInPlace(img); invert.ApplyInPlace(img); img = colorFilter.Apply(img); blackout.StartingPoint = new AForge.IntPoint(0, 0); blackout.ApplyInPlace(img); img = getgame.Apply(img); int tilesx = img.Width / 56; int tilesy = img.Height / 56; int offsetx = 56 * (int)(tilesx - img.Width / 56.0); int offsety = 56 * (int)(tilesy - img.Height / 56.0); if ((Math.Abs(offsetx) > 11) || (Math.Abs(offsety) > 11)) throw new GameNotFoundException(); List<IntPoint> corners = new List<IntPoint>(); Dictionary<IntPoint, Bitmap> tiles = new Dictionary<IntPoint, Bitmap>(); SimpleQuadrilateralTransformation tileXtract = new SimpleQuadrilateralTransformation(); for (int j = 0; j < tilesy; j++) for (int i = 0; i < tilesx; i++) { corners.Add(new IntPoint(offsetx + i * 56, offsety + j * 56 )); corners.Add(new IntPoint(offsetx + i * 56, offsety + (j + 1) * 56 - 1)); corners.Add(new IntPoint(offsetx + (i + 1) * 56 - 1, offsety + (j + 1) * 56 - 1)); corners.Add(new IntPoint(offsetx + (i + 1) * 56 - 1, offsety + j * 56 )); tileXtract.SourceQuadrilateral = corners; tiles.Add(new IntPoint(i, j), tileXtract.Apply(img)); corners.Clear(); } img = (Bitmap)Properties.Resources.ResourceManager.GetObject("cb"); /*Graphics g = Graphics.FromImage(img); Pen bluePen = new Pen(Color.Blue, 2); for (int i = 0, n = blobs.Length; i < n; i++) { List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]); if (edgePoints.Count > 1) { List<IntPoint> corners = PointsCloud.FindQuadrilateralCorners(edgePoints); g.DrawPolygon(bluePen, ToPointsArray(corners)); } } bluePen.Dispose(); g.Dispose(); */ return img; }
//functions public void process(Bitmap image) { while (true) { ProcessImage.Notifier.WaitOne(); foreach (Bitmap _image in queue.GetConsumingEnumerable())//it will block here automatically waiting from new items to be added and it will not take cpu down { //Red HSLFiltering redFilter = new HSLFiltering(new IntRange(345, 15), new Range(0.400f, 1.0f), new Range(0.15f, 1.0f)); HSLFiltering yellowFilter = new HSLFiltering(new IntRange(345, 15), new Range(0.400f, 1.0f), new Range(0.15f, 1.0f)); HSLFiltering whiteFilter = new HSLFiltering(new IntRange(345, 15), new Range(0.400f, 1.0f), new Range(0.15f, 1.0f)); HSLFiltering greenFilter = new HSLFiltering(new IntRange(345, 15), new Range(0.400f, 1.0f), new Range(0.15f, 1.0f)); HSLFiltering blueFilter = new HSLFiltering(new IntRange(345, 15), new Range(0.400f, 1.0f), new Range(0.15f, 1.0f)); redFilter.FillOutsideRange = true; greenFilter.FillOutsideRange = true; blueFilter.FillOutsideRange = true; whiteFilter.FillOutsideRange = true; yellowFilter.FillOutsideRange = true; redFilter.ApplyInPlace(_image); blueFilter.ApplyInPlace(_image); greenFilter.ApplyInPlace(_image); yellowFilter.ApplyInPlace(_image); whiteFilter.ApplyInPlace(_image); FeatureExtracting.queue.Add(_image); FeatureExtracting.Notifier.Set(); } } }
public static void inkFilter() { HSLFiltering filter = new HSLFiltering(); filter.FillOutsideRange = false; filter.FillColor = fillColor; filter.Hue = filterHue; filter.Saturation = filterSat; filter.Luminance = filterLig; filter.ApplyInPlace(img); }
public static void Hsl_Setter(Bitmap video, int minHue, int maxHue, float minSat, float maxSat, float minLum, float maxLum) { //Create color filter HSLFiltering HslFilter = new HSLFiltering(); //configre the filter HslFilter.Hue = new IntRange(minHue, maxHue); HslFilter.Saturation = new Range(minSat, maxSat); HslFilter.Luminance = new Range(minLum, maxLum); //apply color filter to the image HslFilter.ApplyInPlace(video); }
// set color ranges to keep public FrameProcessor(LaserController controller) { _controller = controller; var min_size_val = 4; bc = new BlobCounter(); bc.FilterBlobs = true; bc.MinHeight = min_size_val; bc.MinWidth = min_size_val; bc.MaxHeight = min_size_val + 50; bc.MaxWidth = min_size_val + 50; AForge.Imaging.Filters.HSLFiltering hslFilter = new AForge.Imaging.Filters.HSLFiltering(); }
public FieldInterface() { InitializeComponent(); savedDir = new DirectoryInfo("Saved"); if (!savedDir.Exists) { savedDir.Create(); } processor = new ImageProcessor(); camera = new CameraHandler(this); filter = new HSLFiltering(); camera.SetStream("http://10.6.19.11/mjpg/video.mjpg"); camera.Start(); }
public void FilterChanged() { HSLFiltering newFilter = new HSLFiltering(); newFilter.Hue = new IntRange((int)hueMinInput.Value, (int)hueMaxInput.Value); newFilter.Saturation = new Range((float)satMinInput.Value / 100f, (float)satMaxInput.Value / 100f); newFilter.Luminance = new Range((float)lumMinInput.Value / 100f, (float)lumMaxInput.Value / 100f); filter = newFilter; //if (camera == null || !camera.Running) //{ // processor.SetFilter(filter); // UpdateDisplays(false); //} //else //{ // processor.SetFilter(filter, false); //} }
protected Bitmap[] colourFilter(Bitmap image) { HSLFiltering filt = new HSLFiltering(); filt.FillOutsideRange = true; FilteredImage = new Bitmap[4]; for (int i = 0; i < 4; i++) { switch (i) { case RED: filt.Hue = new IntRange(345, 15); filt.Saturation = new Range(0.4f, 1.0f); filt.Luminance = new Range(0.15f, 1.0f); FilteredImage[RED] = filt.Apply(image); break; case GREEN: filt.Hue = new IntRange(90, 115); filt.Saturation = new Range(0.3f, 1.0f); filt.Luminance = new Range(0.15f, 0.9f); FilteredImage[GREEN] = filt.Apply(image); break; case YELLOW: filt.Hue = new IntRange(25, 80); filt.Saturation = new Range(0.2f, 0.9f); filt.Luminance = new Range(0.25f, 0.8f); FilteredImage[YELLOW] = filt.Apply(image); break; case BLUE: filt.Hue = new IntRange(180, 240); filt.Saturation = new Range(0.1f, 1.0f); filt.Luminance = new Range(0.1f, 0.7f); FilteredImage[BLUE] = filt.Apply(image); break; } } //UpdateVideo(image); return FilteredImage; }
/// <summary> /// Filter the image froma HSV colour range /// </summary> /// <param name="image">Bitmap Image, any suitable image</param> /// <returns>Bitmap Image</returns> public Bitmap addFilters(Bitmap image) { //Instantiate new HSL filter AForge.Imaging.Filters.HSLFiltering hslFilter = new AForge.Imaging.Filters.HSLFiltering(); //Define HSL colour range (default colour is orange) hslFilter.Hue = new AForge.IntRange(0, 50); hslFilter.Saturation = new AForge.DoubleRange(0.7, 1); hslFilter.Luminance = new AForge.DoubleRange(0.2, 0.7); //Instantiate new RGB filter /*AForge.Imaging.Filters.ColorFiltering rgbFilter = new AForge.Imaging.Filters.ColorFiltering(); //Define RGB colour range (default colour is orange) rgbFilter.Red = new AForge.IntRange(60, 180); rgbFilter.Green = new AForge.IntRange(10, 80); rgbFilter.Blue = new AForge.IntRange(5, 25);*/ //Apply the HSL filter to the input image hslFilter.ApplyInPlace(image); //Create a 5 by 5 matrix using a short array int rows = 5; int cols = 5; short[,] Matrix = new short[rows, cols]; for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) Matrix[i, j] = 1; //Instantiate new dilate filter with the 5 by 5 matrix AForge.Imaging.Filters.Dilatation dilate = new AForge.Imaging.Filters.Dilatation(Matrix); //Apply the filter dilate.ApplyInPlace(image); return image; }
/// <summary> /// Initializes a new instance of the <see cref="HslBlobTracker"/> class. /// </summary> /// <param name="filter">The filter.</param> public HslBlobTracker(HSLFiltering filter) { this.filter = filter; this.blobCounter = new BlobCounter(); this.trackingObject = new TrackingObject(); blobCounter.CoupledSizeFiltering = false; blobCounter.FilterBlobs = true; }
public void addcouleur(Bitmap bm) { if (LstZone.Count == 0 || LstZone[LstZone.Count - 1].ID != -1 && col !=null) { int w_i = bm.Width; int h_i = bm.Height; int w_c = imgReel.Width; int h_c = imgReel.Height; float ord = ((float)w_i * (float)((float)this.col[0] / (float)w_c)); float abs = ((float)h_i * (float)((float)this.col[1] / (float)h_c)); this.col = null; int R = 0, G = 0 , B = 0, A = 0; int count = 0; // Moyenne des pixels for (int i = (int)(ord - 1); i < (int)(ord + 1); i++) { for (int j = (int)(abs - 1); j < (int)(abs + 1); j++) { count++; Color c = bm.GetPixel(i,j); R += c.R; G += c.G; B += c.B; A += c.A; } } RGB tmp = new RGB(((byte)(R / count)), ((byte)(G / count)), ((byte)(B / count)), ((byte)(A / count))); HSL colo = HSL.FromRGB(tmp); Logger.GlobalLogger.debug("Couleur ajoutée : " + tmp.ToString() + " HLS : " + colo.Hue + " " + colo.Luminance + " " + colo.Saturation); HSLFiltering Filter = new HSLFiltering(); Filter.Hue = new IntRange((colo.Hue + 340) % 360, (colo.Hue + 20) % 360); Filter.Saturation = new Range(0.6f, 1f); Filter.Luminance = new Range(0.1f, 1f); LstHslFiltering.Add(Filter); PositionZone ZoneTmp = new PositionZone(); ZoneTmp.ID = -1; LstZone.Add(ZoneTmp); MessageBox.Show("Ajouter une zone de dépose avec le click milieu"); } }
private Bitmap hslImage(String path) { try { Bitmap image = new Bitmap(path); HSLFiltering filter = new HSLFiltering(); //filter.Hue = new AForge.IntRange(335,0); filter.UpdateHue = false; filter.Luminance = new AForge.Range(0.4f, 1); filter.Saturation = new AForge.Range(0.6f, 1); image = filter.Apply(image); return image; } catch (Exception ex) { throw new Exception("Deu erro na conversão"); } }
private IFilter GenerateFilters() { FiltersSequence filters = new FiltersSequence(); foreach (TreeNode node in treeLayers.Nodes) { if (node.Level == 0 && node.Checked) { foreach (TreeNode child in node.Nodes) { if (child.Checked) { HSLFiltering local_filter = new HSLFiltering(((LayerColor)child.Tag).hue_range, ((LayerColor)child.Tag).sat_range, ((LayerColor)child.Tag).lum_range); local_filter.FillColor = ((LayerProperties)node.Tag).HSLReplacementColor; local_filter.FillOutsideRange = false; filters.Add(local_filter); } } } } return filters; }
void sensor_AllFramesReady(object sender, Microsoft.Kinect.AllFramesReadyEventArgs e) { if(this.command == "Stop") { Bot.stop(); } if(this.command == "Forward") { Bot.traverse(); } if (this.command == "Right") { Bot.turnRight(); } if (this.command == "Left") { Bot.turnRight(); } xf++; if (xf % 5 == 0) { xf = 0; if (this.command != null) { using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) { using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { humanPosition = frameToHuman(skeletonFrame); if (colorFrame != null) { // Copy the pixel data from the image to a temporary array colorFrame.CopyPixelDataTo(this.colorPixels); // Write the pixel data into our bitmap this.colorBitmap.WritePixels( new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight), this.colorPixels, this.colorBitmap.PixelWidth * sizeof(int), 0); // Error here due to OpenCV_core290.dll //int[] objPos = new int[2]; //objPos = tmp.matchColor(ImageProc.colorFrameToImage(colorFrame)); //if (objPos != null) //{ // short blobDepth = getDepthAtPoint(objPos, depthFrame); // this.lblObject.Content = objPos[0] + ", " + objPos[1] + ", " + blobDepth; //} //else //{ // this.lblObject.Content = "Null"; //} System.Drawing.Bitmap bmp = ImageProc.colorFrameToAforge(colorFrame); HSLFiltering filter = new HSLFiltering(); // set color ranges to keep if (objec[0] == -1) { if (command == "Fetching Bottle") { filter.Hue = bottleH; filter.Saturation = bottleS; filter.Luminance = bottleL; } else if (command == "Fetching Box") { filter.Hue = boxH; filter.Saturation = boxS; filter.Luminance = boxL; } //// apply the filter filter.ApplyInPlace(bmp); BlobCounter blobCounter = new BlobCounter(bmp); int i = blobCounter.ObjectsCount; ExtractBiggestBlob fil = new ExtractBiggestBlob(); int[] pp = new int[2]; pp[0] = 0; pp[1] = 0; int h = 0; if (i > 0) { fil.Apply(bmp); pp[0] = fil.BlobPosition.X; pp[1] = fil.BlobPosition.Y; h = fil.Apply(bmp).Height; } short blobDepth = getDepthAtPoint(pp, depthFrame); this.lblObject.Content = pp[0] + ", " + pp[1] + ", " + blobDepth; this.objec[0] = pp[0]; this.objec[1] = pp[1]; this.objec[2] = blobDepth; } else { filter.Hue = botH; filter.Saturation = botS; filter.Luminance = botL; filter.ApplyInPlace(bmp); BlobCounter blobCounter = new BlobCounter(bmp); int i = blobCounter.ObjectsCount; ExtractBiggestBlob fil = new ExtractBiggestBlob(); int[] pp = new int[2]; pp[0] = 0; pp[1] = 0; int h = 0; if (i > 0) { fil.Apply(bmp); pp[0] = fil.BlobPosition.X; pp[1] = fil.BlobPosition.Y; h = fil.Apply(bmp).Height; } short blobDepth = getDepthAtPoint(pp, depthFrame); this.lblBot.Content = pp[0] + ", " + pp[1] + ", " + blobDepth; this.bot[0] = pp[0]; this.bot[1] = pp[1]; this.bot[2] = blobDepth; } //Assign Manual Position to bot and object } if (humanPosition != null) { this.lblHuman.Content = humanPosition[0] + ", " + humanPosition[1] + ", " + humanPosition[2]; } else { this.lblHuman.Content = "No Human detected"; } if (this.path == 0) { if (humanPosition != null) { if (Bot.moveDoraemon(this.bot[0], this.humanPosition[0], this.bot[2], this.humanPosition[2]) == 0) { this.path = 1; } } } else { if (Bot.moveDoraemon(this.bot[0], this.objec[0], this.bot[2], this.objec[2]) == 0) { Bot.stop(); } } } } } this.lbl.Content = command; } } }
/// <summary> /// /// </summary> /// <param name="img"></param> /// <returns></returns> public GameLogic ScrapeBoardFromImage(Bitmap img) { // filter board's color to better identify tiles Blur blur = new Blur(); blur.Threshold = 1; blur.ApplyInPlace(img); BrightnessCorrection brightness_filter = new BrightnessCorrection(-30); brightness_filter.ApplyInPlace(img); HSLFiltering luminance_filter = new HSLFiltering(); luminance_filter.Luminance = new Range(0.50f, 1); luminance_filter.ApplyInPlace(img); img.Save("c:\\users\\breiche\\pictures\\filtered.bmp", ImageFormat.Bmp); DetectBlobsInImage(img); img.Save("c:\\users\\breiche\\pictures\\blobs.bmp", ImageFormat.Bmp); return new GameLogic(0, 0); }
public void Process(Bitmap bmp, HSLFiltering filter = null, Bitmap copy = null) { if (bmp == null) { return; } Original = bmp; if (Original == null) { return; } Bitmap previous = Filtered; if (copy != null) { Filtered = (Bitmap)Original.Clone(); } else { Filtered = copy; } if (previous != null) { previous.Dispose(); } if (filter != null) { filter.ApplyInPlace(Filtered); } processData(); }
//eventhandler if new frame is ready private void video_NewFrame(object sender, NewFrameEventArgs eventArgs) { Bitmap img = (Bitmap)eventArgs.Frame.Clone(); if (counterImg == 10) { double delaisImage = DateTime.Now.TimeOfDay.TotalMilliseconds - _mill_last_pic; _mill_last_pic = DateTime.Now.TimeOfDay.TotalMilliseconds; double FPS = 1 / delaisImage * 1000 * counterImg + 1; // txt_nb_fps.Text = FPS.ToString() ; //txt_resolution.Text = "" + videoSource.DesiredFrameSize.Height + " * " + videoSource.DesiredFrameSize.Width; string resolutionTxt = "" + img.Width + " * " + img.Height; if (this != null && (!this.IsDisposed)) { try { this.Invoke((ProcessNewFPS)UpdateNewFPS, FPS); this.Invoke((ProcessNewResolution)UpdateNewResolution, resolutionTxt); } catch (ObjectDisposedException) // La fenetre était en train de se fermée { } } counterImg = 0; } counterImg++; //Rectangle rect = new Rectangle(0,0,eventArgs.Frame.Width,eventArgs.Frame.Height); // 1 - grayscaling UnmanagedImage image = UnmanagedImage.FromManagedImage(img); UnmanagedImage imageRouge = image.Clone(); UnmanagedImage imageBleu = image.Clone(); UnmanagedImage imageVert = image.Clone(); UnmanagedImage grayImage = null; Color colorPoint = image.GetPixel(posX, posY); this.Invoke((ProcessLalbelText)ChangeLabelText, new object[] { colorPoint.GetHue().ToString(), lbl_hue }); this.Invoke((ProcessLalbelText)ChangeLabelText, new object[] { colorPoint.GetBrightness().ToString(), lbl_lum }); this.Invoke((ProcessLalbelText)ChangeLabelText, new object[] { colorPoint.GetSaturation().ToString(), lbl_sat }); if (image.PixelFormat == PixelFormat.Format8bppIndexed) { grayImage = image; } else { grayImage = UnmanagedImage.Create(image.Width, image.Height, PixelFormat.Format8bppIndexed); Grayscale.CommonAlgorithms.BT709.Apply(image, grayImage); } // 2 - Edge detection DifferenceEdgeDetector edgeDetector = new DifferenceEdgeDetector(); UnmanagedImage edgesImage = edgeDetector.Apply(grayImage); // 3 - Threshold edges Threshold thresholdFilterGlyph = new Threshold((short)numericUpDown3.Value); Threshold thresholdFilterCouleur = new Threshold((short)numericUpDown2.Value); thresholdFilterGlyph.ApplyInPlace(edgesImage); /* * * Bitmap image = (Bitmap)eventArgs.Frame.Clone(); //Reference : http://www.aforgenet.com/framework/docs/html/743311a9-6c27-972d-39d2-ddc383dd1dd4.htm * private HSLFiltering filter = new HSLFiltering(); // set color ranges to keep red-orange filter.Hue = new IntRange(0, 20); filter.Saturation = new DoubleRange(0.5, 1); // apply the filter filter.ApplyInPlace(image); * */ /*RGB colorRed = new RGB(215, 30, 30); RGB colorBlue = new RGB(10, 10, 215); RGB colorVert = new RGB(30, 215, 30); RGB colorBlanc = new RGB(225, 219, 160);*/ HSLFiltering filter = new HSLFiltering(); // create filter // EuclideanColorFiltering filter = new EuclideanColorFiltering(); //filter.Radius = (short)numericUpDown1.Value; filter.Hue = new IntRange(40, 140); filter.Saturation = new Range(0.5f, 1.0f); filter.Luminance = new Range(0.2f, 1.0f); //filter.CenterColor = colorRed; filter.ApplyInPlace(imageRouge); filter.Hue = new IntRange(100, 180); //filter.CenterColor = colorBlanc; filter.ApplyInPlace(imageVert); filter.Hue = new IntRange(0, 40); //filter.CenterColor = colorBlue; filter.ApplyInPlace(imageBleu); Grayscale filterRouge = new Grayscale(0.800, 0.200, 0.200); Grayscale filterVert = new Grayscale(0.200, 0.800, 0.200); Grayscale filterBleu = new Grayscale(0.200, 0.200, 0.800); UnmanagedImage grayRougeImage = filterRouge.Apply(imageRouge); UnmanagedImage grayBleuImage = filterBleu.Apply(imageBleu); UnmanagedImage edgesRougeImage = edgeDetector.Apply(grayRougeImage); UnmanagedImage edgesBleuImage = edgeDetector.Apply(grayBleuImage); thresholdFilterCouleur.ApplyInPlace(edgesRougeImage); thresholdFilterCouleur.ApplyInPlace(edgesBleuImage); // All the image processing is done here... // pictureBox1.Image = image.ToManagedImage(); if (this != null && (!this.IsDisposed)) // Si on est pas en train de suppirmer la fenetre { try { this.Invoke((ProcessNewImage)DisplayNewImage, new object[] { image, pic_ImageNormal }); this.Invoke((ProcessNewImage)DisplayNewImage, new object[] { edgesImage, pic_ImageEdge }); this.Invoke((ProcessNewImage)DisplayNewImage, new object[] { imageRouge, pic_ImageRouge }); this.Invoke((ProcessNewImage)DisplayNewImage, new object[] { imageBleu, pic_ImageBleu }); this.Invoke((ProcessNewImage)DisplayNewImage, new object[] { imageVert, pic_ImageVert }); } catch (ObjectDisposedException) // La fenetre était en train de se fermée { } } /*pictureBox2.Image = grayImage.ToManagedImage(); pictureBox3.Image = edgesImage.ToManagedImage(); pictureBox4.Image = imageRouge.ToManagedImage();*/ }
public void FilterChanged() { lock (_sync) { _filter = null; } }
private void FillPictureBoxes(ref Bitmap image) { Bitmap tmpImg = image; Bitmap tmpImg2 = image; try { bool hasFilter = false; //setup resize and filtersequesce //resize img to fit picturebox ResizeBicubic resizeFilter = new ResizeBicubic(0, 0); resizeFilter = new ResizeBicubic(pbCapture.Width, pbCapture.Height); tmpImg = resizeFilter.Apply(tmpImg); resizeFilter = new ResizeBicubic(pbShapes.Width, pbShapes.Height); tmpImg2 = resizeFilter.Apply(tmpImg2); FiltersSequence processingFilter = new FiltersSequence(); //List all filters IFilter ConservativeSmoothingFilter = new AForge.Imaging.Filters.ConservativeSmoothing(); IFilter InvertFilter = new AForge.Imaging.Filters.Invert(); IFilter HSLFilteringFilter = new AForge.Imaging.Filters.HSLFiltering(); IFilter SepiaFilter = new AForge.Imaging.Filters.Sepia(); IFilter grayscaleFilter = new AForge.Imaging.Filters.GrayscaleBT709(); IFilter SkeletonizationFilter = new AForge.Imaging.Filters.SimpleSkeletonization(); IFilter pixFilter = new AForge.Imaging.Filters.Pixellate(); ////apply filter and process img--------------------------------------------- if (ConservativeSmoothing) { processingFilter.Add(ConservativeSmoothingFilter); hasFilter = true; } if (Invert) { processingFilter.Add(InvertFilter); hasFilter = true; } if (HSLswitch) { processingFilter.Add(HSLFilteringFilter); hasFilter = true; } if (sepiaSwitch) { processingFilter.Add(SepiaFilter); hasFilter = true; } if (Skeletonization) { processingFilter.Add(grayscaleFilter); processingFilter.Add(SkeletonizationFilter); hasFilter = true; } //apply the filter(s) to image if (hasFilter) { //tmpImg = processingFilter.Apply(tmpImg); tmpImg2 = processingFilter.Apply(tmpImg2); } processingFilter.Clear(); if (bwSwitch) { switchBandW(ref tmpImg); } if (CannyEdgeDetector) { // create filter CannyEdgeDetector filter = new CannyEdgeDetector(); // apply the filter tmpImg = Grayscale.CommonAlgorithms.BT709.Apply(tmpImg); filter.ApplyInPlace(tmpImg); // image = DrawFocusArea(gsImage); } else { // image = DrawFocusArea(image); } if (DifferenceEdgeDetector) { DifferenceEdgeDetector dFilter = new DifferenceEdgeDetector(); // apply the filter tmpImg = Grayscale.CommonAlgorithms.BT709.Apply(tmpImg); dFilter.ApplyInPlace(tmpImg); } if (HomogenityEdgeDetector) { HomogenityEdgeDetector hFilter = new HomogenityEdgeDetector(); // apply the filter tmpImg = Grayscale.CommonAlgorithms.BT709.Apply(tmpImg); hFilter.ApplyInPlace(tmpImg); } if (SobelEdgeDetector) { SobelEdgeDetector hFilter = new SobelEdgeDetector(); // apply the filter tmpImg = Grayscale.CommonAlgorithms.BT709.Apply(tmpImg); hFilter.ApplyInPlace(tmpImg); BlobCounter bc = new BlobCounter(tmpImg); Rectangle[] brecs = bc.GetObjectsRectangles(); //Graphics pg = Graphics.FromImage(tmpImg); //Pen p = new Pen(Color.White, 2); //foreach (Rectangle r in brecs) //{ // pg.DrawRectangle(p, r); //} } if (findShapes) { tmpImg = FindShapes(tmpImg, ref tmpImg2); //ProcessImage(image); } else { pbCapture.Image = tmpImg; //set picturebox image---------------- pbShapes.Image = tmpImg2; //set picturebox image---------------- } // Graphics g = Graphics.FromImage(tmpImg); // Pen p = new Pen(Color.Red, 2); // Rectangle lr = new Rectangle(100, 120, 80, 40); //// Rectangle rr = new Rectangle(360, 220, 80, 40); // g.DrawRectangle(p, lr); // //g.DrawRectangle(p, rr); } catch (Exception ex) { MessageBox.Show(ex.Message); } // pbCapture.Image = tmpImg;//set picturebox image---------------- // pbShapes.Image = tmpImg2;//set picturebox image---------------- }