|
|
@@ -4,14 +4,15 @@ import android.graphics.ImageFormat; |
|
|
|
import android.media.Image; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.util.Size; |
|
|
|
|
|
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
import androidx.camera.core.CameraSelector; |
|
|
|
import androidx.camera.core.ImageAnalysis; |
|
|
|
import androidx.camera.core.Preview; |
|
|
|
import androidx.camera.lifecycle.ProcessCameraProvider; |
|
|
|
import androidx.camera.view.PreviewView; |
|
|
|
// PREVIEW |
|
|
|
//import androidx.camera.view.PreviewView; |
|
|
|
import androidx.core.content.ContextCompat; |
|
|
|
|
|
|
|
import com.google.common.util.concurrent.ListenableFuture; |
|
|
@@ -20,22 +21,26 @@ import java.nio.ByteBuffer; |
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
|
|
|
|
public class KameraAktivitaet extends AppCompatActivity { |
|
|
|
private PreviewView previewView; |
|
|
|
|
|
|
|
// PREVIEW |
|
|
|
// private PreviewView previewView; |
|
|
|
private boolean isMotionDetected; |
|
|
|
private boolean camera_alarm; |
|
|
|
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_main); |
|
|
|
|
|
|
|
// NUR FÜR TESTS |
|
|
|
alarm = findViewById(R.id.textView); |
|
|
|
|
|
|
|
// PREVIEW // |
|
|
|
//previewView = findViewById(R.id.previewView); |
|
|
|
// previewView = findViewById(R.id.previewView); |
|
|
|
|
|
|
|
final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(this); |
|
|
|
cameraProviderFuture.addListener(() -> { |
|
|
@@ -78,42 +83,26 @@ public class KameraAktivitaet extends AppCompatActivity { |
|
|
|
currentImage.close(); |
|
|
|
|
|
|
|
if (isMotionDetected) { |
|
|
|
|
|
|
|
// Code um den Alarm zu setzen aktuell noch über setText |
|
|
|
alarm.setText("ALARM"); |
|
|
|
camera_alarm = true; |
|
|
|
|
|
|
|
runOnUiThread(() -> { |
|
|
|
|
|
|
|
// 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; |
|
|
|
} |
|
|
|
} else { |
|
|
|
camera_alarm = false; |
|
|
|
alarm.setText("OK"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
imageProxy.close(); |
|
|
|
}); |
|
|
|
|
|
|
|
Preview preview = new Preview.Builder().build(); |
|
|
|
// Preview preview = new Preview.Builder().build(); |
|
|
|
|
|
|
|
CameraSelector cameraSelector = new CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build(); |
|
|
|
|
|
|
|
// PREVIEW // |
|
|
|
//preview.setSurfaceProvider(previewView.getSurfaceProvider()); |
|
|
|
// preview.setSurfaceProvider(previewView.getSurfaceProvider()); |
|
|
|
|
|
|
|
cameraProvider.bindToLifecycle(this, cameraSelector, imageAnalysis, preview); |
|
|
|
cameraProvider.bindToLifecycle(this, cameraSelector, imageAnalysis); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@@ -142,12 +131,12 @@ public class KameraAktivitaet extends AppCompatActivity { |
|
|
|
int threshold = 120; |
|
|
|
|
|
|
|
if (pixelDifference > threshold) { |
|
|
|
String text = String.valueOf(pixelDifference); |
|
|
|
// Testzwecke |
|
|
|
//String text = String.valueOf(pixelDifference); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |