Bug Fixes on VideoDetector

This commit is contained in:
Bastian Kohler 2023-06-21 09:50:14 +02:00
parent 39295f9780
commit 43eac872ed

View File

@ -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,6 +173,9 @@ public class VideoDetector extends Detector {
public void stopDetection() {
if (!isDetecting || imageAnalysis == null)
return;
if (!isRecording)
cameraProvider.unbindAll();
else
cameraProvider.unbind(imageAnalysis);
isDetecting = false;
allowReportViolation = false;
@ -187,6 +188,10 @@ public class VideoDetector extends Detector {
return;
videoCapture.stopRecording();
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) {
}