Skip to content

Commit

Permalink
Updates to move the global variables to it's own file
Browse files Browse the repository at this point in the history
git-svn-id: https://android-motion-detection.googlecode.com/svn/trunk@15 996b93ed-3e4d-4b21-1044-74bd19560d1d
  • Loading branch information
[email protected] committed Aug 31, 2011
1 parent 50fd093 commit cf986f1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
11 changes: 11 additions & 0 deletions src/com/jwetherell/motion_detection/Globals.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.jwetherell.motion_detection;

public class Globals {
public static boolean USE_RGB = false;
public static boolean USE_LUMA = true;
public static boolean USE_STATE = false;
public static boolean SAVE_PREVIOUS = false;
public static boolean SAVE_ORIGINAL = false;
public static boolean SAVE_CHANGES = true;
public static int PICTURE_DELAY = 10000;
}
32 changes: 14 additions & 18 deletions src/com/jwetherell/motion_detection/MotionDetectionActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
*/
public class MotionDetectionActivity extends Activity {
private static final String TAG = "MotionDetectionActivity";
private static final boolean SAVE_PREVIOUS = true;
private static final boolean SAVE_ORIGINAL = true;
private static final boolean SAVE_CHANGES = true;
private static final int PICTURE_DELAY = 10000;

private static SurfaceView preview = null;
private static SurfaceHolder previewHolder = null;
Expand Down Expand Up @@ -156,47 +152,47 @@ public void run() {
try {
//Previous frame
int[] pre = null;
if (SAVE_PREVIOUS) pre = MotionDetection.getPrevious();
if (Globals.SAVE_PREVIOUS) pre = MotionDetection.getPrevious();

//Current frame (with changes)
long bConversion = System.currentTimeMillis();
int[] img = null;
if (MotionDetection.USE_RGB) {
if (Globals.USE_RGB) {
img = ImageProcessing.decodeYUV420SPtoRGB(data, width, height);
} else {
img = ImageProcessing.decodeYUV420SPtoLuminescence(data, width, height);
img = ImageProcessing.decodeYUV420SPtoLuma(data, width, height);
}
long aConversion = System.currentTimeMillis();
Log.d(TAG, "Converstion="+(aConversion-bConversion));

//Current frame (without changes)
int[] org = null;
if (SAVE_ORIGINAL && img!=null) org = img.clone();
if (Globals.SAVE_ORIGINAL && img!=null) org = img.clone();

if (img!=null && MotionDetection.detect(img, width, height)) {
// The delay is necessary to avoid taking a picture while in the
// middle of taking another. This problem can causes some phones
// to reboot.
long now = System.currentTimeMillis();
if (now > (mReferenceTime + PICTURE_DELAY)) {
if (now > (mReferenceTime + Globals.PICTURE_DELAY)) {
mReferenceTime = now;

Bitmap previous = null;
if (SAVE_PREVIOUS && pre!=null) {
if (MotionDetection.USE_RGB) previous = ImageProcessing.rgbToBitmap(pre, width, height);
else previous = ImageProcessing.lumToGreyscale(img, width, height);
if (Globals.SAVE_PREVIOUS && pre!=null) {
if (Globals.USE_RGB) previous = ImageProcessing.rgbToBitmap(pre, width, height);
else previous = ImageProcessing.lumaToGreyscale(pre, width, height);
}

Bitmap original = null;
if (SAVE_ORIGINAL && org!=null) {
if (MotionDetection.USE_RGB) original = ImageProcessing.rgbToBitmap(org, width, height);
else original = ImageProcessing.lumToGreyscale(img, width, height);
if (Globals.SAVE_ORIGINAL && org!=null) {
if (Globals.USE_RGB) original = ImageProcessing.rgbToBitmap(org, width, height);
else original = ImageProcessing.lumaToGreyscale(org, width, height);
}

Bitmap bitmap = null;
if (SAVE_CHANGES && img!=null) {
if (MotionDetection.USE_RGB) bitmap = ImageProcessing.rgbToBitmap(img, width, height);
else bitmap = ImageProcessing.lumToGreyscale(img, width, height);
if (Globals.SAVE_CHANGES && img!=null) {
if (Globals.USE_RGB) bitmap = ImageProcessing.rgbToBitmap(img, width, height);
else bitmap = ImageProcessing.lumaToGreyscale(img, width, height);
}

Log.i(TAG,"Saving.. previous="+previous+" original="+original+" bitmap="+bitmap);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.jwetherell.motion_detection.detection;

import com.jwetherell.motion_detection.Globals;

import android.graphics.Color;
import android.util.Log;

Expand All @@ -21,10 +23,6 @@ public abstract class MotionDetection {
private static int mPreviousHeight = 0;
private static State mPreviousState = null;

public static final boolean USE_RGB = true;
public static final boolean USE_LUM = false;
public static final boolean USE_STATE = false;

public static int[] getPrevious() {
return ((mPrevious!=null)?mPrevious.clone():null);
}
Expand Down Expand Up @@ -150,9 +148,9 @@ public static boolean detect(int[] rgb, int width, int height) {

long bDetection = System.currentTimeMillis();
boolean motionDetected = false;
if (USE_RGB) motionDetected = isDifferentComparingRGB(rgb, width, height);
if (USE_LUM) motionDetected = isDifferentComparingLuminescence(rgb, width, height);
if (USE_STATE) motionDetected = isDifferentComparingState(rgb, width, height);
if (Globals.USE_RGB) motionDetected = isDifferentComparingRGB(rgb, width, height);
if (Globals.USE_LUMA) motionDetected = isDifferentComparingLuminescence(rgb, width, height);
if (Globals.USE_STATE) motionDetected = isDifferentComparingState(rgb, width, height);
long aDetection = System.currentTimeMillis();
Log.d(TAG, "Detection "+(aDetection-bDetection));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static int[] convertToHSL(int r, int g, int b) {
return (new int[]{(int)h,(int)s,(int)l});
}

public static int[] decodeYUV420SPtoLuminescence(byte[] yuv420sp, int width, int height) {
public static int[] decodeYUV420SPtoLuma(byte[] yuv420sp, int width, int height) {
if (yuv420sp==null) return null;

final int frameSize = width * height;
Expand Down Expand Up @@ -129,7 +129,7 @@ public static Bitmap rgbToBitmap(int[] rgb, int width, int height) {
return bitmap;
}

public static Bitmap lumToGreyscale(int[] lum, int width, int height) {
public static Bitmap lumaToGreyscale(int[] lum, int width, int height) {
if (lum==null) return null;

Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
Expand Down

0 comments on commit cf986f1

Please sign in to comment.