MotionDetector

Description

This plugin is a motion detector which is able to detect motion in a video stream.
This detector accepts every pixel formats available in Papillon (see papillon::PImage::EPixelFormat).
Two algorithms are available to detect motion: frame to frame difference and background subtraction (see parameters below).

This plugin creates a papillon::PDetector object.
It can be dynamically configured using papillon::PDetectorOptions.

  • Plugin: PPluginMotionDetector
  • Product name: MotionDetector
  • Version: 1.0

Example:

How to create a PDetector Motion Detector object from this plugin?

PDetector detector;
PProperties parameters;
parameters.Set("type", PString("FRAME_TO_FRAME_DIFFERENCE"));
PResult ret = PDetector::Create("MotionDetector", parameters, detector); // or type=BACKGROUND_SUBSTRACTION
if (ret.Failed()) ...

Parameters

When creating an instance of motion detector, you can choose between 2 different algorithms:

  • type=FRAME_TO_FRAME_DIFFERENCE (default)
  • type=BACKGROUND_SUBSTRACTION

Use papillon::PDetectorOptions to configure motion detector (see example below). A papillon::PDetectorOptions object is passed as argument when calling Apply().
Parameters are the following:

Parameter Description
MinDetectionSize Minimum motion detection size in pixels (80x80 by default).
MaxDetectionSize Maximum motion detection size in pixels (1000x1000 by default).
MaxDetections Maximum number of detections in an image (keep only the N largest blobs); detect all by default.
RegionOfInterest (ROI) Detection area in the image (in pixels): the analysed image is cropped to this specified rectangle before applying the motion detector.

Example

/*
* Copyright (C) 2015-2018 Digital Barriers plc. All rights reserved.
* Contact: http://www.digitalbarriers.com/
*
* This file is part of the Papillon SDK.
*
* You can't use, modify or distribute any part of this file without
* the explicit written agreements of Digital Barriers.
*/
#include <PapillonCore.h>
USING_NAMESPACE_PAPILLON
const PString SAMPLE_DIR = PPath::Join(PUtils::GetEnv("PAPILLON_INSTALL_DIR"), "Data", "Samples"); // path to find sample data: $PAPILLON_INSTALL_DIR/Data/Samples
const float SCALE_FACTOR = 1.0f;
const int LINE_WIDTH = 2;
static void RunDemo()
{
// ************************************************************************
// 1. Open Video Stream
// ************************************************************************
PInputVideoStream::Open(PPath::Join(SAMPLE_DIR , "glasgow.avi"), ivs).OrDie();
// ************************************************************************
// 2. Create Motion Detector
// ************************************************************************
PProperties parameters;
parameters.Set("type", PString("BACKGROUND_SUBSTRACTION"));
PDetector motionDetector;
PDetector::Create("MotionDetector", parameters, motionDetector).OrDie(); // you could also try "type=FRAME_TO_FRAME_DIFFERENCE"
motionDetector.SetMinDetectionSize(PSizei(70, 70));
motionDetector.SetMaxDetectionSize(PSizei(500, 500));
motionDetector.SetMaxDetections(10);
// ************************************************************************
// 3. Apply Motion Detector on the video stream
// ************************************************************************
PFrame frame;
PDetectionList detectionList;
while (ivs.GetFrame(frame).Ok() && !PUtils::IsEscPressed())
{
motionDetector.Detect(frame, detectionList);
papillon::PUtils::DisplayDetectionList(frame, detectionList, "Papillon SDK - Motion Detector example", SCALE_FACTOR, PColour3i::Red(), false, false, LINE_WIDTH);
}
}
int main()
{
RunDemo();
return 0;
}