private void videoSourcePlayer1_NewFrame(object sender, ref Bitmap image) { i++; Bitmap objectsImage = null; AForge.Imaging.Filters.EuclideanColorFiltering filter = new AForge.Imaging.Filters.EuclideanColorFiltering(); // set center colol and radius AForge.Imaging.RGB f = new AForge.Imaging.RGB(Color.Red); filter.CenterColor = f;// AForge.Imaging.RGB..Blue; filter.Radius = (short)100; // apply the filter objectsImage = image; filter.ApplyInPlace(image); // lock image for further processing System.Drawing.Imaging.BitmapData objectsData = objectsImage.LockBits(new Rectangle(0, 0, image.Width, image.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, image.PixelFormat); // AForge.Imaging.Filters.Grayscale. // grayscaling AForge.Imaging.UnmanagedImage grayImage = AForge.Imaging.Filters.Grayscale.CommonAlgorithms.BT709.Apply(new AForge.Imaging.UnmanagedImage(objectsData)); // unlock image objectsImage.UnlockBits(objectsData); AForge.Imaging.BlobCounter blobCounter = new AForge.Imaging.BlobCounter(); // locate blobs // blobCounter.MinHeight = 100; // blobCounter.MinWidth = 60; blobCounter.ProcessImage(grayImage); blobCounter.ObjectsOrder = AForge.Imaging.ObjectsOrder.Size; Rectangle[] rects = blobCounter.GetObjectsRectangles(); if (rects.Length > 0) { Rectangle objectRect = rects[0]; // draw rectangle around derected object Graphics g = Graphics.FromImage(image); s = s + "\n" + i + " - top = " + objectRect.Top + " bottom " + objectRect.Bottom + " left " + objectRect.Left + " right " + objectRect.Right + " " + objectRect.X + " " + objectRect.Location.X + " " + objectRect.Location.Y; using (Pen pen = new Pen(Color.FromArgb(160, 255, 160), 5)) { g.DrawRectangle(pen, objectRect); } g.Dispose(); int objectX = objectRect.X + objectRect.Width / 2 - image.Width / 2; int objectY = image.Height / 2 - (objectRect.Y + objectRect.Height / 2); // System.Console.Out. // label1.Text = label1.Text+objectRect.X; // ParameterizedThreadStart t = new ParameterizedThreadStart(p); // Thread aa = new Thread(t); // aa.Start(rects[0]); } Graphics g1 = Graphics.FromImage(image); Pen pen1 = new Pen(Color.FromArgb(160, 255, 160), 3); g1.DrawLine(pen1, image.Width / 2, 0, image.Width / 2, image.Width); g1.DrawLine(pen1, image.Width, image.Height / 2, 0, image.Height / 2); g1.Dispose(); }
/// <summary> /// Takes in black and white binary image and changes white to colour. /// </summary> /// <param name="overBmp">Top binary image (to be coloured).</param> /// <param name="underBmp">Bottom image (to be overlayed).</param> /// <param name="colour">Colour to change the white of the binary image to.</param> /// <returns>Output image with the white of the original binary image overlayed and coloured.</returns> protected Bitmap ApplyColour(Bitmap overBmp, Bitmap underBmp, System.Drawing.Color colour) { Bitmap outImage = ConvertImageFormat(overBmp); AForge.Imaging.Filters.EuclideanColorFiltering filter = new AForge.Imaging.Filters.EuclideanColorFiltering(); filter.CenterColor = new AForge.Imaging.RGB(System.Drawing.Color.White); filter.Radius = 0; filter.FillColor = new AForge.Imaging.RGB(colour); filter.FillOutside = false; filter.ApplyInPlace(outImage); return(outImage); }
private Bitmap ApplyColour(Bitmap overBmp, Bitmap underBmp, System.Drawing.Color colour) { Bitmap newRed = ConvertImageFormat(overBmp); AForge.Imaging.Filters.EuclideanColorFiltering filter = new AForge.Imaging.Filters.EuclideanColorFiltering(); filter.CenterColor = new AForge.Imaging.RGB(System.Drawing.Color.White); //Pure White filter.Radius = 0; //Increase this to allow off-whites filter.FillColor = new AForge.Imaging.RGB(colour); //Replacement Colour filter.FillOutside = false; filter.ApplyInPlace(newRed); //AForge.Imaging.Filters.Merge bfilter = new AForge.Imaging.Filters.Merge(underBmp); //bfilter.Apply(newRed); return newRed; }
/// <summary> /// Takes in black and white binary image and changes white to colour. /// </summary> /// <param name="overBmp">Top binary image (to be coloured).</param> /// <param name="underBmp">Bottom image (to be overlayed).</param> /// <param name="colour">Colour to change the white of the binary image to.</param> /// <returns>Output image with the white of the original binary image overlayed and coloured.</returns> protected Bitmap ApplyColour(Bitmap overBmp, Bitmap underBmp, System.Drawing.Color colour) { Bitmap outImage = ConvertImageFormat(overBmp); AForge.Imaging.Filters.EuclideanColorFiltering filter = new AForge.Imaging.Filters.EuclideanColorFiltering(); filter.CenterColor = new AForge.Imaging.RGB(System.Drawing.Color.White); filter.Radius = 0; filter.FillColor = new AForge.Imaging.RGB(colour); filter.FillOutside = false; filter.ApplyInPlace(outImage); return outImage; }