private void SetPixelleteC(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) { pixeletteFilter.ApplyInPlace(bmpselected); Graphics newImage = Graphics.FromImage(bmp); newImage.DrawImage(bmpselected, SelectedPoints.selectPointForEfX, SelectedPoints.selectPointForEfY, bmpselected.Width, bmpselected.Height); } else if (bmp != null) { try { pixeletteFilter.ApplyInPlace(bmp); } catch { } } Images.Instance.CurrentBitmap = bmp; Images.Instance.NotifyImages(); this.Temporary = bmp; }
int MotionDetection(Bitmap CurrentFrame) { if (PreFrame == null) { PreFrame = GrayFilter.Apply(CurrentFrame); PixFilter.ApplyInPlace(PreFrame); return(0); } Bitmap ProcFrame = GrayFilter.Apply(CurrentFrame); PixFilter.ApplyInPlace(ProcFrame); MoveTowardsFilter.StepSize = 1; MoveTowardsFilter.OverlayImage = ProcFrame; MoveTowardsFilter.ApplyInPlace(PreFrame); DiffFilter.OverlayImage = PreFrame; Bitmap DiffImage = DiffFilter.Apply(ProcFrame); ThreFilter.ApplyInPlace(DiffImage); BlobsFilter.ProcessImage(DiffImage); Blob[] Blobs = BlobsFilter.GetObjectsInformation(); int ret = 0; if (Blobs.Length != 0) { Graphics graph = Graphics.FromImage(CurrentFrame); Pen pen = new Pen(Color.Yellow, 2); graph.DrawRectangle(pen, new Rectangle(3, 3, 10, 10)); foreach (Blob item in Blobs) { if (item.Area > blobArea) { if (ShowMotionCheckBox.Checked) { graph.DrawRectangle(pen, item.Rectangle); } ++ret; } } } videoShowPicBox.Image = CurrentFrame; PreFrame = ProcFrame; return(ret); }
public static void Pixellate(this Bitmap image, Rectangle rec) { Pixellate filter = new Pixellate(); // apply the filter filter.ApplyInPlace(image, rec); }
/// <summary> /// Execute the segmentation process.After the segmentation is over you will /// have a collection of moving objects that were idetified in this frame. /// </summary> /// <param name="frame">The frame.Can not be null.</param> /// <returns> /// A collection of moving objects, i.e. blobs. /// </returns> /// <exception cref="ArgumentNullException">Frame is null.</exception> /// <exception cref="ProcessException">Error while executing the algorithm.</exception> public ICollection <ExtendedBlob> execute(Bitmap frame) { /* * 1. Convert image to grayscale. * 2. Run Difference algorithm. * 3. Use threshold of 40 to turn it into binary frame, why ? see paper * "Moving target classification and tracking from real time video" by Lipton. * 4. Apply connected components algorithm. */ // First time running means no prerior data to compare. if (previousFrame == null) { // create initial backgroung image previousFrame = grayscaleFilter.Apply(frame); // get image dimension width = frame.Width; height = frame.Height; // Return empty list. return(new List <ExtendedBlob>()); } else { // apply the grayscale file Bitmap grayscaledImage = grayscaleFilter.Apply(frame); // set backgroud frame as an overlay for difference filter differenceFilter.OverlayImage = previousFrame; // apply difference filter Bitmap differenceImage = differenceFilter.Apply(grayscaledImage); // lock the temporary image and apply some filters on the locked data bitmapData = differenceImage.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed); // threshold filter thresholdFilter.ApplyInPlace(bitmapData); Bitmap medianImage = medianFilter.Apply(bitmapData); pixelateFilter.ApplyInPlace(medianImage); // unlock temporary image differenceImage.UnlockBits(bitmapData); differenceImage.Dispose(); // Run connected components. List <ExtendedBlob> returnValue = runConectedComponentsAlgorithm(medianImage); // Update users. OnImageChanged(new ImageChangedEventArgs((Image)medianImage.Clone())); // Clean medianImage.Dispose(); // dispose old background previousFrame.Dispose(); // set backgound to current previousFrame = grayscaledImage; return(returnValue); } }