/// <summary> /// Get rectangle contain object in current frame /// </summary> /// <param name="templateInfo">Tracking template information</param> /// <param name="source">Frame</param> /// <returns>Rectangle contain object</returns> public static Rectangle TemplateColorTracking(ImageStatistics templateInfo, ref UnmanagedImage source) { UnmanagedImage image = source.Clone(); // create filter EuclideanColorFiltering filter = new EuclideanColorFiltering(); // set center colol and radius filter.CenterColor = new RGB( (byte)templateInfo.Red.Mean, (byte)templateInfo.Green.Mean, (byte)templateInfo.Blue.Mean); filter.Radius = 30; // apply the filter filter.ApplyInPlace(image); image = Grayscale.CommonAlgorithms.BT709.Apply(image); OtsuThreshold threshold = new OtsuThreshold(); threshold.ApplyInPlace(image); BlobCounter blobCounter = new BlobCounter(); blobCounter.ObjectsOrder = ObjectsOrder.Size; blobCounter.ProcessImage(image); Rectangle rect = blobCounter.ObjectsCount > 0 ? blobCounter.GetObjectsRectangles()[0] : Rectangle.Empty; return rect; }
void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs) { Icon newIcon = new Icon(@"c:\users\gregster\documents\visual studio 2012\Projects\WebCamTrack\WebCamTrack\bin\Debug\favicon.ico"); BlobCounter bc = new BlobCounter(); EuclideanColorFiltering filter = new EuclideanColorFiltering(); Bitmap video = (Bitmap)eventArgs.Frame.Clone();//sem filtro Bitmap video1 = (Bitmap)eventArgs.Frame.Clone();// imagem com filtro // filter.CenterColor = new RGB(0, 0, 0); filter.Radius = 100; filter.ApplyInPlace(video1);//aplicando o filtro bc.MinWidth = 5; bc.MinHeight = 5; bc.FilterBlobs = true; // bc.ObjectsOrder = ObjectsOrder.Size; bc.ProcessImage(video1);// processando a imagem que ja foi filtrada para identificar objetos Rectangle[] rects = bc.GetObjectsRectangles(); foreach (Rectangle recs in rects) if (rects.Length > 0) { Rectangle objectRect = rects[0]; Graphics g = Graphics.FromImage(video);//identificar objetos a partir da imagem com filtro Graphics h = Graphics.FromImage(video1); using (Pen pen = new Pen(Color.FromArgb(160, 255, 160), 5)) { g.DrawIcon(newIcon, objectRect); // g.DrawRectangle(pen, objectRect); h.DrawRectangle(pen, objectRect); } g.Dispose(); h.Dispose(); } pictureBox1.Image = video; pictureBox2.Image = video1; }
public static void EuclideanColorFiltering(this Bitmap image) { AForge.Imaging.Filters.EuclideanColorFiltering filter = new AForge.Imaging.Filters.EuclideanColorFiltering(); // set center colol and radius filter.CenterColor = Color.FromArgb(FilterColor.ToArgb()); filter.Radius = (short)Range; filter.ApplyInPlace(image); }
private void Sec_Click(object sender, AForge.Video.NewFrameEventArgs eventArgs) { Bitmap image = (Bitmap)eventArgs.Frame.Clone(); Bitmap image1 = (Bitmap)eventArgs.Frame.Clone(); pictureBox1.Image = image; Sec.Enabled = true; if (true) { AForge.Imaging.Filters.EuclideanColorFiltering filter = new AForge.Imaging.Filters.EuclideanColorFiltering(); filter.CenterColor = new AForge.Imaging.RGB(Color.FromArgb(215, 0, 0)); filter.Radius = 100; filter.ApplyInPlace(image1); nesnebul(image1); } }
public static Bitmap ApplyFilters(Bitmap image) { if (cSet) { // create filter EuclideanColorFiltering filter = new EuclideanColorFiltering(); // set center colol and radius filter.CenterColor = new AForge.Imaging.RGB(oColor); filter.Radius = 40; // apply the filter filter.ApplyInPlace(image); } image.RotateFlip(RotateFlipType.RotateNoneFlipX); return image; }
// ========================================================= private void KillColor_Func(ref Bitmap frame, int par_int, double par_d, int par_R, int par_G, int par_B) { // create MirrFilter EuclideanColorFiltering filter = new EuclideanColorFiltering(); // set center colol and radius filter.CenterColor = new RGB((byte)par_R, (byte)par_G, (byte)par_B); filter.Radius = (short)par_int; filter.FillOutside = false; // apply the MirrFilter filter.ApplyInPlace(frame); }
public Bitmap ProcessFrame(Bitmap frame) { var filter = new EuclideanColorFiltering(); _color = new RGB(GlobalVar.Red, GlobalVar.Blue, GlobalVar.Green); filter.CenterColor = _color; filter.Radius = 20; filter.ApplyInPlace(frame); //var filter = new Grayscale(0.2125, 0.7154, 0.0721); //var thresh = new Threshold(thresh_val); //frame = filter.Apply(frame); //thresh.ApplyInPlace(frame); bc.ProcessImage(frame); Rectangle[] rects = bc.GetObjectsRectangles(); if (rects.Length > 0) { AForge.Point closest = new AForge.Point(100000, 100000); foreach (var r in rects) { var p = new AForge.Point(r.Left + r.Width / 2, r.Top + r.Height / 2); var d2 = center.SquaredDistanceTo(closest); var d1 = center.SquaredDistanceTo(p); if (d1 < d2) { closest = p; } } var closestDistance = center.SquaredDistanceTo(closest); var shouldFire = closestDistance < 100; //start firing when close (defualt=20) var delta = closest - center; // _controller.Update(delta.X, delta.Y, shouldFire); GlobalVar.objectX = closest.X; GlobalVar.objectY = closest.Y; //send command to move if (GlobalVar.calibrationMode) { if (GlobalVar.calibrationMoveComplete) { GlobalVar.xRatio = delta.X / 100; //GlobalVar.xRatio = delta.X; if (GlobalVar.xRatio < 0) { GlobalVar.xRatio *= -1; } } else { _controller.Calibrate(); GlobalVar.calibrationMoveComplete = true; } } else { _controller.Update(delta.X, delta.Y, shouldFire); alreadyZeroized = false; } var g = Graphics.FromImage(frame); using (Pen p = new Pen(Color.Red)) { foreach (Rectangle r in rects) { g.DrawRectangle(p, r); g.DrawString("+", new Font("Consolas", 10), Brushes.Red, r.X, r.Y); } } using (Pen p = new Pen(Color.Green)) { g.DrawRectangle(p, closest.X - 2, closest.Y - 2, 5, 5); } GlobalVar.nothingTime = 0; } else { // _controller.Hunt(); GlobalVar.nothingTimerEnabled = true; if (GlobalVar.nothingTime == 150) {//10 = 1 second if (!alreadyZeroized) { _controller.FastZeroize(); alreadyZeroized = true; } } if (GlobalVar.nothingTime == 300) {//10 = 1 second //GlobalVar.nothingTime = 0; _controller.SlowZeroize(); alreadyZeroized = true; GlobalVar.nothingTime = 0; } /* if (GlobalVar.nothingTime == 45) {//10 = 1 second _controller.Hunt(); alreadyZeroized = false; } if (GlobalVar.nothingTime == 55) _controller.Hunt(); if (GlobalVar.nothingTime == 65) _controller.Hunt(); if (GlobalVar.nothingTime == 75) _controller.Hunt(); if (GlobalVar.nothingTime == 85) _controller.Hunt(); if (GlobalVar.nothingTime == 90) { GlobalVar.nothingTime = 0; _controller.Hunt(); } */ } return frame; }
/// <summary> /// The ColorFilter is applied with the ColorRange from the colony. /// </summary> public void FilterImgColonySelect() { // CREATE NEW BITMAP IMAGE this.bitmap = new Bitmap((Bitmap)pictureBox.Image); // LOCK IMAGE this.bitmapData = bitmap.LockBits( new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat); // CREATE NEW FILTER EuclideanColorFiltering filter = new EuclideanColorFiltering(); // SET COLOR RANGE FOR BACKGROUND filter.CenterColor = ColonyColor; filter.Radius = 100; // APPLY FILTER ON IMAGE filter.ApplyInPlace(bitmapData); }
private void TakeSnapshot_funct(Bitmap img) { Bitmap image = Grayscale.CommonAlgorithms.RMY.Apply(img); // find edges SobelEdgeDetector EdgeFilter = new SobelEdgeDetector(); EdgeFilter.ApplyInPlace(image); // back to color format GrayscaleToRGB RGBfilter = new GrayscaleToRGB(); image = RGBfilter.Apply(image); // get rid of grays EuclideanColorFiltering filter = new EuclideanColorFiltering(); filter.CenterColor.Red = 20; filter.CenterColor.Green = 20; filter.CenterColor.Blue = 20; filter.FillOutside = false; filter.Radius = 200; filter.ApplyInPlace(image); Color peek; for (int y = 0; y < image.Height; y++) { for (int x = 0; x < image.Width; x++) { peek = image.GetPixel(x, y); if (peek.R != 0) { image.SetPixel(x, y, Color.Blue); } } } image.MakeTransparent(Color.Black); SnapshotImage = image; SnapshotOriginalImage = image; }
private void Button_Click(object sender, RoutedEventArgs e) { Bitmap image = viewCam.GetCurrentVideoFrame(); ImageStatistics statistics = new ImageStatistics(ObjectExtractorDialog.Value); // create filter EuclideanColorFiltering filter = new EuclideanColorFiltering(); // set center colol and radius filter.CenterColor = new RGB((byte)statistics.Red.Median, (byte)statistics.Green.Median, (byte)statistics.Blue.Median); filter.Radius = 20; // apply the filter filter.ApplyInPlace(image); image = Grayscale.CommonAlgorithms.BT709.Apply(image); Blur blur = new Blur(); blur.ApplyInPlace(image); OtsuThreshold otsu = new OtsuThreshold(); otsu.ApplyInPlace(image); //DifferenceEdgeDetector edgeDetector = new DifferenceEdgeDetector(); //edgeDetector.ApplyInPlace(image); //ColorFiltering colorFilter = new ColorFiltering( // new IntRange(2, 255), // new IntRange(0, 60), // new IntRange(0, 60)); //colorFilter.ApplyInPlace(image); //// create filter //Threshold threshold = new Threshold(100); //// apply the filter //threshold.ApplyInPlace(image); using (image) { BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( image.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); //imgtest.Source = bitmapSource; } }
void FinalVideo_NewFrame2(object sender, NewFrameEventArgs eventArgs) { Icon newIcon = new Icon(@"c:\users\gregster\documents\visual studio 2012\Projects\WebCamTrack\WebCamTrack\bin\Debug\Aqua-Ball-Red-icon.ico"); BlobCounter bc = new BlobCounter(); EuclideanColorFiltering filter = new EuclideanColorFiltering(); Bitmap video = (Bitmap)eventArgs.Frame.Clone();//sem filtro Bitmap video1 = (Bitmap)eventArgs.Frame.Clone();// imagem com filtro // filter.CenterColor = new RGB(10, 10, 10); filter.Radius = 20; filter.ApplyInPlace(video1);//aplicando o filtro bc.MinWidth = 12; bc.MinHeight = 12; bc.FilterBlobs = true; // bc.ObjectsOrder = ObjectsOrder.Size; bc.ProcessImage(video1);// processando a imagem que ja foi filtrada para identificar objetos Rectangle[] rects = bc.GetObjectsRectangles(); foreach (Rectangle recs in rects) if (rects.Length > 0) { foreach (Rectangle objectRect in rects) { Graphics g = Graphics.FromImage(video);//Desenhar quadrado em frente da imagem Graphics i = Graphics.FromImage(video); Graphics h = Graphics.FromImage(video1); if (objectRect.Width < 50 && objectRect.Height < 50) { count = count + 1; } using (Pen pen = new Pen(Color.FromArgb(160, 255, 160), 5)) { g.DrawIcon(newIcon, objectRect); h.DrawRectangle(pen, objectRect); } string strNumber = Convert.ToString(count); // Create font and brush. Font drawFont = new Font("Arial", 16); SolidBrush drawBrush = new SolidBrush(Color.Black); // Create point for upper-left corner of drawing. PointF drawPoint = new PointF(150.0F, 150.0F); // Draw string to screen. i.DrawString(strNumber, drawFont, drawBrush, drawPoint); i.Dispose(); g.Dispose(); h.Dispose(); } } pictureBox1.Image = video; pictureBox2.Image = video1; }