AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Filter: How does this work?

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

Filter: How does this work?

Postby aish0 » Tue Mar 03, 2009 6:53 pm

Hey,

I have the following code:

Code: Select all
private void webcam_NewFrame(object sender, NewFrameEventArgs e)
        {
            if (pictureBox1.Image != null)
            {
                Bitmap lastFrame = (Bitmap)pictureBox1.Image;
                Bitmap currentFrame = e.Frame;
                // Motion Detection
                // Difference
                Difference df1 = new Difference();
                df1.OverlayImage = lastFrame;
                Bitmap t1 = df1.Apply(currentFrame);
               
                Threshold df2 = new Threshold(15);
                Bitmap t2 = df2.Apply(t1);
                //Bitmap t2 = t1;

                Bitmap rt2 = new Bitmap(320,240);
                using (Graphics g = Graphics.FromImage((System.Drawing.Image)rt2))
                {
                    g.DrawImage(t1, 0, 0, 320, 240);
                }

                PictureBox mB = (PictureBox)mS.Controls["pictureBox1"];
                mB.Image = rt2;
            }

            pictureBox1.Image = (Bitmap)e.Frame.Clone();
            System.Threading.Thread.Sleep(40);
        }


mS is another form. What I am trying to accomplish is to use the difference filter between the last frame and the current frame, pass this through the threshold filter, and show this output in the mB picture box. pictureBox1 should still show the video (camera) input.

Instead I see a discoloured still image (of i guess the first/second frame the camera captured) in pictureBox1. The mB picture box is empty.

What am I doing wrong?

I hope you can help me out. Thank you!
Aish
aish0
 
Posts: 16
Joined: Tue Mar 03, 2009 4:11 am

Re: Filter: How does this work?

Postby andrew.kirillov » Tue Mar 03, 2009 8:10 pm

Hello,

What you should see is actually a difference image between current frame and the previous frame. You will not see thresholded image, since you ignore it:
aish0 wrote: Threshold df2 = new Threshold(15);
Bitmap t2 = df2.Apply(t1);

- you don't use t2 anywhere in the code. What is the pixel format of your source images? Color or grayscale? If your source images are color, than the code should not work. Threshold filer works only with grayscale image and should generate exception for color.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Filter: How does this work?

Postby aish0 » Tue Mar 03, 2009 8:58 pm

Hey,

Thanks for your reply. I see. My image is colour. So I guess I will gray scale it and then pass it to threshold. I am trying to detect motion (following one of your articles at code project - by doing difference first, threshold, then passing it through erosion - and counting the number of white pixels (since i only need to know if motion occurred, not which part)).

Thanks for your patience :)
Aish
(P.S. Yes, there was that mistake too, where I did not use t2 anywhere)
aish0
 
Posts: 16
Joined: Tue Mar 03, 2009 4:11 am

Re: Filter: How does this work?

Postby andrew.kirillov » Tue Mar 03, 2009 9:05 pm

Hello,

aish0 wrote:I am trying to detect motion (following one of your articles at code project -

Well, if you try to follow that article, then there was a bit different filters sequence: grayscale, difference, threshold, ... You can see all that from the attached code to the article.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK




Return to AForge.NET Framework

cron