Class MotionDetectorFilter

  • All Implemented Interfaces:
    java.awt.image.BufferedImageOp, java.lang.Cloneable

    public class MotionDetectorFilter
    extends AbstractBufferedImageOp
    A motion detector image filter. This filter compares each image to be filtered against the previously provided image to be filtered. If enough of the pixels differ by enough, then it modifies the image to be filtered by adding a small red circle at the center of gravity of the pixels that differ by enough. The parameters of the filter are:
    • PixelThreshold: Intensity threshold whereby a pixel is deemed to different (an int 0 - 255, with default 25).
    • AreaThreshold: The percentage threshold of image that has different pixels for motion to be detected (a double 0-100, with default 0.2).
    • ModifyImage: If true (the default), the modify the provided image with a visual indication of the location and amount of motion.
    The 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. The filter architecture follows the pattern defined by Jerry Huxtable in the JH Labs Java Image Processing library, available from: http://www.jhlabs.com/ip/filters and licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0).
    Since:
    Ptolemy II 11.0
    Version:
    $Id$
    Author:
    Bartosz Firyn (SarXos) and Edward A. Lee
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Yellow (eal)
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.image.BufferedImage filter​(java.awt.image.BufferedImage source, java.awt.image.BufferedImage destination)
      Filter the source image, and if motion is detected, place a red circle at the center of gravity of the motion.
      double getAreaThreshold()
      Get the percentage fraction of detected motion area threshold above which it is classified as "moved".
      java.awt.Point getCOG()
      Return center of gravity of motion detected by the most recent invocation of filter(), or null if no motion was detected.
      boolean getModifyImage()
      Return whether the filter will modify the provided image with a visual indication of the amount and location of the motion.
      double getMotionArea()
      Return the motion strength (0 = no motion, 100 = full image covered by motion).
      int getPixelThreshold()
      Get the pixel intensity difference threshold above which pixel is classified as "moved".
      boolean isMotion()
      Return whether motion was detected in the last filter operation.
      void setAreaThreshold​(double threshold)
      Set the percentage fraction of detected motion area threshold above which it is classified as "moved".
      void setModifyImage​(boolean modify)
      Specify whether to modify the image with a visual indication of the amount and location of the motion.
      void setPixelThreshold​(int threshold)
      Set the pixel intensity difference threshold above which pixel is classified as "moved".
      java.lang.String toString()
      Return a string description of the filter.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • MotionDetectorFilter

        public MotionDetectorFilter()
    • Method Detail

      • filter

        public java.awt.image.BufferedImage filter​(java.awt.image.BufferedImage source,
                                                   java.awt.image.BufferedImage destination)
        Filter the source image, and if motion is detected, place a red circle at the center of gravity of the motion. If the destination argument is null, then the red circle is added directly to the source, and the source is returned. Otherwise, the red circle is added to the destination image.
        Parameters:
        source - The source image, on which motion is detected.
        destination - The destination image, on which the red circle is added, or null to specify to add the circle to the source image.
      • getAreaThreshold

        public double getAreaThreshold()
        Get the percentage fraction of detected motion area threshold above which it is classified as "moved". Minimum value for this is 0 and maximum is 100, which corresponds to full image covered by spontaneous motion.
        Returns:
        The percentage of image area.
        See Also:
        setAreaThreshold(double)
      • getCOG

        public java.awt.Point getCOG()
        Return center of gravity of motion detected by the most recent invocation of filter(), or null if no motion was detected.
        Returns:
        The center of gravity of motion (in pixels).
      • getModifyImage

        public boolean getModifyImage()
        Return whether the filter will modify the provided image with a visual indication of the amount and location of the motion.
        Returns:
        True if the image will be modified (the default).
      • getMotionArea

        public double getMotionArea()
        Return the motion strength (0 = no motion, 100 = full image covered by motion).
        Returns:
        The motion area percentage.
      • getPixelThreshold

        public int getPixelThreshold()
        Get the pixel intensity difference threshold above which pixel is classified as "moved". The minimum value is 0 and maximum is 255. Default value is 10. This value is equal for all RGB components difference.
        Returns:
        The pixel intensity difference threshold.
        See Also:
        setPixelThreshold(int)
      • isMotion

        public boolean isMotion()
        Return whether motion was detected in the last filter operation.
        Returns:
        Whether motion was detected.
      • setAreaThreshold

        public void setAreaThreshold​(double threshold)
        Set the percentage fraction of detected motion area threshold above which it is classified as "moved". The minimum value for this is 0 and maximum is 100, which corresponds to full image covered by spontaneous motion.
        Parameters:
        threshold - The percentage of image area.
        See Also:
        getAreaThreshold()
      • setModifyImage

        public void setModifyImage​(boolean modify)
        Specify whether to modify the image with a visual indication of the amount and location of the motion.
        Parameters:
        modify - True to modify the image.
        See Also:
        getModifyImage()
      • setPixelThreshold

        public void setPixelThreshold​(int threshold)
        Set the pixel intensity difference threshold above which pixel is classified as "moved". The minimum value is 0 and maximum is 255. Default value is 10. This value is equal for all RGB components difference.
        Parameters:
        threshold - The pixel intensity difference threshold.
        See Also:
        getPixelThreshold()
      • toString

        public java.lang.String toString()
        Return a string description of the filter.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The string "MotionDetectorFilter".