Removed olf Luminosity detection
This commit is contained in:
parent
ba6765b1fb
commit
74a291bdd6
@ -3,7 +3,6 @@ package com.example.ueberwachungssystem.VideoDetection;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.ImageFormat;
|
import android.graphics.ImageFormat;
|
||||||
import android.media.Image;
|
import android.media.Image;
|
||||||
import android.util.Log;
|
|
||||||
import android.util.Size;
|
import android.util.Size;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -32,12 +31,9 @@ public class VideoDetector extends Detector {
|
|||||||
private Boolean isDetectionRunning = false;
|
private Boolean isDetectionRunning = false;
|
||||||
// Preview Camera Image
|
// Preview Camera Image
|
||||||
private PreviewView previewView = null;
|
private PreviewView previewView = null;
|
||||||
// Check Violation
|
// Detect Violation
|
||||||
private final float DELTA_LUMINOSITY_THRESHOLD = 1.5f;
|
private static final int PIXEL_THRESHOLD = 60; // Luminosity (brightness channel of YUV_420_888)
|
||||||
private Float previousLuminosity = null;
|
private static final float ALARM_THRESHOLD = 0.5f; // Percent of pixels changed
|
||||||
|
|
||||||
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
|
|
||||||
private ByteBuffer previousBuffer = null;
|
private ByteBuffer previousBuffer = null;
|
||||||
|
|
||||||
|
|
||||||
@ -101,23 +97,15 @@ public class VideoDetector extends Detector {
|
|||||||
Image image = imageProxy.getImage();
|
Image image = imageProxy.getImage();
|
||||||
assert image != null;
|
assert image != null;
|
||||||
|
|
||||||
|
|
||||||
// Luminosity Detection
|
|
||||||
//float luminosity = calculateLuminosity(image);
|
|
||||||
//if (previousLuminosity != null)
|
|
||||||
// checkForViolation(luminosity, previousLuminosity);
|
|
||||||
//previousLuminosity = luminosity;
|
|
||||||
|
|
||||||
|
|
||||||
// Changed Pixel Detection
|
// Changed Pixel Detection
|
||||||
int pixelChanged = getChangedPixelCount(image);
|
int pixelChanged = getChangedPixelCount(image);
|
||||||
int width = image.getWidth();
|
int width = image.getWidth();
|
||||||
int height = image.getHeight();
|
int height = image.getHeight();
|
||||||
|
|
||||||
float percentPixelChanged = (float) 100f * pixelChanged / (width * height);
|
float percentPixelChanged = (float) 100f * pixelChanged / (width * height);
|
||||||
|
|
||||||
if (percentPixelChanged > ALARM_THRESHOLD)
|
if (percentPixelChanged > ALARM_THRESHOLD)
|
||||||
reportViolation("0", "Video", percentPixelChanged);
|
reportViolation("0", "Video", percentPixelChanged);
|
||||||
|
|
||||||
}
|
}
|
||||||
imageProxy.close();
|
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 */
|
/** Calculate Amount of Pixels changed */
|
||||||
private int getChangedPixelCount(Image image) {
|
private int getChangedPixelCount(Image image) {
|
||||||
int width = image.getWidth();
|
int width = image.getWidth();
|
||||||
@ -177,6 +140,7 @@ public class VideoDetector extends Detector {
|
|||||||
buffer.rewind();
|
buffer.rewind();
|
||||||
previousBuffer.put(buffer);
|
previousBuffer.put(buffer);
|
||||||
previousBuffer.rewind();
|
previousBuffer.rewind();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int y = 0; y < height; ++y) {
|
for (int y = 0; y < height; ++y) {
|
||||||
@ -196,15 +160,4 @@ public class VideoDetector extends Detector {
|
|||||||
|
|
||||||
return changedPixelCount;
|
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