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