Haven is for people who need a way to protect their personal spaces and possessions without compromising their own privacy, through an Android app and on-device sensors
Fixed initialization of motion sensitivity threshold
Luca Bonatofb1c8dc54ac9
diff --git a/src/me/ziccard/secureit/codec/ImageCodec.java b/src/me/ziccard/secureit/codec/ImageCodec.javaindex 16d70d3..9b6f482 100644--- a/src/me/ziccard/secureit/codec/ImageCodec.java+++ b/src/me/ziccard/secureit/codec/ImageCodec.java@@ -18,12 +18,10 @@ public class ImageCodec {final int frameSize = width*height;int[] lumaImage = new int[frameSize];- for (int j = 0, yp = 0; j < height; j++) {- for (int i = 0; i < width; i++, yp++) {- int luminance = (0xff & ((int) YUVimage[yp])) - 16;- if (luminance < 0) luminance = 0;- lumaImage[yp] = luminance;- }+ for (int ij = 0; ij < height*width; ij++) {+ int luminance = (0xff & ((int) YUVimage[ij])) - 16;+ if (luminance < 0) luminance = 0;+ lumaImage[ij] = luminance;}return lumaImage;}@@ -42,7 +40,7 @@ public class ImageCodec {for(int y=0, xy=0; y<bitmap.getHeight(); y++) {for(int x=0; x<bitmap.getWidth(); x++, xy++) {int luma = lum[xy];- bitmap.setPixel(x,y,Color.argb(1,luma,luma,luma));+ bitmap.setPixel(x,y,Color.rgb(luma,luma,luma));}}return bitmap;diff --git a/src/me/ziccard/secureit/motiondetection/LuminanceMotionDetector.java b/src/me/ziccard/secureit/motiondetection/LuminanceMotionDetector.javaindex 7027d64..9cf6bbe 100644--- a/src/me/ziccard/secureit/motiondetection/LuminanceMotionDetector.java+++ b/src/me/ziccard/secureit/motiondetection/LuminanceMotionDetector.java@@ -3,12 +3,10 @@ package me.ziccard.secureit.motiondetection;import java.util.ArrayList;import java.util.List;-import android.graphics.Color;-public class LuminanceMotionDetector implements IMotionDetector {/**- * Difference in lumina for each pixel+ * Difference in luma for each pixel*/private int VALUE_THRESHOLD = 50;/**@@ -29,15 +27,18 @@ public class LuminanceMotionDetector implements IMotionDetector {*/public void setThreshold(int thresh) {switch(thresh) {- case MOTION_LOW:+ case MOTION_LOW:VALUE_THRESHOLD = 60;NUMBER_THRESHOLD = 20000;+ break;case MOTION_MEDIUM:VALUE_THRESHOLD = 50;NUMBER_THRESHOLD = 10000;+ break;case MOTION_HIGH:VALUE_THRESHOLD = 40;NUMBER_THRESHOLD = 9000;+ break;}}@@ -53,20 +54,18 @@ public class LuminanceMotionDetector implements IMotionDetector {ArrayList<Integer> differentPixels = new ArrayList<Integer>();int differentPixelNumber = 0;- for (int i = 0, ij=0; i < height; i++) {- for (int j = 0; j < width; j++, ij++) {- int newPixelValue = newImage[ij];- int oldPixelValue = oldImage[ij];- if (Math.abs(newPixelValue - oldPixelValue) >= VALUE_THRESHOLD) {- differentPixelNumber++;- differentPixels.add(ij);-- // sets RED new- newImage[ij] = Color.RED;- }- }+ for (int ij=0; ij < height*width; ij++) {+ int newPixelValue = newImage[ij];+ int oldPixelValue = oldImage[ij];+ if (Math.abs(newPixelValue - oldPixelValue) >= VALUE_THRESHOLD) {+ differentPixelNumber++;+ differentPixels.add(ij);+ }+ }++ if (differentPixelNumber > NUMBER_THRESHOLD) {+ return differentPixels;}- if (differentPixelNumber > NUMBER_THRESHOLD) return differentPixels;return null;}