|
|
|
|
|
|
|
|
import android.media.Image; |
|
|
import android.media.Image; |
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
import android.os.Handler; |
|
|
import android.os.Handler; |
|
|
import android.util.Log; |
|
|
|
|
|
import android.util.Size; |
|
|
import android.util.Size; |
|
|
|
|
|
|
|
|
import android.widget.TextView; |
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
|
// PREVIEW |
|
|
// PREVIEW |
|
|
// private PreviewView previewView; |
|
|
// private PreviewView previewView; |
|
|
private boolean isMotionDetected; |
|
|
private boolean isMotionDetected; |
|
|
private boolean camera_alarm; |
|
|
|
|
|
|
|
|
private boolean camera_alarm = false; |
|
|
private TextView alarm; |
|
|
private TextView alarm; |
|
|
private TextView test; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Bildverarbeitung Variablen |
|
|
// Bildverarbeitung Variablen |
|
|
private ByteBuffer previousBuffer; |
|
|
private ByteBuffer previousBuffer; |
|
|
private int previousWidth; |
|
|
private int previousWidth; |
|
|
private int previousHeight; |
|
|
private int previousHeight; |
|
|
private int threshold = 50; |
|
|
|
|
|
|
|
|
private final int threshold = 50; |
|
|
private int startX; |
|
|
private int startX; |
|
|
private int startY; |
|
|
private int startY; |
|
|
private int endX; |
|
|
private int endX; |
|
|
private int endY; |
|
|
private int endY; |
|
|
|
|
|
|
|
|
private static final long ALARM_RESET_DELAY = 5000; |
|
|
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 |
|
|
@Override |
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NUR FÜR TESTS |
|
|
// NUR FÜR TESTS |
|
|
alarm = findViewById(R.id.textView); |
|
|
alarm = findViewById(R.id.textView); |
|
|
test = findViewById(R.id.textView2); |
|
|
|
|
|
|
|
|
|
|
|
// PREVIEW // |
|
|
|
|
|
// previewView = findViewById(R.id.previewView); |
|
|
// previewView = findViewById(R.id.previewView); |
|
|
|
|
|
|
|
|
final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(this); |
|
|
final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(this); |
|
|
|
|
|
|
|
|
currentImage.close(); |
|
|
currentImage.close(); |
|
|
|
|
|
|
|
|
if (isMotionDetected) { |
|
|
if (isMotionDetected) { |
|
|
|
|
|
|
|
|
alarm.setText("ALARM"); |
|
|
alarm.setText("ALARM"); |
|
|
camera_alarm = true; |
|
|
camera_alarm = true; |
|
|
|
|
|
|
|
|
|
|
|
if(alarmResetRunnable != null) { |
|
|
|
|
|
alarmResetHandler.removeCallbacks(alarmResetRunnable); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
alarmResetRunnable = this::resetAlarmStatus; |
|
|
alarmResetHandler.postDelayed(alarmResetRunnable, ALARM_RESET_DELAY); |
|
|
alarmResetHandler.postDelayed(alarmResetRunnable, ALARM_RESET_DELAY); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
float averageLuminance = (float) sumLuminance / countPixels; |
|
|
|
|
|
|
|
|
|
|
|
return averageLuminance; |
|
|
|
|
|
|
|
|
return (float) sumLuminance / countPixels; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private int kleinstesQuadrat(int height, int width) { |
|
|
private int kleinstesQuadrat(int height, int width) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|