Version0 /
motionDetector ModuleModule 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. FunctionsThe following functions are implemented by this module:
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://ptolemy.berkeley.edu/accessors/doc/jsdoc/accessor-MotionDetector.html">detailed documentation</a>.
UsageTo 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 |