Good morning,
So i was finally able to solve all the errors in my game, but now i can't seem to get a Motion Detector to work using Aforge, so far i've got:
private void device_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
{
tmpImage = eventArgs.Frame.Clone(Rec, PixelFormat.Format24bppRgb);
Bitmap image = (Bitmap)tmpImage.Clone();
//BitmapData bitmapData = image.LockBits( new System.Drawing.Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite, image.PixelFormat);
//BlobCounter blobCounter = new BlobCounter();
//blobCounter.FilterBlobs = true;
//blobCounter.MinHeight = 5;
//blobCounter.MinWidth = 5;
////blobCounter.ProcessImage(bitmapData);
////Blob[] blobs = blobCounter.GetObjectsInformation();
//image.UnlockBits(bitmapData);
//Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
Threshold filter2 = new Threshold(200);
Invert invert = new Invert();
Bitmap grayImage = Grayscale.CommonAlgorithms.BT709.Apply(image);
invert.ApplyInPlace(grayImage);
filter2.ApplyInPlace(grayImage);
Graphics g = Graphics.FromImage(tmpImage);
blobCounter.MinHeight = 40;
blobCounter.MinWidth = 40;
blobCounter.ObjectsOrder = ObjectsOrder.Area;
blobCounter.ProcessImage(grayImage);
System.Drawing.Rectangle[] rects = blobCounter.GetObjectsRectangles();
Pen pen = new Pen(System.Drawing.Color.Red, 1);
using (pen)
{
foreach (System.Drawing.Rectangle rc in rects)
{
g.DrawRectangle(pen, rects[0].X, rects[0].Y, rects[0].Width, rects[0].Height);
g.DrawRectangle(pen, rects[1].X, rects[1].Y, rects[1].Width, rects[1].Height);
}
}
g.Dispose();
}
I've tried following several tutorials, but all of them are for C# (I'm using XNA), i tried to apply them, but they didn't seem to work, can anyone help me out?
Thanks in advance,
Daniel.
EDIT: Forgot to mention, so far it's detecting the 2 largest black blobs.