1

私はモーション検出に AForge を使用しており、モーション領域を設定できることを知っています。定義されたすべての領域にモーションがある場合にのみトリガーするようにすることは可能ですか? 上記の機能がすぐに利用できない場合は、書き込もうと考えています。

現在、Vision Library の MotionDetector.cs の zoneFrame に領域が設定されていると理解しています。これを地域ごとにやろうと思っているのですが、効率が悪いようです。

これを行う最も効率的な方法は何ですか?

誰かが私に以下のコードを説明してもらえますか?

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;
                    }
                }
            }
        }
    }
4

1 に答える 1

1

これを行う最も効率的な方法は何ですか? 地域ごとに行うだけです。顕著なパフォーマンスの低下はないと思います (ただし、間違っている可能性があります)。

さて、あなたが同封したコードは次のことを行います:

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;
}
于 2014-04-02T07:39:40.007 に答える