Removed old Luminosity detection
This commit is contained in:
parent
c5577b125f
commit
804c5aba36
@ -3,7 +3,6 @@ package com.example.ueberwachungssystem.VideoDetection;
|
||||
import android.content.Context;
|
||||
import android.graphics.ImageFormat;
|
||||
import android.media.Image;
|
||||
import android.util.Log;
|
||||
import android.util.Size;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@ -32,12 +31,9 @@ public class VideoDetector extends Detector {
|
||||
private Boolean isDetectionRunning = false;
|
||||
// Preview Camera Image
|
||||
private PreviewView previewView = null;
|
||||
// Check Violation
|
||||
private final float DELTA_LUMINOSITY_THRESHOLD = 1.5f;
|
||||
private Float previousLuminosity = null;
|
||||
|
||||
private static final int PIXEL_THRESHOLD = 50; // Luminosity (brightness channel of YUV_420_888)
|
||||
private static final int ALARM_THRESHOLD = 1; // Percent of pixels changed
|
||||
// Detect Violation
|
||||
private static final int PIXEL_THRESHOLD = 60; // Luminosity (brightness channel of YUV_420_888)
|
||||
private static final float ALARM_THRESHOLD = 0.5f; // Percent of pixels changed
|
||||
private ByteBuffer previousBuffer = null;
|
||||
|
||||
|
||||
@ -101,23 +97,15 @@ public class VideoDetector extends Detector {
|
||||
Image image = imageProxy.getImage();
|
||||
assert image != null;
|
||||
|
||||
|
||||
// Luminosity Detection
|
||||
//float luminosity = calculateLuminosity(image);
|
||||
//if (previousLuminosity != null)
|
||||
// checkForViolation(luminosity, previousLuminosity);
|
||||
//previousLuminosity = luminosity;
|
||||
|
||||
|
||||
// Changed Pixel Detection
|
||||
int pixelChanged = getChangedPixelCount(image);
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
|
||||
float percentPixelChanged = (float) 100f * pixelChanged / (width * height);
|
||||
|
||||
if (percentPixelChanged > ALARM_THRESHOLD)
|
||||
reportViolation("0", "Video", percentPixelChanged);
|
||||
|
||||
}
|
||||
imageProxy.close();
|
||||
});
|
||||
@ -134,31 +122,6 @@ public class VideoDetector extends Detector {
|
||||
}
|
||||
|
||||
|
||||
/** Return Luminosity from Image */
|
||||
private float calculateLuminosity (Image image) {
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
|
||||
Image.Plane[] planes = image.getPlanes();
|
||||
ByteBuffer luminosityBuffer = planes[0].getBuffer();
|
||||
|
||||
int yRowStride = image.getPlanes()[0].getRowStride();
|
||||
int yPixelStride = image.getPlanes()[0].getPixelStride();
|
||||
|
||||
int luminosity;
|
||||
float sum = 0;
|
||||
|
||||
for (int y = 0; y < height; ++y) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int index = (y * yRowStride) + (x * yPixelStride);
|
||||
luminosity = (luminosityBuffer.get(index) & 0xff);
|
||||
sum += luminosity;
|
||||
}
|
||||
}
|
||||
return sum / (width * height);
|
||||
}
|
||||
|
||||
|
||||
/** Calculate Amount of Pixels changed */
|
||||
private int getChangedPixelCount(Image image) {
|
||||
int width = image.getWidth();
|
||||
@ -177,6 +140,7 @@ public class VideoDetector extends Detector {
|
||||
buffer.rewind();
|
||||
previousBuffer.put(buffer);
|
||||
previousBuffer.rewind();
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int y = 0; y < height; ++y) {
|
||||
@ -196,15 +160,4 @@ public class VideoDetector extends Detector {
|
||||
|
||||
return changedPixelCount;
|
||||
}
|
||||
|
||||
|
||||
/** Check if delta Luminosity exceeds threshold */
|
||||
private void checkForViolation(float luminosity, float previousLuminosity) {
|
||||
float deltaLuminosity = Math.abs(luminosity - previousLuminosity);
|
||||
if (deltaLuminosity > DELTA_LUMINOSITY_THRESHOLD) {
|
||||
reportViolation("0", "Video",luminosity);
|
||||
Log.d("Violation", "Violation");
|
||||
}
|
||||
Log.d("Delta", String.valueOf(Math.abs(previousLuminosity - luminosity)));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user