-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to move MotionDetection into a more OO design and fixed the a…
…ggregate luma detection git-svn-id: https://android-motion-detection.googlecode.com/svn/trunk@19 996b93ed-3e4d-4b21-1044-74bd19560d1d
- Loading branch information
1 parent
d4a09a4
commit 891f971
Showing
9 changed files
with
366 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
package com.jwetherell.motion_detection; | ||
|
||
public class Globals { | ||
//Which motion detection to use | ||
public static boolean USE_RGB = true; | ||
public static boolean USE_LUMA = false; | ||
public static boolean USE_STATE = false; | ||
|
||
//Which photos to save | ||
public static boolean SAVE_PREVIOUS = false; | ||
public static boolean SAVE_ORIGINAL = false; | ||
public static boolean SAVE_CHANGES = true; | ||
|
||
//Time between saving photos | ||
public static int PICTURE_DELAY = 10000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/com/jwetherell/motion_detection/detection/AggregateLumaMotionDetection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.jwetherell.motion_detection.detection; | ||
|
||
import android.util.Log; | ||
|
||
|
||
/** | ||
* This class is used to process integer arrays containing luma data and detects motion using an aggregate map. | ||
* | ||
* @author Justin Wetherell <[email protected]> | ||
*/ | ||
public class AggregateLumaMotionDetection implements IMotionDetection { | ||
private static final String TAG = "AggregateLumaMotionDetection"; | ||
|
||
//Specific settings | ||
private static final int mLeniency = 10; //Difference of aggregate map of luma values | ||
private static final int mDebugMode = 2; //State based debug | ||
private static final int mXBoxes = 10; //State based debug | ||
private static final int mYBoxes = 10; //State based debug | ||
|
||
private static int[] mPrevious = null; | ||
private static int mPreviousWidth; | ||
private static int mPreviousHeight; | ||
private static State mPreviousState = null; | ||
|
||
public int[] getPrevious() { | ||
return ((mPrevious!=null)?mPrevious.clone():null); | ||
} | ||
|
||
protected static boolean isDifferent(int[] first, int width, int height) { | ||
if (first==null) throw new NullPointerException(); | ||
|
||
if (mPrevious==null) return false; | ||
if (first.length != mPrevious.length) return true; | ||
if (mPreviousWidth != width || mPreviousHeight != height) return true; | ||
|
||
if (mPreviousState==null) { | ||
mPreviousState = new State(mPrevious, mPreviousWidth, mPreviousHeight); | ||
return false; | ||
} | ||
|
||
State state = new State(first, width, height); | ||
Comparer comparer = new Comparer(state, mPreviousState, mXBoxes, mYBoxes, mLeniency, mDebugMode); | ||
|
||
boolean different = comparer.isDifferent(); | ||
String output = "isDifferent="+different; | ||
if (different) { | ||
Log.e(TAG, output); | ||
comparer.paintDifferences(first); | ||
} else { | ||
Log.d(TAG, output); | ||
} | ||
|
||
mPreviousState = state; | ||
|
||
return different; | ||
} | ||
|
||
public boolean detect(int[] luma, int width, int height) { | ||
if (luma==null) throw new NullPointerException(); | ||
|
||
int[] original = luma.clone(); | ||
|
||
// Create the "mPrevious" picture, the one that will be used to check the next frame against. | ||
if(mPrevious == null) { | ||
mPrevious = original; | ||
mPreviousWidth = width; | ||
mPreviousHeight = height; | ||
Log.i(TAG, "Creating background image"); | ||
} | ||
|
||
long bDetection = System.currentTimeMillis(); | ||
boolean motionDetected = isDifferent(luma, width, height); | ||
long aDetection = System.currentTimeMillis(); | ||
Log.d(TAG, "Detection "+(aDetection-bDetection)); | ||
|
||
// Replace the current image with the previous. | ||
mPrevious = original; | ||
mPreviousWidth = width; | ||
mPreviousHeight = height; | ||
|
||
return motionDetected; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/com/jwetherell/motion_detection/detection/IMotionDetection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.jwetherell.motion_detection.detection; | ||
|
||
|
||
/** | ||
* This interface is used to represent a class that can detect motion | ||
* | ||
* @author Justin Wetherell <[email protected]> | ||
*/ | ||
public interface IMotionDetection { | ||
|
||
public int[] getPrevious(); | ||
|
||
public boolean detect(int[] data, int width, int height); | ||
} |
Oops, something went wrong.