Implemented VideoDetector as a child class of abstract class Detector

This commit is contained in:
Bastian Kohler 2023-05-28 21:16:17 +02:00
parent 37617dbd54
commit 62a528d33b
2 changed files with 7 additions and 28 deletions

View File

@ -1,6 +1,5 @@
package com.example.ueberwachungssystem; package com.example.ueberwachungssystem;
import android.content.Context;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -8,7 +7,7 @@ abstract public class Detector {
private OnDetectionListener listener; private OnDetectionListener listener;
/** Constructor - takes context of current activity */ /** Constructor - takes context of current activity */
public Detector(Context context) {}; public Detector() {};
/** On Detection Listener - runs when violation is reported */ /** On Detection Listener - runs when violation is reported */

View File

@ -17,14 +17,14 @@ import androidx.camera.view.PreviewView;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
import com.example.ueberwachungssystem.DetectionReport; import com.example.ueberwachungssystem.Detector;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ExperimentalGetImage @ExperimentalGetImage
public class VideoDetector { public class VideoDetector extends Detector {
// Calling Activity // Calling Activity
private final Context context; private final Context context;
@ -36,39 +36,18 @@ public class VideoDetector {
// Check Violation // Check Violation
private final float DELTA_LUMINOSITY_THRESHOLD = 1.5f; private final float DELTA_LUMINOSITY_THRESHOLD = 1.5f;
private Float previousLuminosity = null; private Float previousLuminosity = null;
// On Detection Listener
private OnDetectionListener listener;
/** Constructor */ /** Constructor */
public VideoDetector(Context context) { public VideoDetector(Context context) {
super();
this.context = context; this.context = context;
} }
/** On Detection Listener - runs when a violation is reported */
public interface OnDetectionListener {
void onDetection(DetectionReport detectionReport);
}
public void setOnDetectionListener(OnDetectionListener listener) {
this.listener = listener;
}
private void reportViolation(float amplitude) {
if (listener != null) {
DetectionReport detectionReport = new DetectionReport("123", "Video", amplitude);
listener.onDetection(detectionReport);
}
}
/** Return State of Video Detector */
public Boolean isRunning() {
return isDetectionRunning;
}
/** Starts Video Detection */ /** Starts Video Detection */
@Override
public void startDetection() { public void startDetection() {
if (isDetectionRunning) if (isDetectionRunning)
return; return;
@ -91,6 +70,7 @@ public class VideoDetector {
/** Stops Video Detection */ /** Stops Video Detection */
@Override
public void stopDetection() { public void stopDetection() {
if (!isDetectionRunning) if (!isDetectionRunning)
return; return;
@ -173,7 +153,7 @@ public class VideoDetector {
private void checkForViolation(float luminosity, float previousLuminosity) { private void checkForViolation(float luminosity, float previousLuminosity) {
float deltaLuminosity = Math.abs(luminosity - previousLuminosity); float deltaLuminosity = Math.abs(luminosity - previousLuminosity);
if (deltaLuminosity > DELTA_LUMINOSITY_THRESHOLD) { if (deltaLuminosity > DELTA_LUMINOSITY_THRESHOLD) {
reportViolation(luminosity); reportViolation("1232", "Video",luminosity);
Log.d("Violation", "Violation"); Log.d("Violation", "Violation");
} }
Log.d("Delta", String.valueOf(Math.abs(previousLuminosity - luminosity))); Log.d("Delta", String.valueOf(Math.abs(previousLuminosity - luminosity)));