Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e01e23eccd | ||
|
|
a493bafb79 | ||
|
|
aed079377f | ||
|
|
bff6abbd29 | ||
|
|
5d31f0bb46 | ||
|
|
ea0e88ed89 |
No files matched your search
@@ -14,7 +14,6 @@ import java.io.File;
|
||||
|
||||
@ExperimentalGetImage
|
||||
public class DetectorService extends LifecycleService {
|
||||
|
||||
public ServiceBinder serviceBinder = new ServiceBinder();
|
||||
private DetectorService.OnDetectionListener listener;
|
||||
private boolean isServiceRunning = false;
|
||||
@@ -27,6 +26,9 @@ public class DetectorService extends LifecycleService {
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if (isServiceRunning)
|
||||
return START_NOT_STICKY;
|
||||
|
||||
|
||||
// Setup Service classes:
|
||||
videoDetector = new VideoDetector(this);
|
||||
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||
@Override
|
||||
@@ -38,8 +40,8 @@ public class DetectorService extends LifecycleService {
|
||||
audioRecorder = new AudioRecorder(this);
|
||||
|
||||
|
||||
isServiceRunning = true;
|
||||
|
||||
isServiceRunning = true;
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.example.ueberwachungssystem.Detection;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.ImageFormat;
|
||||
@@ -53,9 +52,6 @@ public class VideoDetector extends Detector {
|
||||
// Calling Activity
|
||||
private final Context context;
|
||||
|
||||
// Permission handling
|
||||
private static final int PERMISSION_REQUEST_CODE = 3691;
|
||||
|
||||
// Camera Provider
|
||||
private ProcessCameraProvider cameraProvider;
|
||||
private ImageAnalysis imageAnalysis;
|
||||
@@ -79,9 +75,11 @@ public class VideoDetector extends Detector {
|
||||
|
||||
|
||||
// Parameters
|
||||
private static final float ALARM_THRESHOLD = 0.5f; // Percent of pixels changed
|
||||
private static final float ALARM_THRESHOLD = 0f; // Percent of pixels changed
|
||||
private static final float AREA_THRESHOLD = 10f;
|
||||
private static final int DILATE_ITERATIONS = 2;
|
||||
private static final float START_DELAY = 20000; // milliseconds
|
||||
private static final android.util.Size IMAGE_RES = new android.util.Size(480, 360);
|
||||
private static final android.util.Size IMAGE_RES = new android.util.Size(640, 480);
|
||||
|
||||
|
||||
|
||||
@@ -110,11 +108,6 @@ public class VideoDetector extends Detector {
|
||||
// Check States
|
||||
if (isDetecting)
|
||||
return;
|
||||
// Return On Request Permissions
|
||||
if (!hasPermissions()) {
|
||||
getPermissions();
|
||||
return;
|
||||
}
|
||||
// Configure Image Analysis
|
||||
imageAnalysis = setupImageAnalysis();
|
||||
// Open CV startup check
|
||||
@@ -141,12 +134,6 @@ public class VideoDetector extends Detector {
|
||||
public void startRecording() {
|
||||
// Check States
|
||||
if (isRecording){
|
||||
extendViolation();
|
||||
return;
|
||||
}
|
||||
// Return On Request Permissions
|
||||
if (!hasPermissions()) {
|
||||
getPermissions();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -237,7 +224,7 @@ public class VideoDetector extends Detector {
|
||||
// Violation Condition
|
||||
if (percentChanged * 100 > ALARM_THRESHOLD) {
|
||||
if (allowReportViolation)
|
||||
reportViolation("Video", n);
|
||||
reportViolation("Video", percentChanged);
|
||||
}
|
||||
}
|
||||
imageProxy.close();
|
||||
@@ -274,9 +261,11 @@ public class VideoDetector extends Detector {
|
||||
// Process Image
|
||||
Mat processed = preprocessed.clone();
|
||||
processed = OpenCVHelper.thresholdPixels(processed, previousImage, 25);
|
||||
processed = OpenCVHelper.dilateBinaryMat(processed, new Size(3,3));
|
||||
processed = OpenCVHelper.dilateBinaryMat(processed, new Size(3,3));
|
||||
processed = OpenCVHelper.thresholdContourArea(processed, 500);
|
||||
|
||||
for(int i = 0; i < DILATE_ITERATIONS; i++)
|
||||
processed = OpenCVHelper.dilateBinaryMat(processed, new Size(3,3));
|
||||
|
||||
processed = OpenCVHelper.thresholdContourArea(processed, AREA_THRESHOLD);
|
||||
// Output
|
||||
previousImage = preprocessed.clone();
|
||||
// Show Output Image
|
||||
@@ -292,7 +281,6 @@ public class VideoDetector extends Detector {
|
||||
this.outputImageView = outputImageView;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
private void setPreviewView(@NonNull PreviewView previewView) {
|
||||
// Create Preview
|
||||
@@ -302,7 +290,6 @@ public class VideoDetector extends Detector {
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** Generate File Name */
|
||||
private String generateFileName(){
|
||||
// Get the current timestamp
|
||||
@@ -321,7 +308,6 @@ public class VideoDetector extends Detector {
|
||||
return display.getRotation();
|
||||
}
|
||||
|
||||
|
||||
/** Start delay until Violation Report is allowed */
|
||||
private void startViolationTimer(float setupTime) {
|
||||
new CountDownTimer((long) (START_DELAY), 100) {
|
||||
@@ -335,16 +321,6 @@ public class VideoDetector extends Detector {
|
||||
}.start();
|
||||
}
|
||||
|
||||
/** Permission handling */
|
||||
private boolean hasPermissions() {
|
||||
return ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED &&
|
||||
ContextCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
private void getPermissions() {
|
||||
if (!hasPermissions())
|
||||
ActivityCompat.requestPermissions((Activity) context, new String[]{android.Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO}, PERMISSION_REQUEST_CODE);
|
||||
}
|
||||
|
||||
public void setOutputDir(File outputDir) {
|
||||
this.outputDir = outputDir;
|
||||
}
|
||||
|
||||
@@ -30,39 +30,50 @@ public class MainActivity extends AppCompatActivity {
|
||||
PreviewView previewView = findViewById(R.id.previewView);
|
||||
|
||||
|
||||
VideoDetector vd = new VideoDetector(this);
|
||||
//vd.setPreviewView(previewView);
|
||||
vd.debugProcessing(inputImageView, outputImageView);
|
||||
vd.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||
@Override
|
||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||
Log.d("onDetection", detectionReport.toString());
|
||||
}
|
||||
});
|
||||
vd.startDetection();
|
||||
PermissionHandler permissionHandler = new PermissionHandler(this);
|
||||
|
||||
|
||||
AudioRecorder audioRecorder = new AudioRecorder(this);
|
||||
permissionHandler.getPermissions();
|
||||
|
||||
|
||||
|
||||
ToggleButton toggleButton = findViewById(R.id.toggleButton);
|
||||
toggleButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (toggleButton.isChecked())
|
||||
{
|
||||
//vd.startDetection();
|
||||
//vd.stopDetection();
|
||||
vd.startRecording();
|
||||
audioRecorder.startRecording();
|
||||
if (permissionHandler.hasPermissions()) {
|
||||
AudioRecorder audioRecorder = new AudioRecorder(this);
|
||||
VideoDetector vd = new VideoDetector(this);
|
||||
//vd.setPreviewView(previewView);
|
||||
vd.debugProcessing(inputImageView, outputImageView);
|
||||
vd.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||
@Override
|
||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||
Log.d("onDetection", detectionReport.toString());
|
||||
}
|
||||
else {
|
||||
//vd.stopDetection();
|
||||
vd.stopRecording();
|
||||
audioRecorder.stopRecording();
|
||||
});
|
||||
vd.startDetection();
|
||||
|
||||
ToggleButton toggleButton = findViewById(R.id.toggleButton);
|
||||
toggleButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (toggleButton.isChecked())
|
||||
{
|
||||
//vd.startDetection();
|
||||
//vd.stopDetection();
|
||||
vd.startRecording();
|
||||
audioRecorder.startRecording();
|
||||
}
|
||||
else {
|
||||
//vd.stopDetection();
|
||||
vd.stopRecording();
|
||||
audioRecorder.stopRecording();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.example.ueberwachungssystem;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
public class PermissionHandler {
|
||||
private final Context context;
|
||||
private static final int PERMISSION_REQUEST_CODE = 23409;
|
||||
private static final String[] permissions = new String[]{
|
||||
android.Manifest.permission.CAMERA,
|
||||
android.Manifest.permission.RECORD_AUDIO
|
||||
};
|
||||
|
||||
public PermissionHandler(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public boolean hasPermissions() {
|
||||
boolean permissionState = true;
|
||||
for (String permission: permissions) {
|
||||
permissionState = permissionState && ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
return permissionState;
|
||||
}
|
||||
|
||||
public void getPermissions() {
|
||||
if (!hasPermissions())
|
||||
ActivityCompat.requestPermissions((Activity) context, permissions, PERMISSION_REQUEST_CODE);
|
||||
}
|
||||
|
||||
public void showPermissionToast() {
|
||||
if (hasPermissions())
|
||||
Toast.makeText(context, "permissions available", Toast.LENGTH_SHORT).show();
|
||||
else
|
||||
Toast.makeText(context, "permissions missing", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user