Compare commits
No commits in common. "1576719d10e3246acaae7eaf82b2eb63a49b4b03" and "bef5d034941c6dccd58ef052c0aeba90d5a1d6fa" have entirely different histories.
1576719d10
...
bef5d03494
@ -15,17 +15,13 @@ import androidx.lifecycle.LifecycleOwner;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.example.ueberwachungssystem.VideoDetection.DetectionReport;
|
|
||||||
import com.example.ueberwachungssystem.VideoDetection.VideoDetector;
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
@ExperimentalGetImage
|
@ExperimentalGetImage
|
||||||
@ -51,15 +47,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
VideoDetector vd = new VideoDetector(this);
|
VideoDetector vd = new VideoDetector(this);
|
||||||
vd.setPreviewView(previewView);
|
vd.setPreviewView(previewView);
|
||||||
vd.setOnDetectionListener(new VideoDetector.OnDetectionListener() {
|
|
||||||
@Override
|
|
||||||
public void onDetection(DetectionReport detectionReport) {
|
|
||||||
Log.d("Listener", detectionReport.detectionType);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
vd.startDetection();
|
vd.startDetection();
|
||||||
|
|
||||||
|
|
||||||
previewButton.setOnClickListener(new View.OnClickListener() {
|
previewButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
package com.example.ueberwachungssystem.VideoDetection;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
|
|
||||||
/** Detection Report Class */
|
|
||||||
|
|
||||||
public class DetectionReport {
|
|
||||||
public String timeStamp;
|
|
||||||
public String detectionType;
|
|
||||||
public float detectedAmplitude;
|
|
||||||
public String detectorID;
|
|
||||||
|
|
||||||
public DetectionReport(String detectorID, String detectionType, float detectedAmplitude) {
|
|
||||||
this.timeStamp = String.valueOf(Calendar.getInstance().getTime());
|
|
||||||
this.detectionType = detectionType;
|
|
||||||
this.detectedAmplitude = detectedAmplitude;
|
|
||||||
this.detectorID = detectorID;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.example.ueberwachungssystem.VideoDetection;
|
package com.example.ueberwachungssystem;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.ImageFormat;
|
import android.graphics.ImageFormat;
|
||||||
@ -22,7 +22,6 @@ 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 {
|
||||||
// Calling Activity
|
// Calling Activity
|
||||||
@ -33,36 +32,24 @@ public class VideoDetector {
|
|||||||
// Preview Camera Image
|
// Preview Camera Image
|
||||||
private PreviewView previewView = null;
|
private PreviewView previewView = null;
|
||||||
// Check Violation
|
// Check Violation
|
||||||
private final float DELTA_LUMINOSITY_THRESHOLD = 0.5f;
|
private final float DELTA_LUMINOSITY_THRESHOLD = 10f;
|
||||||
private float previousLuminosity = 0f;
|
private float lastLuminosity = 0f;
|
||||||
// On Detection Listener
|
private Boolean isViolated = false;
|
||||||
private OnDetectionListener listener;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
public VideoDetector(Context context) { this.context = context; }
|
public VideoDetector(Context context) { this.context = context; }
|
||||||
|
|
||||||
|
|
||||||
/** On Detection Listener - runs when a violation is reported */
|
|
||||||
public interface OnDetectionListener {
|
|
||||||
public void onDetection(DetectionReport detectionReport);
|
|
||||||
}
|
|
||||||
public void setOnDetectionListener(OnDetectionListener listener) {
|
|
||||||
this.listener = listener;
|
|
||||||
}
|
|
||||||
public void reportViolation(float amplitude) {
|
|
||||||
DetectionReport detectionReport = new DetectionReport("123", "Video", amplitude);
|
|
||||||
if (listener != null)
|
|
||||||
listener.onDetection(detectionReport);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Return State of Video Detector */
|
/** Return State of Video Detector */
|
||||||
public Boolean isRunning() {
|
public Boolean isRunning() { return isDetectionRunning; }
|
||||||
return isDetectionRunning;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/** Return the status of Violation */
|
||||||
|
public boolean getViolationStatus()
|
||||||
|
{
|
||||||
|
return isViolated;
|
||||||
|
}
|
||||||
|
|
||||||
/** Starts Video Detection */
|
/** Starts Video Detection */
|
||||||
public void startDetection() {
|
public void startDetection() {
|
||||||
@ -83,20 +70,17 @@ public class VideoDetector {
|
|||||||
},ContextCompat.getMainExecutor(context));
|
},ContextCompat.getMainExecutor(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Stops Video Detection */
|
/** Stops Video Detection */
|
||||||
public void stopDetection() {
|
public void stopDetection() {
|
||||||
cameraProvider.unbindAll();
|
cameraProvider.unbindAll();
|
||||||
isDetectionRunning = false;
|
isDetectionRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Set PreviewView to show Image */
|
/** Set PreviewView to show Image */
|
||||||
public void setPreviewView(PreviewView previewView) {
|
public void setPreviewView(PreviewView previewView) {
|
||||||
this.previewView = previewView;
|
this.previewView = previewView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Binds the Luminosity Analyzer (configure and run Analysis) */
|
/** Binds the Luminosity Analyzer (configure and run Analysis) */
|
||||||
private void bindLuminosityAnalysis(@NonNull ProcessCameraProvider cameraProvider) {
|
private void bindLuminosityAnalysis(@NonNull ProcessCameraProvider cameraProvider) {
|
||||||
// Configure and create Image Analysis
|
// Configure and create Image Analysis
|
||||||
@ -116,8 +100,9 @@ public class VideoDetector {
|
|||||||
// Analyze frame
|
// Analyze frame
|
||||||
float luminosity = calculateLuminosity(image);
|
float luminosity = calculateLuminosity(image);
|
||||||
Log.d("Video Detector", String.valueOf(luminosity));
|
Log.d("Video Detector", String.valueOf(luminosity));
|
||||||
checkForViolation(luminosity, previousLuminosity);
|
if (luminosity != 0)
|
||||||
previousLuminosity = luminosity;
|
checkForViolation(luminosity, lastLuminosity);
|
||||||
|
lastLuminosity = luminosity;
|
||||||
}
|
}
|
||||||
imageProxy.close();
|
imageProxy.close();
|
||||||
}
|
}
|
||||||
@ -133,7 +118,6 @@ public class VideoDetector {
|
|||||||
cameraProvider.bindToLifecycle((LifecycleOwner) context, cameraSelector, imageAnalysis, preview);
|
cameraProvider.bindToLifecycle((LifecycleOwner) context, cameraSelector, imageAnalysis, preview);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Return Luminosity from Image */
|
/** Return Luminosity from Image */
|
||||||
private float calculateLuminosity (Image image) {
|
private float calculateLuminosity (Image image) {
|
||||||
int width = image.getWidth();
|
int width = image.getWidth();
|
||||||
@ -158,12 +142,11 @@ public class VideoDetector {
|
|||||||
return sum / (width * height);
|
return sum / (width * height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Check if delta Luminosity exceeds threshold */
|
/** Check if delta Luminosity exceeds threshold */
|
||||||
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(deltaLuminosity);
|
isViolated = true;
|
||||||
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)));
|
Loading…
x
Reference in New Issue
Block a user