Compare commits
4
Commits
5d31f0bb46
...
bk_video
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e01e23eccd | ||
|
|
a493bafb79 | ||
|
|
aed079377f | ||
|
|
bff6abbd29 |
No files matched your search
@@ -14,7 +14,6 @@ import java.io.File;
|
|||||||
|
|
||||||
@ExperimentalGetImage
|
@ExperimentalGetImage
|
||||||
public class DetectorService extends LifecycleService {
|
public class DetectorService extends LifecycleService {
|
||||||
|
|
||||||
public ServiceBinder serviceBinder = new ServiceBinder();
|
public ServiceBinder serviceBinder = new ServiceBinder();
|
||||||
private DetectorService.OnDetectionListener listener;
|
private DetectorService.OnDetectionListener listener;
|
||||||
private boolean isServiceRunning = false;
|
private boolean isServiceRunning = false;
|
||||||
@@ -27,6 +26,9 @@ public class DetectorService extends LifecycleService {
|
|||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
if (isServiceRunning)
|
if (isServiceRunning)
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
|
|
||||||
|
|
||||||
|
// Setup Service classes:
|
||||||
videoDetector = new VideoDetector(this);
|
videoDetector = new VideoDetector(this);
|
||||||
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -38,8 +40,8 @@ public class DetectorService extends LifecycleService {
|
|||||||
audioRecorder = new AudioRecorder(this);
|
audioRecorder = new AudioRecorder(this);
|
||||||
|
|
||||||
|
|
||||||
isServiceRunning = true;
|
|
||||||
|
|
||||||
|
isServiceRunning = true;
|
||||||
return super.onStartCommand(intent, flags, startId);
|
return super.onStartCommand(intent, flags, startId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.example.ueberwachungssystem.Detection;
|
|||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.ImageFormat;
|
import android.graphics.ImageFormat;
|
||||||
@@ -53,9 +52,6 @@ public class VideoDetector extends Detector {
|
|||||||
// Calling Activity
|
// Calling Activity
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
// Permission handling
|
|
||||||
private static final int PERMISSION_REQUEST_CODE = 3691;
|
|
||||||
|
|
||||||
// Camera Provider
|
// Camera Provider
|
||||||
private ProcessCameraProvider cameraProvider;
|
private ProcessCameraProvider cameraProvider;
|
||||||
private ImageAnalysis imageAnalysis;
|
private ImageAnalysis imageAnalysis;
|
||||||
@@ -112,11 +108,6 @@ public class VideoDetector extends Detector {
|
|||||||
// Check States
|
// Check States
|
||||||
if (isDetecting)
|
if (isDetecting)
|
||||||
return;
|
return;
|
||||||
// Return On Request Permissions
|
|
||||||
if (!hasPermissions()) {
|
|
||||||
getPermissions();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Configure Image Analysis
|
// Configure Image Analysis
|
||||||
imageAnalysis = setupImageAnalysis();
|
imageAnalysis = setupImageAnalysis();
|
||||||
// Open CV startup check
|
// Open CV startup check
|
||||||
@@ -145,11 +136,6 @@ public class VideoDetector extends Detector {
|
|||||||
if (isRecording){
|
if (isRecording){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Return On Request Permissions
|
|
||||||
if (!hasPermissions()) {
|
|
||||||
getPermissions();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
videoCapture = setupVideoCapture();
|
videoCapture = setupVideoCapture();
|
||||||
|
|
||||||
@@ -295,7 +281,6 @@ public class VideoDetector extends Detector {
|
|||||||
this.outputImageView = outputImageView;
|
this.outputImageView = outputImageView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
private void setPreviewView(@NonNull PreviewView previewView) {
|
private void setPreviewView(@NonNull PreviewView previewView) {
|
||||||
// Create Preview
|
// Create Preview
|
||||||
@@ -305,7 +290,6 @@ public class VideoDetector extends Detector {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Generate File Name */
|
/** Generate File Name */
|
||||||
private String generateFileName(){
|
private String generateFileName(){
|
||||||
// Get the current timestamp
|
// Get the current timestamp
|
||||||
@@ -324,7 +308,6 @@ public class VideoDetector extends Detector {
|
|||||||
return display.getRotation();
|
return display.getRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** 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) (START_DELAY), 100) {
|
new CountDownTimer((long) (START_DELAY), 100) {
|
||||||
@@ -338,16 +321,6 @@ public class VideoDetector extends Detector {
|
|||||||
}.start();
|
}.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) {
|
public void setOutputDir(File outputDir) {
|
||||||
this.outputDir = outputDir;
|
this.outputDir = outputDir;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,39 +30,50 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
PreviewView previewView = findViewById(R.id.previewView);
|
PreviewView previewView = findViewById(R.id.previewView);
|
||||||
|
|
||||||
|
|
||||||
VideoDetector vd = new VideoDetector(this);
|
PermissionHandler permissionHandler = new PermissionHandler(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();
|
|
||||||
|
|
||||||
|
|
||||||
AudioRecorder audioRecorder = new AudioRecorder(this);
|
permissionHandler.getPermissions();
|
||||||
|
|
||||||
|
if (permissionHandler.hasPermissions()) {
|
||||||
|
AudioRecorder audioRecorder = new AudioRecorder(this);
|
||||||
ToggleButton toggleButton = findViewById(R.id.toggleButton);
|
VideoDetector vd = new VideoDetector(this);
|
||||||
toggleButton.setOnClickListener(new View.OnClickListener() {
|
//vd.setPreviewView(previewView);
|
||||||
@Override
|
vd.debugProcessing(inputImageView, outputImageView);
|
||||||
public void onClick(View v) {
|
vd.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||||
if (toggleButton.isChecked())
|
@Override
|
||||||
{
|
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||||
//vd.startDetection();
|
Log.d("onDetection", detectionReport.toString());
|
||||||
//vd.stopDetection();
|
|
||||||
vd.startRecording();
|
|
||||||
audioRecorder.startRecording();
|
|
||||||
}
|
}
|
||||||
else {
|
});
|
||||||
//vd.stopDetection();
|
vd.startDetection();
|
||||||
vd.stopRecording();
|
|
||||||
audioRecorder.stopRecording();
|
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