public mCompositeIntersect(Bitmap UnderlayBitmap, Bitmap OverlayBitmap) { BitmapUnder = new mSetFormat(UnderlayBitmap, mFilter.BitmapTypes.Rgb24bpp).ModifiedBitmap; BitmapOver = new mSetFormat(OverlayBitmap, mFilter.BitmapTypes.Rgb24bpp).ModifiedBitmap; ModifiedBitmap = BitmapUnder; Effect = new Intersect(BitmapOver); ModifiedBitmap = Effect.Apply(BitmapUnder); }
public PreProcess(UISettings ui, FileData file) { try { ExtendFileData(file); BitmapOriginal = (ui.WorkDirectory + "\\" + FileName).FileTo24bbpRgb(ResizeRatio: ui.ResizeValue, FrameCrop: ui.CropValue, ImageZoom: 1, RotateDegree: ui.RotateDegree); UnmanagedMarkup = UnmanagedImage.FromManagedImage(BitmapOriginal); ImageStatistics stats = null; Threshold AFbinary = new Threshold(1); Grayscale AFgray = new Grayscale(0.1, 0.7, 0.2); if (ui.ExcludeColorSwitch && ui.ExcludeColorRadius > 0) { System.Windows.Media.Color excolor = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(ui.ExcludeColorHex); EuclideanColorFiltering AFexcolor = new EuclideanColorFiltering(new RGB(excolor.R, excolor.G, excolor.B), (short)ui.ExcludeColorRadius); UnmanagedExclude = AFbinary.Apply(AFgray.Apply(AFexcolor.Apply(UnmanagedMarkup))); } else { UnmanagedExclude = UnmanagedImage.Create(UnmanagedMarkup.Width, UnmanagedMarkup.Height, PixelFormat.Format8bppIndexed); } if (ui.WhiteBalanceSwitch || ui.BlackBalanceSwitch) // need to apply auto white/black balance { Invert AFinvert = new Invert(); stats = new ImageStatistics(UnmanagedMarkup, AFinvert.Apply(UnmanagedExclude)); int lowend = (ui.BlackBalanceSwitch) ? (int)Math.Round(0.333d * (stats.RedWithoutBlack.Center2QuantileValue(ui.BlackBalance) + stats.GreenWithoutBlack.Center2QuantileValue(ui.BlackBalance) + stats.BlueWithoutBlack.Center2QuantileValue(ui.BlackBalance))):0; LevelsLinear levelsLinear = new LevelsLinear { InRed = new IntRange(lowend, (ui.WhiteBalanceSwitch) ? stats.RedWithoutBlack.Center2QuantileValue(ui.WhiteBalance) : 255), InGreen = new IntRange(lowend, (ui.WhiteBalanceSwitch) ? stats.GreenWithoutBlack.Center2QuantileValue(ui.WhiteBalance) : 255), InBlue = new IntRange(lowend, (ui.WhiteBalanceSwitch) ? stats.BlueWithoutBlack.Center2QuantileValue(ui.WhiteBalance) : 255), }; //LevelsLinear levelsLinear = new LevelsLinear { // InRed=new IntRange((ui.BlackBalanceSwitch)?stats.RedWithoutBlack.Center2QuantileValue(ui.BlackBalance):0, (ui.WhiteBalanceSwitch)?stats.RedWithoutBlack.Center2QuantileValue(ui.WhiteBalance):255), // InGreen=new IntRange((ui.BlackBalanceSwitch)?stats.GreenWithoutBlack.Center2QuantileValue(ui.BlackBalance):0, (ui.WhiteBalanceSwitch)?stats.GreenWithoutBlack.Center2QuantileValue(ui.WhiteBalance):255), // InBlue=new IntRange((ui.BlackBalanceSwitch)?stats.BlueWithoutBlack.Center2QuantileValue(ui.BlackBalance):0, (ui.WhiteBalanceSwitch)?stats.BlueWithoutBlack.Center2QuantileValue(ui.WhiteBalance):255), //}; levelsLinear.ApplyInPlace(UnmanagedMarkup); } if (ui.GaussianBlurSwitch && ui.GaussianBlur != 0) // Gaussian Blur and Darken { GaussianBlur AFgblur = new GaussianBlur(11.0, Math.Max(ui.GaussianBlur, 0) * 2 + 1); // Gaussian Blur sigma = 8.0 kernel size = 7 Intersect AFintersect = new Intersect(AFgblur.Apply(UnmanagedMarkup)); UnmanagedMarkup = AFintersect.Apply(UnmanagedMarkup); } UnmanagedGray = AFgray.Apply(UnmanagedMarkup); // directly turn into gray } catch { throw new Exception("Error Occured During PreProcessing"); } }
private Bitmap getThreeFrameDifference(Bitmap frame) { if (lastFrame == null || lastButOneFrame == null) { return(null); } Difference filterPrevious = new Difference(lastButOneFrame); Bitmap differenceBitmapPrevious = filterPrevious.Apply(lastFrame); Difference filterNext = new Difference(lastFrame); Bitmap differenceBitmapNext = filterNext.Apply(frame); Intersect intersectionFilter = new Intersect(differenceBitmapPrevious); Bitmap threeFrameDifferenceBitmap = intersectionFilter.Apply(differenceBitmapNext); return(threeFrameDifferenceBitmap); }
public static Bitmap operationImages(Bitmap img1, Bitmap img2, int op) { img1 = ImageUtil.convert(img1, System.Drawing.Imaging.PixelFormat.Format32bppArgb); img2 = ImageUtil.convert(img2, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Bitmap filteredImage = img1; IFilter myFilter; if (op == Filters.mode["Add"]) { myFilter = new Add(img2); filteredImage = myFilter.Apply(img1); } else if (op == Filters.mode["Subtract"]) { myFilter = new Subtract(img2); filteredImage = myFilter.Apply(img1); } else if (op == Filters.mode["Intersect"]) { myFilter = new Intersect(img2); filteredImage = myFilter.Apply(img1); } else if (op == Filters.mode["Difference"]) { myFilter = new Difference(img2); filteredImage = myFilter.Apply(img1); } else if (op == Filters.mode["Merge"]) { myFilter = new Merge(img2); filteredImage = myFilter.Apply(img1); } else if (op == Filters.mode["Multiply"]) { myFilter = new Multiply(img2); filteredImage = myFilter.Apply(img1); } return(filteredImage); }
private void videoSourcePlayer1_NewFrame(object sender, ref Bitmap image) { Invert inv = new Invert(); inv.ApplyInPlace(image); UnmanagedImage ui = UnmanagedImage.FromManagedImage(image); pictureBox1.Image = image; if (controller.Tracker.TrackingObject == null) { return; } if (controller.Tracker.TrackingObject.IsEmpty) { return; } var rect = controller.Tracker.TrackingObject.Rectangle; Crop crop = new Crop(rect); UnmanagedImage head = crop.Apply(ui); var points = new List <IntPoint>() { new IntPoint(head.Width / 2, head.Height / 2) }; var pps = head.Collect16bppPixelValues(points); double mean = Accord.Statistics.Tools.Mean(pps); double cutoff = mean + 15; Threshold t = new Threshold((int)cutoff); var mask = t.Apply(ui); LevelsLinear16bpp levels = new LevelsLinear16bpp(); levels.InGray = new IntRange((int)cutoff, 65535); levels.OutGray = new IntRange(0, 65535); levels.ApplyInPlace(ui); var mask8bit = AForge.Imaging.Image.Convert16bppTo8bpp(mask.ToManagedImage()); BlobCounter bc = new BlobCounter(); bc.ObjectsOrder = ObjectsOrder.Area; bc.ProcessImage(mask8bit); var blobs = bc.GetObjectsInformation(); inv.ApplyInPlace(image); Intersect intersect = new Intersect(); intersect.UnmanagedOverlayImage = mask; mask = intersect.Apply(ui); List <Rectangle> rects = new List <Rectangle>(); // Extract the uppermost largest blobs. for (int i = 0; i < blobs.Length; i++) { double dx = (blobs[i].Rectangle.Top - controller.Tracker.TrackingObject.Center.Y); double d = (dx * dx) / controller.Tracker.TrackingObject.Area; if (d < 2 && blobs[i].Area > 1000) { rects.Add(blobs[i].Rectangle); } } rects.Sort(compare); if (rects.Count > 0) { captureHand(mask, rects[0], pbLeftArm, pbLeftHand); } if (rects.Count > 1) { captureHand(mask, rects[1], pbRightArm, pbRightHand); } RectanglesMarker marker = new RectanglesMarker(rects); marker.MarkerColor = Color.White; marker.ApplyInPlace(mask8bit); image = mask.ToManagedImage(); }