gpt4 book ai didi

c# - Aforge.Net 的运动检测区域

转载 作者:太空宇宙 更新时间:2023-11-03 23:04:15 26 4
gpt4 key购买 nike

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

最佳答案

最有效的方法是什么?只为每个地区做。我不认为会有明显的性能损失(但我可能是错的)

好吧,您附上的代码执行以下操作:

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

关于c# - Aforge.Net 的运动检测区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7057970/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com