Skip to main content

Motion detection

Products: Video Capture SDK .Net

SDK includes two motion detectors - simple and advanced (extended).

Simple motion detector

The basic motion detector operates with simplicity and efficiency. This detector swiftly processes movements and provides the output in the form of a two-dimensional byte array, known as the motion matrix. Users have the flexibility to adjust the matrix size through the settings.

Each time the motion detector is activated, it calculates the level of motion, presenting it as a percentage. Additionally, the detector offers the functionality to emphasize detected motion. It allows the analysis of all RGB (Red, Green, Blue) color channels or the option to focus on just a single channel.

Sample code

// create motion detector settings
var motionDetector = new MotionDetectionSettings();

// set the motion detector matrix width
motionDetector.Matrix_Width = 10;

// set the motion detector matrix height
motionDetector.Matrix_Height = 10;

// set the color channels to analyze
motionDetector.Compare_Red = false;
motionDetector.Compare_Green = false;
motionDetector.Compare_Blue = false;
motionDetector.Compare_Greyscale = true;

// highlight motion by color?
motionDetector.Highlight_Color = MotionCHLColor.Green;
motionDetector.Highlight_Enabled = true;

// sets the frame interval to analyze motion. SDK can skip frames to speed up the process
motionDetector.FrameInterval = 5;

// set the drop frames mode. SDK can drop frames if the analysis takes too much time
motionDetector.DropFrames_Enabled = false;

// apply settings
VideoCapture1.Motion_Detection = motionDetector;

Implement the OnMotion event to get the motion level and matrix.

Advanced motion detector

The advanced motion detector is more complex. It can detect objects and has different processor and detector types.

Sample code and usage

Create motion detector settings.

var motionDetector = new MotionDetectionExSettings();

Set the sample processor type.

ProcessorType = MotionProcessorType.BlobCountingObjects;

Set the sample detector type.

DetectorType = MotionDetectorType.CustomFrameDifference;

Apply settings.

VideoCapture1.Motion_DetectionEx = motionDetector;

Implement the OnMotionDetectionEx event to get the motion level, matrix, and objects, depending on the configuration used.

Motion processor types

  • None - do not highlight motion on the image
  • BlobCountingObjects - counts separate moving objects and highlights them
  • GridMotionAreaProcessing - performs grid processing of motion frame
  • MotionAreaHighlighting - highlights motion areas
  • MotionBorderHighlighting - highlights the border of motion areas

Motion detector types

  • CustomFrameDifference - Motion detector based on the difference with the predefined background frame
  • SimpleBackgroundModeling - Motion detector based on simple background modeling
  • TwoFramesDifference - Motion detector based on two continuous frames difference

Visit our GitHub page to get more code samples.