1
我使用AForge進行運動檢測,我知道可以設置運動區域。是否有可能只在有運動時觸發所有定義的區域? 如果上述功能不易獲取,我正在考慮編寫它。Aforge.Net的運動檢測區域
目前,我的理解是區域設置爲視覺庫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;
}
}
}
}
}