All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.sarxos.webcam.WebcamMotionDetectorAlgorithm Maven / Gradle / Ivy

Go to download

This library allows you to use your PC webcam, IP or network cameras directly from Java. It's compatible with most operating systems (Windows, Linux, MacOS).

There is a newer version: 0.3.12
Show newest version
package com.github.sarxos.webcam;

import java.awt.Point;
import java.awt.image.BufferedImage;
import java.util.ArrayList;


/**
 * Implementation of this interface is responsible for decision whether the
 * difference between two images represents movement or not. Instance may
 * specified as parameter of WebcamMotionDetector constructor, otherwise
 * WebcamMotionDetectorDefaultAlgorithm is used.
 */
public interface WebcamMotionDetectorAlgorithm {

	/**
	 * WebcamMotionDetector calls this method for each image used as parameter
	 * of the method {@link #detect(BufferedImage, BufferedImage)}.
	 * Implementation may transform the original image and prepare it for
	 * comparison of two images.
	 * May return the same instance if no there is no need to transform.
	 * 
	 * @param original image
	 * @return modified image
	 */
	BufferedImage prepareImage(BufferedImage original);

	/**
	 * Detects motion by comparison of the two specified images content.
	 * {@link #prepareImage(BufferedImage)} method was called for both specified images.
	 * 
	 * @param previousModified 
	 * @param currentModified
	 * @return If the motion was detected returns true, otherwise returns false
	 */
	boolean detect(BufferedImage previousModified, BufferedImage currentModified);
	
	/**
	 * Get motion center of gravity. When no motion is detected this value
	 * points to the image center.
	 * May return null before the first movement check.
	 *
	 * @return Center of gravity point
	 */
	Point getCog();
	
	/**
	 * Get percentage fraction of image covered by motion. 0 means no motion on
	 * image and 100 means full image covered by spontaneous motion.
	 *
	 * @return Return percentage image fraction covered by motion
	 */
	double getArea();

    /**
     * Set the minimum range between each point detected
     * @param i the range to set
     */
    void setPointRange(int i);

    /**
     * Set the max amount of points that can be detected at one time
     * @param i The amount of points that can be detected
     */
    void setMaxPoints(int i);


    /**
     * Get the current minimum range between each point
     * @return The current range
     */
    int getPointRange();

    /**
     * Get the current max amount of points that can be detected at one time
     * @return
     */
    int getMaxPoints();


    /**
     * Returns the currently stored points that have been detected
     * @return The current points
     */
    ArrayList getPoints();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy