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 8c988d15..e32f47f2 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 void addListener(MotionListener listener) { 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 void setMotionSensitivity (int motionSensitivity) 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 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 ee277936..1f2adcf6 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 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 CameraViewHolder(Activity context, CameraView cameraView) { 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 void setMotionSensitivity (int { this. motionSensitivity = motionSensitivity; - task.setMotionSensitivity(motionSensitivity); + motionDetector.setMotionSensitivity(motionSensitivity); } public void addListener(MotionDetector.MotionListener listener) { @@ -304,10 +304,7 @@ private void recordNewFrame (Frame frame) 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 @@ private void processNewFrame (Frame frame) 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; }