我正在使用 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;
}
}
}
}
}