public float ProcessFrame( UnmanagedImage videoFrame )
{
lock ( sync )
{
if ( detector == null )
return 0;
videoWidth = videoFrame.Width;
videoHeight = videoFrame.Height;
float motionLevel = 0;
// call motion detection
detector.ProcessFrame( videoFrame );
motionLevel = detector.MotionLevel;
// check if motion zones are specified
if ( motionZones != null )
{
if ( zonesFrame == null )
{
CreateMotionZonesFrame( );
}
if ( ( videoWidth == zonesFrame.Width ) && ( videoHeight == zonesFrame.Height ) )
{
unsafe
{
// pointers to background and current frames
byte* zonesPtr = (byte*) zonesFrame.ImageData.ToPointer( );
byte* motionPtr = (byte*) detector.MotionFrame.ImageData.ToPointer( );
motionLevel = 0;
for ( int i = 0, frameSize = zonesFrame.Stride * videoHeight; i < frameSize; i++, zonesPtr++, motionPtr++ )
{
*motionPtr &= *zonesPtr;
motionLevel += ( *motionPtr & 1 );
}
motionLevel /= ( videoWidth * videoHeight );
}
}
}
// call motion post processing
if ( ( processor != null ) && ( detector.MotionFrame != null ) )
{
processor.ProcessFrame( videoFrame, detector.MotionFrame );
}
return motionLevel;
}
}