Skip to content

armgit / haven

Public Imported from GitHub
0

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

code cleanup; changed detection interval to 200ms from 300ms

n8fr8bf09efa4a031
diff --git a/src/main/java/org/havenapp/main/sensors/motion/MotionDetector.java b/src/main/java/org/havenapp/main/sensors/motion/MotionDetector.java
index 8c988d1..e32f47f 100644
--- a/src/main/java/org/havenapp/main/sensors/motion/MotionDetector.java
+++ b/src/main/java/org/havenapp/main/sensors/motion/MotionDetector.java
@@ -41,12 +41,8 @@ public class MotionDetector {
private IMotionDetector detector;
- //private RenderScript renderScript;
-
- private int detectColor = Color.YELLOW;
-
public interface MotionListener {
- public void onProcess(
+ void onProcess(
Bitmap newBitmap,
Bitmap rawBitmap,
boolean motionDetected);
@@ -58,17 +54,11 @@ public class MotionDetector {
public MotionDetector(
int motionSensitivity) {
- // this.renderScript = renderScript;
this.motionSensitivity = motionSensitivity;
detector = new LuminanceMotionDetector();
+ detector.setThreshold(motionSensitivity);
-
- }
-
- public void setDetectColor (int detectColor)
- {
- this.detectColor = detectColor;
}
public void setMotionSensitivity (int motionSensitivity)
@@ -80,15 +70,12 @@ public class MotionDetector {
public void detect(byte[] rawOldPic,
byte[] rawNewPic,
int width,
- int height,
- int rotationDegrees,
- boolean facingFront) {
+ int height) {
int[] newPicLuma = ImageCodec.N21toLuma(rawNewPic, width, height);
if (rawOldPic != null) {
- detector.setThreshold(motionSensitivity);
List<Integer> changedPixels =
detector.detectMotion(ImageCodec.N21toLuma(rawOldPic, width, height), newPicLuma, width, height);
diff --git a/src/main/java/org/havenapp/main/ui/CameraViewHolder.java b/src/main/java/org/havenapp/main/ui/CameraViewHolder.java
index ee27793..1f2adcf 100644
--- a/src/main/java/org/havenapp/main/ui/CameraViewHolder.java
+++ b/src/main/java/org/havenapp/main/ui/CameraViewHolder.java
@@ -62,7 +62,7 @@ public class CameraViewHolder {
*/
private PreferenceManager prefs;
- private final static int DETECTION_INTERVAL_MS = 300;
+ private final static int DETECTION_INTERVAL_MS = 200;
private final static int MAX_CAMERA_WIDTH = 800;
private List<MotionDetector.MotionListener> listeners = new ArrayList<>();
@@ -102,7 +102,7 @@ public class CameraViewHolder {
private Messenger serviceMessenger = null;
//private Camera camera;
private Activity context;
- private MotionDetector task;
+ private MotionDetector motionDetector;
AndroidSequenceEncoder encoder;
private File videoFile;
@@ -133,10 +133,10 @@ public class CameraViewHolder {
prefs = new PreferenceManager(context);
- task = new MotionDetector(
+ motionDetector = new MotionDetector(
motionSensitivity);
- task.addListener((detectedImage, rawBitmap, motionDetected) -> {
+ motionDetector.addListener((detectedImage, rawBitmap, motionDetected) -> {
for (MotionDetector.MotionListener listener : listeners)
listener.onProcess(detectedImage,rawBitmap,motionDetected);
@@ -194,7 +194,7 @@ public class CameraViewHolder {
{
this.
motionSensitivity = motionSensitivity;
- task.setMotionSensitivity(motionSensitivity);
+ motionDetector.setMotionSensitivity(motionSensitivity);
}
public void addListener(MotionDetector.MotionListener listener) {
@@ -304,10 +304,7 @@ public class CameraViewHolder {
if (data != null && size != null) {
int width = size.getWidth();
int height = size.getHeight();
- int rotationDegrees = getCorrectCameraOrientation(cameraView.getFacing(), frame.getRotation());
-
Bitmap bitmap = MotionDetector.convertImage(data, width, height);
-
bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, mtxVideoRotate, true);
try {
@@ -354,15 +351,12 @@ public class CameraViewHolder {
if (data != null && size != null) {
int width = size.getWidth();
int height = size.getHeight();
- int rotationDegrees = getCorrectCameraOrientation(cameraView.getFacing(), frame.getRotation());
- task.detect(
+ motionDetector.detect(
lastPic,
data,
width,
- height,
- rotationDegrees,
- cameraView.getFacing() == Facing.FRONT);
+ height);
lastPic = data;
}