AForge.NET

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

How can I draw Blobs?

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

How can I draw Blobs?

Postby mr.shutdown » Wed Mar 11, 2009 8:18 am

Code: Select all
        private void video_NewFrame(object sender, NewFrameEventArgs eventArgs) {
            // get new frame
            Bitmap bitmap = eventArgs.Frame;
            // process the frame
            detector.ProcessFrame(bitmap);
            // create an instance of blob counter algorithm
            BlobCounter bc = new BlobCounter();
            // process binary image
            bc.ProcessImage(bitmap);
            Rectangle[] rects = bc.GetObjectRectangles();
            Graphics g = Graphics.FromImage(bitmap);
            // process blobs
            foreach (Rectangle rect in rects) {
                using (Pen pen = new Pen(Color.FromArgb(160, 255, 160), 2)) {
                    g.DrawRectangle(pen, rect);
                }
            }
            g.Dispose();
            // show the image
            pictureBox1.Image = (Bitmap)bitmap.Clone();
            pictureBox1.Refresh();
        }


When I added BlobCounter, PictureBox doesn't show the picture.
I think that the bc.ProcessImage() argument is wrong.

What is the error?
mr.shutdown
 
Posts: 12
Joined: Fri Feb 27, 2009 10:29 am
Location: Italy

Re: How can I draw Blobs?

Postby andrew.kirillov » Wed Mar 11, 2009 9:21 am

Hello,

Check BlobCounter documentation - it accepts 8 bpp indexed grayscale images only. I am not really sure your source image is in this format.

And this line also has 0 effect on the source image:
Code: Select all
            // process the frame
            detector.ProcessFrame(bitmap);
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: How can I draw Blobs?

Postby mr.shutdown » Wed Mar 11, 2009 9:57 am

So I have to filter the bitmap image... Ok!
Can you tell me the name of the appropriate class to convert the image?

Why this code has no effect?
Code: Select all
detector.ProcessFrame(bitmap);


Ehi Andrew! Thank you very much...
Niccolò.
mr.shutdown
 
Posts: 12
Joined: Fri Feb 27, 2009 10:29 am
Location: Italy

Re: How can I draw Blobs?

Postby andrew.kirillov » Wed Mar 11, 2009 10:34 am

You
mr.shutdown wrote:So I have to filter the bitmap image... Ok!
Can you tell me the name of the appropriate class to convert the image?

You may use GrayscaleBT709 filter, for example, to get grayscale image from color. But, be careful - BlobCounter supposes you have binary image (or at least gray objects on black background) ... I am not really sure what you are trying to do, so can not advice about which routines you need to use.

mr.shutdown wrote:Why this code has no effect?

detector.ProcessFrame(bitmap);

Sorry, my fault. It may have effect, if does changes to the source image. But I am not sure it does. If the detector is a motion detector, then it does not make changes to the source image except highlighting of motion regions.

P.S. try to explain what you would like to get and what is you issue, instead of always posting your source code. We are not debuggers/compilers here, so looking for your bugs in your code snippets is not fun at all.
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: How can I draw Blobs?

Postby mr.shutdown » Wed Mar 11, 2009 12:02 pm

Okay okay, then I try to explain my situation.

You have to know that "video_NewFrame" is the "New Frame Event Handler" and that I'm acquiring the image from webcam.

I decided to print each received frame in a picture box and this feature is OK. So I'd like to draw a red rectangle for each "Blob" identified. But, when I try to draw these rectangles, no image is printed in the box.

Well, if this problem (empty picture box) may take more time, you can think that you can help me by an example wich show directly the recognition of "Blob".

If you prefer you can write a short code to show me the correct solution.

Bye and thank you Andrew, ;)
Niccolò.
mr.shutdown
 
Posts: 12
Joined: Fri Feb 27, 2009 10:29 am
Location: Italy

Re: How can I draw Blobs?

Postby mr.shutdown » Tue Mar 17, 2009 1:19 pm

I have found a solution.
Thanks to all.

Bye!
mr.shutdown
 
Posts: 12
Joined: Fri Feb 27, 2009 10:29 am
Location: Italy




Return to AForge.NET Framework

cron