src/Foundation/Media/Gimela.Media.Vision.Motion/MotionProcessors/MotionAreaHighlighting.cs
/// <summary>
/// Process video and motion frames doing further post processing after
/// performed motion detection.
/// </summary>
/// 
/// <param name="videoFrame">Original video frame.</param>
/// <param name="motionFrame">Motion frame provided by motion detection
/// algorithm (see <see cref="IMotionDetector"/>).</param>
/// 
/// <remarks><para>Processes provided motion frame and highlights motion areas
/// on the original video frame with <see cref="HighlightColor">specified color</see>.</para>
/// </remarks>
///
Process video and motion frames doing further post processing after
performed motion detection.
Process video and motion frames doing further post processing after performed motion detection .
public unsafe void ProcessFrame(UnmanagedImage videoFrame, UnmanagedImage motionFrame)
    {
      int width = videoFrame.Width;
      int height = videoFrame.Height;
      if ((motionFrame.Width != width) || (motionFrame.Height != height))
        return;
      byte* src = (byte*)videoFrame.ImageData.ToPointer();
      byte* motion = (byte*)motionFrame.ImageData.ToPointer();
      int srcOffset = videoFrame.Stride - width * 3;
      int motionOffset = motionFrame.Stride - width;
      byte fillR = highlightColor.R;
      byte fillG = highlightColor.G;
      byte fillB = highlightColor.B;
      for (int y = 0; y < height; y++)
      {
        for (int x = 0; x < width; x++, motion++, src += 3)
        {
          if ((*motion != 0) && (((x + y) & 1) == 0))
          {
            src[RGB.R] = fillR;
            src[RGB.G] = fillG;
            src[RGB.B] = fillB;
          }
        }
        src += srcOffset;
        motion += motionOffset;
      }
    }
public unsafe void ProcessFrame ( UnmanagedImage videoFrame , UnmanagedImage motionFrame ) { int width = videoFrame . Width ; int height = videoFrame . Height ; if ( ( motionFrame . Width != width ) || ( motionFrame . Height != height ) ) return ; byte * src = ( byte * ) videoFrame . ImageData . ToPointer ( ) ; byte * motion = ( byte * ) motionFrame . ImageData . ToPointer ( ) ; int srcOffset = videoFrame . Stride - width * 3 ; int motionOffset = motionFrame . Stride - width ; byte fillR = highlightColor . R ; byte fillG = highlightColor . G ; byte fillB = highlightColor . B ; for ( int y = 0 ; y < height ; y ++ ) { for ( int x = 0 ; x < width ; x ++ , motion ++ , src += 3 ) { if ( ( * motion != 0 ) && ( ( ( x + y ) & 1 ) == 0 ) ) { src [ RGB . R ] = fillR ; src [ RGB . G ] = fillG ; src [ RGB . B ] = fillB ; } } src += srcOffset ; motion += motionOffset ; } }
Process video and motion frames doing further post processing after
performed motion detection.
Process video and motion frames doing further post processing after performed motion detection .
videoFrame
UnmanagedImage
Original video frame.
Original video frame .
motionFrame
UnmanagedImage
Motion frame provided by motion detection
algorithm (see


Motion frame provided by motion detection algorithm ( see
remarks
Processes provided motion frame and highlights motion areas
on the original video frame with specified color
Processes provided motion frame and highlights motion areas on the original video frame with specified color