AForge.Vision.Motion.BlobCountingObjectsProcessing.ProcessFrame C# (CSharp) Method

ProcessFrame() public method

Process video and motion frames doing further post processing after performed motion detection.

Processes provided motion frame and counts number of separate objects, which size satisfies MinObjectsWidth and MinObjectsHeight properties. In the case if HighlightMotionRegions property is set to , the found object are also highlighted on the original video frame.

Motion frame is not 8 bpp image, but it must be so. Video frame must be 8 bpp grayscale image or 24/32 bpp color image.
public ProcessFrame ( UnmanagedImage videoFrame, UnmanagedImage motionFrame ) : void
videoFrame AForge.Imaging.UnmanagedImage Original video frame.
motionFrame AForge.Imaging.UnmanagedImage Motion frame provided by motion detection /// algorithm (see ).
return void
        public unsafe void ProcessFrame( UnmanagedImage videoFrame, UnmanagedImage motionFrame )
        {
            if ( motionFrame.PixelFormat != PixelFormat.Format8bppIndexed )
            {
                throw new InvalidImagePropertiesException( "Motion frame must be 8 bpp image." );
            }

            if ( ( videoFrame.PixelFormat != PixelFormat.Format8bppIndexed ) &&
                 ( videoFrame.PixelFormat != PixelFormat.Format24bppRgb ) &&
                 ( videoFrame.PixelFormat != PixelFormat.Format32bppRgb ) &&
                 ( videoFrame.PixelFormat != PixelFormat.Format32bppArgb ) )
            {
                throw new UnsupportedImageFormatException( "Video frame must be 8 bpp grayscale image or 24/32 bpp color image." );
            } 

            int width  = videoFrame.Width;
            int height = videoFrame.Height;

            if ( ( motionFrame.Width != width ) || ( motionFrame.Height != height ) )
                return;

            lock ( blobCounter )
            {
                blobCounter.ProcessImage( motionFrame );
            }

            if ( highlightMotionRegions )
            {
                // highlight each moving object
                Rectangle[] rects = blobCounter.GetObjectsRectangles( );

                foreach ( Rectangle rect in rects )
                {
                    Drawing.Rectangle( videoFrame, rect, highlightColor );
                }
            }
        }