Compare commits
3 Commits
19d1bfe1e3
...
daaf8735de
Author | SHA1 | Date | |
---|---|---|---|
daaf8735de | |||
1b342d1049 | |||
8cc57ec4d5 |
@ -3,7 +3,10 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<uses-feature android:name="android.hardware.camera"/>
|
<uses-feature android:name="android.hardware.camera"/>
|
||||||
<uses-permission android:name="android.permission.CAMERA"/>
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
<uses-feature android:name="android.hardware.Camera"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
@ -10,17 +10,20 @@ import androidx.camera.core.ExperimentalGetImage;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.widget.ToggleButton;
|
import android.widget.ToggleButton;
|
||||||
|
import android.widget.VideoView;
|
||||||
|
|
||||||
import com.example.ueberwachungssystem.VideoDetection.VideoDetector;
|
import com.example.ueberwachungssystem.VideoDetection.VideoDetector;
|
||||||
|
|
||||||
@ExperimentalGetImage
|
@ExperimentalGetImage
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private static final int CAMERA_PERMISSION_REQUEST_CODE = 101;
|
private static final int CAMERA_PERMISSION_REQUEST_CODE = 100;
|
||||||
|
private static final int RECORD_VIDEO_PERMISSION_REQUEST_CODE = 102;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -31,6 +34,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
TextView textView = findViewById(R.id.textView);
|
TextView textView = findViewById(R.id.textView);
|
||||||
PreviewView previewView = findViewById(R.id.previewView);
|
PreviewView previewView = findViewById(R.id.previewView);
|
||||||
|
|
||||||
|
getCameraAccess();
|
||||||
|
|
||||||
VideoDetector vd = new VideoDetector(this);
|
VideoDetector vd = new VideoDetector(this);
|
||||||
vd.setPreviewView(previewView);
|
vd.setPreviewView(previewView);
|
||||||
@ -38,27 +42,11 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||||
detectionReport.log("OnDetection");
|
detectionReport.log("OnDetection");
|
||||||
textView.setText(detectionReport.toString());
|
textView.setText("Alarm:\t[" + String.valueOf(detectionReport.detectedValue) + "]");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//vd.startDetection();
|
|
||||||
|
|
||||||
|
|
||||||
ToggleButton toggleButton = findViewById(R.id.previewButton);
|
|
||||||
toggleButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
getCameraAccess();
|
|
||||||
if (isCameraAccessAllowed() && toggleButton.isChecked())
|
|
||||||
{
|
|
||||||
vd.startDetection();
|
vd.startDetection();
|
||||||
}
|
|
||||||
else {
|
|
||||||
vd.stopDetection();
|
|
||||||
textView.setText("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCameraAccessAllowed() {
|
private boolean isCameraAccessAllowed() {
|
||||||
@ -77,9 +65,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
if (requestCode == CAMERA_PERMISSION_REQUEST_CODE && grantResults.length > 0) {
|
if (requestCode == CAMERA_PERMISSION_REQUEST_CODE && grantResults.length > 0) {
|
||||||
boolean cameraRights = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
boolean cameraRights = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
||||||
if (cameraRights) {
|
if (cameraRights) {
|
||||||
Toast.makeText(this, "camera permission granted", Toast.LENGTH_LONG).show();
|
Toast.makeText(this, "permission granted", Toast.LENGTH_LONG).show();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, "camera permission denied", Toast.LENGTH_LONG).show();
|
Toast.makeText(this, "permission denied", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public class VideoDetector extends Detector {
|
|||||||
private PreviewView previewView = null;
|
private PreviewView previewView = null;
|
||||||
// Detect Violation
|
// Detect Violation
|
||||||
private static final float PIXEL_THRESHOLD = 30f; // Luminosity (brightness channel of YUV_420_888)
|
private static final float PIXEL_THRESHOLD = 30f; // Luminosity (brightness channel of YUV_420_888)
|
||||||
private static final float ALARM_THRESHOLD = 1f; // Percent of pixels changed
|
private static final float ALARM_THRESHOLD = 0.5f; // Percent of pixels changed
|
||||||
private ByteBuffer previousBuffer = null;
|
private ByteBuffer previousBuffer = null;
|
||||||
|
|
||||||
|
|
||||||
@ -117,6 +117,7 @@ public class VideoDetector extends Detector {
|
|||||||
if (previewView != null)
|
if (previewView != null)
|
||||||
preview.setSurfaceProvider(previewView.getSurfaceProvider());
|
preview.setSurfaceProvider(previewView.getSurfaceProvider());
|
||||||
|
|
||||||
|
cameraProvider.unbindAll();
|
||||||
cameraProvider.bindToLifecycle((LifecycleOwner) context, cameraSelector, imageAnalysis, preview);
|
cameraProvider.bindToLifecycle((LifecycleOwner) context, cameraSelector, imageAnalysis, preview);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,24 +14,21 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text=""
|
android:text=""
|
||||||
android:textSize="20dp"
|
android:textSize="30sp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
|
||||||
<ToggleButton
|
|
||||||
android:id="@+id/previewButton"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="ToggleButton" />
|
|
||||||
|
|
||||||
|
|
||||||
<androidx.camera.view.PreviewView
|
<androidx.camera.view.PreviewView
|
||||||
android:id="@+id/previewView"
|
android:id="@+id/previewView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:backgroundTint="@android:color/black"/>
|
android:backgroundTint="@android:color/black">
|
||||||
|
|
||||||
|
</androidx.camera.view.PreviewView>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user