【问题标题】:Motion detection regions for Aforge.NetAforge.Net 的运动检测区域
【发布时间】:2011-10-26 20:14:15
【问题描述】:

我正在使用 AForge 进行运动检测,并且我知道可以设置运动区域。是否可以使其仅在所有定义的区域中有运动时触发? 如果上述功能尚不可用,我正在考虑编写它。

目前,我的理解是区域设置为视觉库中 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;
                    }
                }
            }
        }
    }

【问题讨论】:

    标签: c# opencv computer-vision motion-detection aforge


    【解决方案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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-30
      • 2016-09-02
      • 2014-06-15
      相关资源
      最近更新 更多