|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 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); |
|
|
|
|
|
* */ |
|
|
* */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void stopDetection() { |
|
|
public void stopDetection() { |
|
|
if (!isDetecting || imageAnalysis == null) |
|
|
if (!isDetecting || imageAnalysis == null) |
|
|
return; |
|
|
return; |
|
|
cameraProvider.unbind(imageAnalysis); |
|
|
|
|
|
|
|
|
if (!isRecording) |
|
|
|
|
|
cameraProvider.unbindAll(); |
|
|
|
|
|
else |
|
|
|
|
|
cameraProvider.unbind(imageAnalysis); |
|
|
isDetecting = false; |
|
|
isDetecting = false; |
|
|
allowReportViolation = false; |
|
|
allowReportViolation = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
videoCapture.stopRecording(); |
|
|
videoCapture.stopRecording(); |
|
|
cameraProvider.unbind(videoCapture); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isDetecting()) |
|
|
|
|
|
cameraProvider.unbindAll(); |
|
|
|
|
|
else |
|
|
|
|
|
cameraProvider.unbind(videoCapture); |
|
|
isRecording = false; |
|
|
isRecording = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
|
float percentChanged = (float) (n / pixelCount) * 100; |
|
|
|
|
|
|
|
|
// Violation Condition |
|
|
// Violation Condition |
|
|
if (percentChanged * 100 > ALARM_THRESHOLD) { |
|
|
|
|
|
|
|
|
if (percentChanged> ALARM_THRESHOLD) { |
|
|
if (allowReportViolation) |
|
|
if (allowReportViolation) |
|
|
reportViolation("Video", percentChanged * 100); |
|
|
|
|
|
|
|
|
reportViolation("Video", percentChanged); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
imageProxy.close(); |
|
|
imageProxy.close(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 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) (setupTime), 100) { |
|
|
@Override |
|
|
@Override |
|
|
public void onTick(long millisUntilFinished) { |
|
|
public void onTick(long millisUntilFinished) { |
|
|
} |
|
|
} |