|
|
@@ -21,21 +21,22 @@ import java.util.concurrent.ExecutionException; |
|
|
|
|
|
|
|
public class KameraAktivitaet extends AppCompatActivity { |
|
|
|
private PreviewView previewView; |
|
|
|
private TextView alarm; |
|
|
|
private TextView alarm2; |
|
|
|
private boolean isMotionDetected; |
|
|
|
|
|
|
|
private TextView alarm; |
|
|
|
private ByteBuffer previousBuffer; |
|
|
|
private int previousWidth; |
|
|
|
private int previousHeight; |
|
|
|
private boolean camera_alarm = false; |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
setContentView(R.layout.activity_demo_kamera2_nebenaktivitaet); |
|
|
|
alarm = findViewById(R.id.luminanz); |
|
|
|
alarm2 = findViewById(R.id.orientierung); |
|
|
|
previewView = findViewById(R.id.previewView); |
|
|
|
setContentView(R.layout.activity_main); |
|
|
|
alarm = findViewById(R.id.textView); |
|
|
|
|
|
|
|
// PREVIEW // |
|
|
|
//previewView = findViewById(R.id.previewView); |
|
|
|
|
|
|
|
final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(this); |
|
|
|
cameraProviderFuture.addListener(() -> { |
|
|
|
try { |
|
|
@@ -78,12 +79,28 @@ public class KameraAktivitaet extends AppCompatActivity { |
|
|
|
|
|
|
|
if (isMotionDetected) { |
|
|
|
|
|
|
|
// Code um den Alarm zu setzen aktuell noch über setText |
|
|
|
alarm.setText("ALARM"); |
|
|
|
camera_alarm = true; |
|
|
|
|
|
|
|
runOnUiThread(() -> { |
|
|
|
// Hier kannst du den Code für die Videoaufzeichnung oder andere Aktionen einfügen |
|
|
|
// Beispiel: starteVideoAufzeichnung(); |
|
|
|
|
|
|
|
// Platz um die Videoaufzeichnung zu starten |
|
|
|
|
|
|
|
}); |
|
|
|
} else { |
|
|
|
|
|
|
|
// Optional evtl nicht nötig |
|
|
|
if (camera_alarm) { |
|
|
|
/* |
|
|
|
try { |
|
|
|
Thread.sleep(2000); // Wartezeit wie lange der Alarm gesetzt sein soll bzw. die Aufzeichnung laufen soll |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} */ |
|
|
|
|
|
|
|
camera_alarm = false; |
|
|
|
} |
|
|
|
alarm.setText("OK"); |
|
|
|
} |
|
|
|
} |
|
|
@@ -92,12 +109,15 @@ public class KameraAktivitaet extends AppCompatActivity { |
|
|
|
|
|
|
|
Preview preview = new Preview.Builder().build(); |
|
|
|
CameraSelector cameraSelector = new CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build(); |
|
|
|
preview.setSurfaceProvider(previewView.getSurfaceProvider()); |
|
|
|
cameraProvider.bindToLifecycle(this, cameraSelector, imageAnalysis, preview); |
|
|
|
|
|
|
|
// PREVIEW // |
|
|
|
//preview.setSurfaceProvider(previewView.getSurfaceProvider()); |
|
|
|
|
|
|
|
cameraProvider.bindToLifecycle(this, cameraSelector, imageAnalysis, preview); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Bildverarbeitung zur Bewegungserkennung |
|
|
|
private boolean compareFrames(Image currentImage) { |
|
|
|
|
|
|
|
ByteBuffer currentBuffer = currentImage.getPlanes()[0].getBuffer(); |
|
|
@@ -105,34 +125,28 @@ public class KameraAktivitaet extends AppCompatActivity { |
|
|
|
int currentWidth = currentImage.getWidth(); |
|
|
|
int currentHeight = currentImage.getHeight(); |
|
|
|
|
|
|
|
// Überprüfe, ob die Größe der beiden Bilder übereinstimmt |
|
|
|
if (previousWidth != currentWidth || previousHeight != currentHeight) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// Überprüfe die Pixelwerte für jede Zeile und Spalte |
|
|
|
for (int row = 0; row < previousHeight; row++) { |
|
|
|
for (int col = 0; col < previousWidth; col++) { |
|
|
|
// Berechne den Index des aktuellen Pixels im ByteBuffer |
|
|
|
|
|
|
|
int previousIndex = row * previousWidth + col; |
|
|
|
int currentIndex = row * currentWidth + col; |
|
|
|
|
|
|
|
// Lese die Pixelwerte für den aktuellen Pixel |
|
|
|
int previousPixel = previousBuffer.get(previousIndex) & 0xFF; |
|
|
|
int currentPixel = currentBuffer.get(currentIndex) & 0xFF; |
|
|
|
|
|
|
|
// Vergleiche die Pixelwerte und prüfe auf einen signifikanten Unterschied |
|
|
|
int pixelDifference = Math.abs(previousPixel - currentPixel); |
|
|
|
int threshold = 120; |
|
|
|
|
|
|
|
if (pixelDifference > threshold) { |
|
|
|
String text = String.valueOf(pixelDifference); |
|
|
|
alarm2.setText(text); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |