Compare commits
4 Commits
54ba3b4862
...
c730eec9f9
Author | SHA1 | Date | |
---|---|---|---|
c730eec9f9 | |||
1aea88d08f | |||
43eac872ed | |||
39295f9780 |
@ -1,8 +1,11 @@
|
||||
package com.example.ueberwachungssystem.Detection;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.util.Log;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
/** Detection Report Class */
|
||||
public class DetectionReport {
|
||||
@ -12,7 +15,11 @@ public class DetectionReport {
|
||||
public boolean detectionState;
|
||||
|
||||
public DetectionReport(boolean detectionState, String detectionType, float detectedAmplitude) {
|
||||
this.timeStamp = String.valueOf(Calendar.getInstance().getTime());
|
||||
// New Date Format
|
||||
@SuppressLint("SimpleDateFormat") SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
||||
Date curDate = new Date(System.currentTimeMillis());
|
||||
this.timeStamp = formatter.format(curDate);
|
||||
//Old Date Format: this.timeStamp = String.valueOf(Calendar.getInstance().getTime());
|
||||
this.detectionType = detectionType;
|
||||
this.detectedValue = detectedAmplitude;
|
||||
this.detectionState = detectionState;
|
||||
|
@ -3,17 +3,13 @@ package com.example.ueberwachungssystem.Detection;
|
||||
import android.content.Intent;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.camera.core.ExperimentalGetImage;
|
||||
import androidx.lifecycle.LifecycleService;
|
||||
|
||||
import com.example.ueberwachungssystem.WifiCommunication;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@ExperimentalGetImage
|
||||
@ -22,10 +18,11 @@ public class DetectorService extends LifecycleService {
|
||||
private DetectorService.OnDetectionListener listener;
|
||||
private boolean isServiceRunning = false;
|
||||
|
||||
VideoDetector videoDetector = null;
|
||||
AudioRecorder audioRecorder = null;
|
||||
Accelerometer accelerometer = null;
|
||||
MicrophoneDetector microphoneDetector = null;
|
||||
// Used Objects:
|
||||
public VideoDetector videoDetector = null;
|
||||
public AudioRecorder audioRecorder = null;
|
||||
public Accelerometer motionDetector = null;
|
||||
public MicrophoneDetector audioDetector = null;
|
||||
|
||||
|
||||
@Override
|
||||
@ -33,6 +30,9 @@ public class DetectorService extends LifecycleService {
|
||||
if (isServiceRunning)
|
||||
return START_NOT_STICKY;
|
||||
|
||||
|
||||
|
||||
|
||||
/** Video Detection/Recorder **/
|
||||
videoDetector = new VideoDetector(this);
|
||||
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||
@ -42,17 +42,17 @@ public class DetectorService extends LifecycleService {
|
||||
}
|
||||
});
|
||||
/** Motion Detection**/
|
||||
accelerometer = new Accelerometer(this);
|
||||
accelerometer.getSensor();
|
||||
accelerometer.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||
motionDetector = new Accelerometer(this);
|
||||
motionDetector.getSensor();
|
||||
motionDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||
@Override
|
||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||
passToServiceListener(detectionReport);
|
||||
}
|
||||
});
|
||||
/** Audio Detection **/
|
||||
microphoneDetector = new MicrophoneDetector(this);
|
||||
microphoneDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||
audioDetector = new MicrophoneDetector(this);
|
||||
audioDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||
@Override
|
||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||
passToServiceListener(detectionReport);
|
||||
@ -63,9 +63,13 @@ public class DetectorService extends LifecycleService {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
isServiceRunning = true;
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
@ -108,22 +112,22 @@ public class DetectorService extends LifecycleService {
|
||||
|
||||
/** Audio Detection */
|
||||
public void startAudioDetection() {
|
||||
if(microphoneDetector != null)
|
||||
microphoneDetector.startDetection();
|
||||
if(audioDetector != null)
|
||||
audioDetector.startDetection();
|
||||
}
|
||||
public void stopAudioDetection() {
|
||||
if(microphoneDetector != null)
|
||||
microphoneDetector.stopDetection();
|
||||
if(audioDetector != null)
|
||||
audioDetector.stopDetection();
|
||||
}
|
||||
|
||||
/** Motion Detection */
|
||||
public void startMotionDetection() {
|
||||
if(accelerometer != null)
|
||||
accelerometer.startDetection();
|
||||
if(motionDetector != null)
|
||||
motionDetector.startDetection();
|
||||
}
|
||||
public void stopMotionDetection() {
|
||||
if(accelerometer != null)
|
||||
accelerometer.stopDetection();
|
||||
if(motionDetector != null)
|
||||
motionDetector.stopDetection();
|
||||
}
|
||||
|
||||
/** Video Recording */
|
||||
@ -165,7 +169,7 @@ public class DetectorService extends LifecycleService {
|
||||
}
|
||||
|
||||
|
||||
/** pass Detection Report to Service Detection Listener and trigger it */
|
||||
/** Pass Detection Report to Service Detection Listener and trigger it */
|
||||
public void passToServiceListener(DetectionReport detectionReport) {
|
||||
if (listener != null) {
|
||||
listener.onDetection(detectionReport);
|
||||
|
@ -42,8 +42,6 @@ import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* Video Detector inherits some methods from abstract Detector class (more info there)
|
||||
* USE FROM MAIN ACTIVITY:
|
||||
* VideoDetector vd = new VideoDetector(this);
|
||||
* */
|
||||
|
||||
|
||||
@ -175,7 +173,10 @@ public class VideoDetector extends Detector {
|
||||
public void stopDetection() {
|
||||
if (!isDetecting || imageAnalysis == null)
|
||||
return;
|
||||
cameraProvider.unbind(imageAnalysis);
|
||||
if (!isRecording)
|
||||
cameraProvider.unbindAll();
|
||||
else
|
||||
cameraProvider.unbind(imageAnalysis);
|
||||
isDetecting = false;
|
||||
allowReportViolation = false;
|
||||
}
|
||||
@ -187,7 +188,11 @@ public class VideoDetector extends Detector {
|
||||
return;
|
||||
|
||||
videoCapture.stopRecording();
|
||||
cameraProvider.unbind(videoCapture);
|
||||
|
||||
if (!isDetecting())
|
||||
cameraProvider.unbindAll();
|
||||
else
|
||||
cameraProvider.unbind(videoCapture);
|
||||
isRecording = false;
|
||||
}
|
||||
|
||||
@ -219,12 +224,12 @@ public class VideoDetector extends Detector {
|
||||
|
||||
int n = OpenCVHelper.countNonZeroPixels(processed);
|
||||
int pixelCount = image.getWidth() * image.getHeight();
|
||||
float percentChanged = (float) n / pixelCount;
|
||||
float percentChanged = ((float) n / pixelCount) * 100;
|
||||
|
||||
// Violation Condition
|
||||
if (percentChanged * 100 > ALARM_THRESHOLD) {
|
||||
if (percentChanged> ALARM_THRESHOLD) {
|
||||
if (allowReportViolation)
|
||||
reportViolation("Video", percentChanged * 100);
|
||||
reportViolation("Video", percentChanged);
|
||||
}
|
||||
}
|
||||
imageProxy.close();
|
||||
@ -310,7 +315,7 @@ public class VideoDetector extends Detector {
|
||||
|
||||
/** Start delay until Violation Report is allowed */
|
||||
private void startViolationTimer(float setupTime) {
|
||||
new CountDownTimer((long) (START_DELAY), 100) {
|
||||
new CountDownTimer((long) (setupTime), 100) {
|
||||
@Override
|
||||
public void onTick(long millisUntilFinished) {
|
||||
}
|
||||
|
@ -5,7 +5,12 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.camera.core.ExperimentalGetImage;
|
||||
import androidx.camera.view.PreviewView;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
@ -15,77 +20,61 @@ import com.example.ueberwachungssystem.Detection.Accelerometer;
|
||||
import com.example.ueberwachungssystem.Detection.AudioRecorder;
|
||||
import com.example.ueberwachungssystem.Detection.DetectionReport;
|
||||
import com.example.ueberwachungssystem.Detection.Detector;
|
||||
import com.example.ueberwachungssystem.Detection.DetectorService;
|
||||
import com.example.ueberwachungssystem.Detection.MicrophoneDetector;
|
||||
import com.example.ueberwachungssystem.Detection.VideoDetector;
|
||||
|
||||
@ExperimentalGetImage
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private DetectorService detectorService = new DetectorService();
|
||||
ImageView inputImageView;
|
||||
ImageView outputImageView;
|
||||
ToggleButton toggleButton;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
|
||||
ImageView inputImageView = findViewById(R.id.inputImageView);
|
||||
ImageView outputImageView = findViewById(R.id.outputImageView);
|
||||
PreviewView previewView = findViewById(R.id.previewView);
|
||||
inputImageView = findViewById(R.id.inputImageView);
|
||||
outputImageView = findViewById(R.id.outputImageView);
|
||||
toggleButton = findViewById(R.id.toggleButton);
|
||||
|
||||
|
||||
PermissionHandler permissionHandler = new PermissionHandler(this);
|
||||
|
||||
|
||||
permissionHandler.getPermissions();
|
||||
|
||||
if (permissionHandler.hasPermissions()) {
|
||||
AudioRecorder audioRecorder = new AudioRecorder(this);
|
||||
|
||||
VideoDetector vd = new VideoDetector(this);
|
||||
//vd.debugProcessing(inputImageView, outputImageView);
|
||||
vd.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||
@Override
|
||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||
Log.d("onDetection", detectionReport.toString());
|
||||
}
|
||||
});
|
||||
|
||||
MicrophoneDetector microphoneDetector = new MicrophoneDetector(this);
|
||||
microphoneDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||
@Override
|
||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||
Log.d("onDetection", detectionReport.toString());
|
||||
}
|
||||
});
|
||||
|
||||
Accelerometer accelerometer = new Accelerometer(this);
|
||||
accelerometer.getSensor();
|
||||
accelerometer.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||
@Override
|
||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||
Log.d("onDetection", detectionReport.toString());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ToggleButton toggleButton = findViewById(R.id.toggleButton);
|
||||
Intent serviceIntent = new Intent(this, DetectorService.class);
|
||||
bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||
startService(serviceIntent);
|
||||
|
||||
|
||||
toggleButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (toggleButton.isChecked())
|
||||
{
|
||||
//vd.startDetection();
|
||||
//vd.stopDetection();
|
||||
vd.startDetection();
|
||||
microphoneDetector.startDetection();
|
||||
accelerometer.startDetection();
|
||||
if (detectorService != null){
|
||||
|
||||
vd.startRecording();
|
||||
audioRecorder.startRecording();
|
||||
detectorService.debugVideoProcessing(inputImageView, outputImageView);
|
||||
detectorService.startVideoDetection();
|
||||
detectorService.startAudioDetection();
|
||||
detectorService.startMotionDetection();
|
||||
detectorService.startVideoRecording();
|
||||
detectorService.startAudioRecording();
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
//vd.stopDetection();
|
||||
vd.stopRecording();
|
||||
audioRecorder.stopRecording();
|
||||
detectorService.stopVideoDetection();
|
||||
detectorService.stopAudioDetection();
|
||||
detectorService.stopMotionDetection();
|
||||
detectorService.stopVideoRecording();
|
||||
detectorService.stopAudioRecording();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -97,6 +86,22 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ServiceConnection serviceConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
DetectorService.ServiceBinder binder = (DetectorService.ServiceBinder) service;
|
||||
detectorService = binder.getBoundService();
|
||||
|
||||
detectorService.setOnDetectionListener(new DetectorService.OnDetectionListener() {
|
||||
@Override
|
||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||
Log.d("onDetection", detectionReport.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {}
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user