Skip to content

Commit

Permalink
code cleanup; changed detection interval to 200ms from 300ms
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Feb 10, 2019
1 parent c9ba5e5 commit bf09efa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
19 changes: 3 additions & 16 deletions src/main/java/org/havenapp/main/sensors/motion/MotionDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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<Integer> changedPixels =
detector.detectMotion(ImageCodec.N21toLuma(rawOldPic, width, height), newPicLuma, width, height);

Expand Down
20 changes: 7 additions & 13 deletions src/main/java/org/havenapp/main/ui/CameraViewHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -194,7 +194,7 @@ public void setMotionSensitivity (int
{
this.
motionSensitivity = motionSensitivity;
task.setMotionSensitivity(motionSensitivity);
motionDetector.setMotionSensitivity(motionSensitivity);
}

public void addListener(MotionDetector.MotionListener listener) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit bf09efa

Please sign in to comment.