Recent Changes - Search:

edit SideBar

motionDetector Module

Module to detect motion in a sequence of images. This module defines three functions, a filter() function that takes an image and some options and returns a modified image; an area() function returns an indicator of the amount of motion in the image, compared to the previous image; and a cog() function, that returns the center of gravity of detected motion, or null if no motion has been detected.

The Ptolemy II/Nashorn host implementation is taken from the webcam-capture package by Bartosz Firyn (SarXos), available from https://github.com/sarxos/webcam-capture. The webcam-capture package is licensed under the MIT License.

See also the auto-generated doc file for the current version of the Ptolemy II/Nashorn host implementation of this module.

Functions

The following functions are implemented by this module:

  • filter(image, options): Invoke the motion detector on the specified image with the specified options and return the result. Any unrecognized options are ignored. Note that previously applied options for a given filter will still be used, even if they are not set in this call.

If this is the first image provided, then no motion is detected and the returned image is identical to the supplied image. Otherwise, the image is compared against the one previously passed to this same function, and the returned image includes an indicator of the center of gravity of detected motion, if sufficient motion is detected. The options are described in the <a href="https://www.icyphy.org/accessors/doc/jsdoc/accessor-MotionDetector.html">detailed documentation</a>.

  • area(): Return a percentage of area covered by motion in the most recently provided image to the filter() function, where 0 means no motion and 100 means full image motion. If filter() has not been invoked, return 0.
  • cog(): Return an array of two numbers giving the center of gravity of the detected motion in pixel coordinates, or return null if no motion has been detected.

Usage

To detect motion between two images from the default camera, you can do this:

   var cameras = require("cameras");
   var motionDetector = require("motionDetector");
   var camera = new cameras.Camera();
   camera.open();
   var image1 = camera.snapshot();
   var image2 = camera.snapshot();
   camera.close();
   var modifiedImage = motionDetector.filter(image); // Use default options.
   var motion = aprilTags.area();
   console.log("Percentage of motion: " + motion);
   var cog = aprilTags.cog();
   console.log("Center of gravity of motion: " + JSON.stringify(cog));

Back to Optional JavaScript Modules

Edit - History - Print - Recent Changes - Search
Page last modified on August 07, 2015, at 06:58 AM