Implemented VideoDetector as a child class of abstract class Detector
This commit is contained in:
parent
37617dbd54
commit
62a528d33b
@ -1,6 +1,5 @@
|
||||
package com.example.ueberwachungssystem;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
|
||||
@ -8,7 +7,7 @@ abstract public class Detector {
|
||||
private OnDetectionListener listener;
|
||||
|
||||
/** Constructor - takes context of current activity */
|
||||
public Detector(Context context) {};
|
||||
public Detector() {};
|
||||
|
||||
|
||||
/** On Detection Listener - runs when violation is reported */
|
||||
|
@ -17,14 +17,14 @@ import androidx.camera.view.PreviewView;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import com.example.ueberwachungssystem.DetectionReport;
|
||||
import com.example.ueberwachungssystem.Detector;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@ExperimentalGetImage
|
||||
public class VideoDetector {
|
||||
public class VideoDetector extends Detector {
|
||||
|
||||
// Calling Activity
|
||||
private final Context context;
|
||||
@ -36,39 +36,18 @@ public class VideoDetector {
|
||||
// Check Violation
|
||||
private final float DELTA_LUMINOSITY_THRESHOLD = 1.5f;
|
||||
private Float previousLuminosity = null;
|
||||
// On Detection Listener
|
||||
private OnDetectionListener listener;
|
||||
|
||||
|
||||
|
||||
/** Constructor */
|
||||
public VideoDetector(Context context) {
|
||||
super();
|
||||
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 */
|
||||
@Override
|
||||
public void startDetection() {
|
||||
if (isDetectionRunning)
|
||||
return;
|
||||
@ -91,6 +70,7 @@ public class VideoDetector {
|
||||
|
||||
|
||||
/** Stops Video Detection */
|
||||
@Override
|
||||
public void stopDetection() {
|
||||
if (!isDetectionRunning)
|
||||
return;
|
||||
@ -173,7 +153,7 @@ public class VideoDetector {
|
||||
private void checkForViolation(float luminosity, float previousLuminosity) {
|
||||
float deltaLuminosity = Math.abs(luminosity - previousLuminosity);
|
||||
if (deltaLuminosity > DELTA_LUMINOSITY_THRESHOLD) {
|
||||
reportViolation(luminosity);
|
||||
reportViolation("1232", "Video",luminosity);
|
||||
Log.d("Violation", "Violation");
|
||||
}
|
||||
Log.d("Delta", String.valueOf(Math.abs(previousLuminosity - luminosity)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user