AForge.NET

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

MotionZones Question

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

MotionZones Question

Postby durnek60 » Sat Feb 11, 2012 11:47 am

Dear Andrew,

I have two questions about MotionDetector.CreateMotionZonesFrame( ) method.
Here is the code:
Code: Select all
zonesFrame = UnmanagedImage.Create( videoWidth, videoHeight, PixelFormat.Format8bppIndexed );

                    Rectangle imageRect = new Rectangle( 0, 0, videoWidth, videoHeight );

                    // draw all motion zones on motion frame
                    foreach ( Rectangle rect in motionZones )
                    {
                        rect.Intersect( imageRect );

                        // rectangle's dimenstion
                        int rectWidth  = rect.Width;
                        int rectHeight = rect.Height;

                        // start pointer
                        int stride = zonesFrame.Stride;
                        byte* ptr = (byte*) zonesFrame.ImageData.ToPointer( ) + rect.Y * stride + rect.X;

                        for ( int y = 0; y < rectHeight; y++ )
                        {
                            AForge.SystemTools.SetUnmanagedMemory( ptr, 255, rectWidth );
                            ptr += stride;
                        }


My first question is, Why do you use intersect method? - Because you want to handle the MotionRectangle and ImageRectangle at the corners?

My second question is, could you explain this part of your code?
Code: Select all

byte* ptr = (byte*) zonesFrame.ImageData.ToPointer( ) + rect.Y * stride + rect.X;

                        for ( int y = 0; y < rectHeight; y++ )
                        {
                            AForge.SystemTools.SetUnmanagedMemory( ptr, 255, rectWidth );
                            ptr += stride;
                        }


Thank you very much!
User avatar
durnek60
 
Posts: 21
Joined: Sat Feb 11, 2012 11:37 am

Re: MotionZones Question

Postby andrew.kirillov » Sat Feb 11, 2012 2:44 pm

Hello,

durnek60 wrote:My first question is, Why do you use intersect method?

Because I want to make sure the specified rectangles are within image.

durnek60 wrote:My second question is, could you explain this part of your code?

What is not clear about the code? It simple fills memory area with bytes equal to 255.
With best regards,
Andrew


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




Return to AForge.NET Framework