Good morning,

I'm having some trouble getting this to work, but i am using 1 color filter to detect a color in my webcam video, but to achieve what i want, is it possible to use 2 color filters?

Thank you in advance.

I actually followed that website, to help me achieve what i wanted, but alas, it does not use 2 color filters only one.
As for the code :

private void cam_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
        {
            Bitmap image = (Bitmap)eventArgs.Frame.Clone();
            EuclideanColorFiltering filter = new EuclideanColorFiltering();
            filter.CenterColor = new AForge.Imaging.RGB(colorDialog1.Color);
            //Pure White  
            filter.Radius = 100;
            filter.FillOutside = true;
            //Increase this to allow off-whites  
            filter.ApplyInPlace(image);
            //Head
            blobCounter.FilterBlobs = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            blobCounter.ProcessImage(image);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Pen pen = new Pen(Color.Red, 1);
            foreach (Rectangle recs in rects)
                if (rects.Length > 0)
                {
                    Graphics g = Graphics.FromImage(image);

                    g.DrawImage(Bitmap.FromFile("C:\\Documents and Settings\\NEXTV035\\Ambiente de trabalho\\Daniel\\dog.png"), rects[0].Location.X, rects[0].Location.Y, rects[0].Width, rects[0].Height);

                    //g.DrawImage(Bitmap.FromFile("C:\\Documents and Settings\\NEXTV035\\Ambiente de trabalho\\Daniel\\Hand.png"), rects[0].Location.X, rects[0].Location.Y, rects[0].Width, rects[0].Height);
                    //g.DrawImage(Bitmap.FromFile("C:\\Documents and Settings\\NEXTV035\\Ambiente de trabalho\\Daniel\\Hand.png"), rects[0].Location.X, rects[0].Location.Y, rects[0].Width, rects[0].Height);
                    g.Dispose();
                }
            pictureBox1.Image = image;
        }

Its really easy:

            ColorFiltering colorFilter = new ColorFiltering( );
            colorFilter.FillOutsideRange = false;


            //black
            colorFilter.Red   = new IntRange( 0, 100 );
            colorFilter.Green = new IntRange( 0, 100 );
            colorFilter.Blue  = new IntRange( 0, 100 );
            colorFilter.ApplyInPlace( bitmapData );


            //white
            colorFilter.Red = new IntRange(200, 255);
            colorFilter.Green = new IntRange(200, 255);
            colorFilter.Blue = new IntRange(200, 255);
            colorFilter.ApplyInPlace(bitmapData);

or on your code:

private void cam_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
        {
            Bitmap image = (Bitmap)eventArgs.Frame.Clone();
            EuclideanColorFiltering filter = new EuclideanColorFiltering();


            filter.CenterColor = new AForge.Imaging.RGB(colorDialog1.Color);
            //Pure White  
            filter.Radius = 100;
            filter.FillOutside = true;
            //Increase this to allow off-whites  
            filter.ApplyInPlace(image);


            filter.CenterColor = new AForge.Imaging.RGB(colorDialog2.Color);
            filter.Radius = 50;
            filter.ApplyInPlace(image);

            //Head
            blobCounter.FilterBlobs = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            blobCounter.ProcessImage(image);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Pen pen = new Pen(Color.Red, 1);
            foreach (Rectangle recs in rects)
                if (rects.Length > 0)
                {
                    Graphics g = Graphics.FromImage(image);
                    g.DrawImage(Bitmap.FromFile("C:\\Documents and Settings\\NEXTV035\\Ambiente de trabalho\\Daniel\\dog.png"), rects[0].Location.X, rects[0].Location.Y, rects[0].Width, rects[0].Height);
                    //g.DrawImage(Bitmap.FromFile("C:\\Documents and Settings\\NEXTV035\\Ambiente de trabalho\\Daniel\\Hand.png"), rects[0].Location.X, rects[0].Location.Y, rects[0].Width, rects[0].Height);
                    //g.DrawImage(Bitmap.FromFile("C:\\Documents and Settings\\NEXTV035\\Ambiente de trabalho\\Daniel\\Hand.png"), rects[0].Location.X, rects[0].Location.Y, rects[0].Width, rects[0].Height);
                    g.Dispose();
                }
            pictureBox1.Image = image;
        }
This article has been dead for over six months. Start a new discussion instead.