Области обнаружения движения для Aforge.Net - PullRequest
1 голос
/ 14 августа 2011

Я использую AForge для обнаружения движения и знаю, что области движения можно установить.Можно ли сделать так, чтобы это срабатывало только при наличии движений в ВСЕХ определенных областей ?Если вышеупомянутая функциональность недоступна, я подумываю о ее написании.

В настоящее время мое понимание состоит в том, что для регионов задано значение zoneFrame в MotionDetector.cs в Vision Library.Я думаю сделать это для каждого региона, но это кажется неэффективным.

Какой самый эффективный способ сделать это?

Может кто-нибудь объяснить, пожалуйста, код ниже?

private unsafe void CreateMotionZonesFrame( )
    {
        lock ( this )
        {
            // free previous motion zones frame
            if ( zonesFrame != null )
            {
                zonesFrame.Dispose( );
                zonesFrame = null;
            }

            // create motion zones frame only in the case if the algorithm has processed at least one frame
            if ( ( motionZones != null ) && ( motionZones.Length != 0 ) && ( videoWidth != 0 ) )
            {
                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 )
                {
                    //Please explain here
                    rect.Intersect( imageRect );

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

                    // start pointer
                    //Please explain here
                    int stride = zonesFrame.Stride;

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

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

1 Ответ

1 голос
/ 02 апреля 2014

Какой самый эффективный способ сделать это?просто делай для каждого региона.Я не думаю, что будет заметное снижение производительности (но я могу ошибаться)

Ну, код, который вы вложили, делает следующее:

1) проверяет, являются ли ограничения, является ли изображение motionZonesсоздано 2) маски областей белого цвета:

//Please explain here => if the motion region is out of bounds crop it to the image bounds
rect.Intersect( imageRect );

//Please explain here => gets the image stride (width step), the number of bytes per row; see:
//http://msdn.microsoft.com/en-us/library/windows/desktop/aa473780(v=vs.85).aspx
int stride = zonesFrame.Stride;

//Please explain here => gets the pointer of the first element in rectangle area
byte* ptr = (byte*) zonesFrame.ImageData.ToPointer( ) + rect.Y * stride + rect.X;

//mask the rectangle area with 255 value. If the image is color every pixel will have the    //(255,255, 255) value which is white color
for ( int y = 0; y < rectHeight; y++ )
{
    //Please explain here
    AForge.SystemTools.SetUnmanagedMemory( ptr, 255, rectWidth );
    ptr += stride;
}
...