From 8f49402a1d7092f666dc266af090784cac6543a5 Mon Sep 17 00:00:00 2001 From: Libor Masek Date: Wed, 28 Jun 2017 13:52:45 +0800 Subject: [PATCH] Two Frames Motion Detector: reverted back to existing byte level difference code. --- Vision/TwoFramesDifferenceDetector.cs | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/Vision/TwoFramesDifferenceDetector.cs b/Vision/TwoFramesDifferenceDetector.cs index 8d9267df..9b4f9df1 100644 --- a/Vision/TwoFramesDifferenceDetector.cs +++ b/Vision/TwoFramesDifferenceDetector.cs @@ -258,37 +258,22 @@ public unsafe void ProcessFrame(UnmanagedImage videoFrame) // convert current image to grayscale Tools.ConvertToGrayscale(videoFrame, _motionFrame); - UInt64* prevFrame = (UInt64*)_previousFrame.ImageData.ToPointer(); - UInt64* currFrame = (UInt64*)_motionFrame.ImageData.ToPointer(); + // pointers to previous and current frames + byte* prevFrame = (byte*)_previousFrame.ImageData.ToPointer(); + byte* currFrame = (byte*)_motionFrame.ImageData.ToPointer(); // difference value // 1 - get difference between frames // 2 - threshold the difference // 3 - copy current frame to previous frame - for (int i = 0; i < _frameSize / sizeof(UInt64); i++, prevFrame++, currFrame++) + for (int i = 0; i < _frameSize; i++, prevFrame++, currFrame++) { // difference - var diff = (*currFrame ^ *prevFrame) & _differenceThresholMask; + var diff = *currFrame - *prevFrame; // copy current frame to previous *prevFrame = *currFrame; // treshold - *currFrame = 0; - if ((diff & 0xFF00000000000000) != 0) // take care of the 1st byte - *currFrame |= 0xFF00000000000000; - if ((diff & 0x00FF000000000000) != 0) // take care of the 2nd byte - *currFrame |= 0x00FF000000000000; - if ((diff & 0x0000FF0000000000) != 0) // take care of the 3rd byte - *currFrame |= 0x0000FF0000000000; - if ((diff & 0x000000FF00000000) != 0) // take care of the 4th byte - *currFrame |= 0x000000FF00000000; - if ((diff & 0x00000000FF000000) != 0) // take care of the 5th byte - *currFrame |= 0x00000000FF000000; - if ((diff & 0x0000000000FF0000) != 0) // take care of the 6th byte - *currFrame |= 0x0000000000FF0000; - if ((diff & 0x000000000000FF00) != 0) // take care of the 7th byte - *currFrame |= 0x000000000000FF00; - if ((diff & 0x00000000000000FF) != 0) // take care of the 8th byte - *currFrame |= 0x00000000000000FF; + *currFrame = ((diff >= _differenceLevel) || (diff <= -_differenceLevel)) ? (byte)255 : (byte)0; } if (_suppressNoise)