private void video_NewFrame(object sender, NewFrameEventArgs e)
{
try
{
bool motion = false;
lock (this)
{
// dispose old frame
if (mLastFrame != null)
{
mLastFrame.Dispose();
}
mLastFrame = new Bitmap(e.Frame);
if (this.Mirror)
{
mLastFrame.RotateFlip(RotateFlipType.RotateNoneFlipX);
}
if (this.Flip)
{
mLastFrame.RotateFlip(RotateFlipType.RotateNoneFlipY);
}
// apply motion detector
if (mMotionDetecotor != null)
{
mMotionDetecotor.ProcessFrame(mLastFrame);
if (mMotionDetecotor is ICountingMotionDetector)
{
ICountingMotionDetector m = mMotionDetecotor as ICountingMotionDetector;
motion = (m.ObjectsCount > 0);
}
else
{
motion = (mMotionDetecotor.MotionLevel > 0.005);
}
}
// image dimension
mImageWidth = mLastFrame.Width;
mImageHeight = mLastFrame.Height;
}
if (this.Alarm != null)
{
if ((motion && this.DetectMode == DETECTMODE.MOTION) || (motion == false && this.DetectMode == DETECTMODE.STILLNESS))
{
Alarm(this, new EventArgs());
}
}
}
catch (Exception)
{
}
// notify client
if (NewFrame != null)
NewFrame(this, new NewFrameEventArgs(null));
}