|
|
@@ -4,7 +4,6 @@ import android.graphics.ImageFormat; |
|
|
|
import android.media.Image; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Handler; |
|
|
|
import android.util.Log; |
|
|
|
import android.util.Size; |
|
|
|
|
|
|
|
import android.widget.TextView; |
|
|
@@ -27,24 +26,22 @@ public class KameraAktivitaet extends AppCompatActivity { |
|
|
|
// PREVIEW |
|
|
|
// private PreviewView previewView; |
|
|
|
private boolean isMotionDetected; |
|
|
|
private boolean camera_alarm; |
|
|
|
private boolean camera_alarm = false; |
|
|
|
private TextView alarm; |
|
|
|
private TextView test; |
|
|
|
|
|
|
|
|
|
|
|
// Bildverarbeitung Variablen |
|
|
|
private ByteBuffer previousBuffer; |
|
|
|
private int previousWidth; |
|
|
|
private int previousHeight; |
|
|
|
private int threshold = 50; |
|
|
|
private final int threshold = 50; |
|
|
|
private int startX; |
|
|
|
private int startY; |
|
|
|
private int endX; |
|
|
|
private int endY; |
|
|
|
|
|
|
|
private static final long ALARM_RESET_DELAY = 5000; |
|
|
|
private boolean isAlarmSet = false; |
|
|
|
private Handler alarmResetHandler = new Handler(); |
|
|
|
private Runnable alarmResetRunnable; |
|
|
|
private final Handler alarmResetHandler = new Handler(); |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
@@ -53,9 +50,7 @@ public class KameraAktivitaet extends AppCompatActivity { |
|
|
|
|
|
|
|
// NUR FÜR TESTS |
|
|
|
alarm = findViewById(R.id.textView); |
|
|
|
test = findViewById(R.id.textView2); |
|
|
|
|
|
|
|
// PREVIEW // |
|
|
|
// previewView = findViewById(R.id.previewView); |
|
|
|
|
|
|
|
final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(this); |
|
|
@@ -99,9 +94,15 @@ public class KameraAktivitaet extends AppCompatActivity { |
|
|
|
currentImage.close(); |
|
|
|
|
|
|
|
if (isMotionDetected) { |
|
|
|
|
|
|
|
alarm.setText("ALARM"); |
|
|
|
camera_alarm = true; |
|
|
|
|
|
|
|
if(alarmResetRunnable != null) { |
|
|
|
alarmResetHandler.removeCallbacks(alarmResetRunnable); |
|
|
|
} |
|
|
|
|
|
|
|
alarmResetRunnable = this::resetAlarmStatus; |
|
|
|
alarmResetHandler.postDelayed(alarmResetRunnable, ALARM_RESET_DELAY); |
|
|
|
} |
|
|
|
} |
|
|
@@ -182,9 +183,7 @@ public class KameraAktivitaet extends AppCompatActivity { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
float averageLuminance = (float) sumLuminance / countPixels; |
|
|
|
|
|
|
|
return averageLuminance; |
|
|
|
return (float) sumLuminance / countPixels; |
|
|
|
} |
|
|
|
|
|
|
|
private int kleinstesQuadrat(int height, int width) { |
|
|
@@ -197,12 +196,10 @@ public class KameraAktivitaet extends AppCompatActivity { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private Runnable alarmResetRunnable = new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
camera_alarm = false; |
|
|
|
alarm.setText("OK"); |
|
|
|
} |
|
|
|
}; |
|
|
|
private void resetAlarmStatus() { |
|
|
|
camera_alarm = false; |
|
|
|
alarm.setText("OK"); |
|
|
|
alarmResetRunnable = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|