diff --git a/app/src/main/java/com/example/ueberwachungssystem/DetectionReport.java b/app/src/main/java/com/example/ueberwachungssystem/Detection/DetectionReport.java similarity index 95% rename from app/src/main/java/com/example/ueberwachungssystem/DetectionReport.java rename to app/src/main/java/com/example/ueberwachungssystem/Detection/DetectionReport.java index bfcb52c..2dc8cba 100644 --- a/app/src/main/java/com/example/ueberwachungssystem/DetectionReport.java +++ b/app/src/main/java/com/example/ueberwachungssystem/Detection/DetectionReport.java @@ -1,4 +1,4 @@ -package com.example.ueberwachungssystem; +package com.example.ueberwachungssystem.Detection; import android.util.Log; diff --git a/app/src/main/java/com/example/ueberwachungssystem/Detector.java b/app/src/main/java/com/example/ueberwachungssystem/Detection/Detector.java similarity index 96% rename from app/src/main/java/com/example/ueberwachungssystem/Detector.java rename to app/src/main/java/com/example/ueberwachungssystem/Detection/Detector.java index 7f00656..0b726a7 100644 --- a/app/src/main/java/com/example/ueberwachungssystem/Detector.java +++ b/app/src/main/java/com/example/ueberwachungssystem/Detection/Detector.java @@ -1,4 +1,4 @@ -package com.example.ueberwachungssystem; +package com.example.ueberwachungssystem.Detection; import androidx.annotation.NonNull; diff --git a/app/src/main/java/com/example/ueberwachungssystem/VideoDetection/VideoDetector.java b/app/src/main/java/com/example/ueberwachungssystem/Detection/VideoDetector.java similarity index 96% rename from app/src/main/java/com/example/ueberwachungssystem/VideoDetection/VideoDetector.java rename to app/src/main/java/com/example/ueberwachungssystem/Detection/VideoDetector.java index babb677..a9c2a9d 100644 --- a/app/src/main/java/com/example/ueberwachungssystem/VideoDetection/VideoDetector.java +++ b/app/src/main/java/com/example/ueberwachungssystem/Detection/VideoDetector.java @@ -1,4 +1,4 @@ -package com.example.ueberwachungssystem.VideoDetection; +package com.example.ueberwachungssystem.Detection; import android.content.Context; import android.graphics.ImageFormat; @@ -15,7 +15,6 @@ import androidx.camera.view.PreviewView; import androidx.core.content.ContextCompat; import androidx.lifecycle.LifecycleOwner; -import com.example.ueberwachungssystem.Detector; import com.google.common.util.concurrent.ListenableFuture; import java.nio.ByteBuffer; @@ -33,7 +32,7 @@ public class VideoDetector extends Detector { private PreviewView previewView = null; // Detect Violation private static final float PIXEL_THRESHOLD = 30f; // Luminosity (brightness channel of YUV_420_888) - private static final float ALARM_THRESHOLD = 1f; // Percent of pixels changed + private static final float ALARM_THRESHOLD = 0.2f; // Percent of pixels changed private ByteBuffer previousBuffer = null; diff --git a/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java b/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java index 1173b49..f4fdae7 100644 --- a/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java +++ b/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java @@ -1,86 +1,14 @@ package com.example.ueberwachungssystem; -import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; -import androidx.camera.view.PreviewView; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; -import androidx.camera.core.ExperimentalGetImage; -import android.Manifest; -import android.content.pm.PackageManager; import android.os.Bundle; -import android.view.View; -import android.widget.TextView; -import android.widget.Toast; -import android.widget.ToggleButton; -import com.example.ueberwachungssystem.VideoDetection.VideoDetector; - -@ExperimentalGetImage public class MainActivity extends AppCompatActivity { - private static final int CAMERA_PERMISSION_REQUEST_CODE = 101; - - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - - TextView textView = findViewById(R.id.textView); - PreviewView previewView = findViewById(R.id.previewView); - - - VideoDetector vd = new VideoDetector(this); - vd.setPreviewView(previewView); - vd.setOnDetectionListener(new VideoDetector.OnDetectionListener() { - @Override - public void onDetection(@NonNull DetectionReport detectionReport) { - detectionReport.log("OnDetection"); - textView.setText(detectionReport.toString()); - } - }); - //vd.startDetection(); - - - ToggleButton toggleButton = findViewById(R.id.previewButton); - toggleButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - getCameraAccess(); - if (isCameraAccessAllowed() && toggleButton.isChecked()) - { - vd.startDetection(); - } - else { - vd.stopDetection(); - textView.setText(""); - } - } - }); - } - - private boolean isCameraAccessAllowed() { - return ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED; - } - - private void getCameraAccess() { - if (!isCameraAccessAllowed()) - ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.CAMERA}, CAMERA_PERMISSION_REQUEST_CODE); - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - - if (requestCode == CAMERA_PERMISSION_REQUEST_CODE && grantResults.length > 0) { - boolean cameraRights = grantResults[0] == PackageManager.PERMISSION_GRANTED; - if (cameraRights) { - Toast.makeText(this, "camera permission granted", Toast.LENGTH_LONG).show(); - } else { - Toast.makeText(this, "camera permission denied", Toast.LENGTH_LONG).show(); - } - } } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 275c453..17eab17 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,37 +1,18 @@ - - - - - - - - \ No newline at end of file + \ No newline at end of file