Revert "[DNM] Make use of cam service on MainActivity"
This reverts commit 25efdbcb02b88363d5665dc62dc25de6f8846d09.
diff --git a/app/src/main/java/com/libremobileos/facedetect/MainActivity.java b/app/src/main/java/com/libremobileos/facedetect/MainActivity.java
index 88dc39e..ddfcc69 100644
--- a/app/src/main/java/com/libremobileos/facedetect/MainActivity.java
+++ b/app/src/main/java/com/libremobileos/facedetect/MainActivity.java
@@ -25,7 +25,6 @@
import android.util.Size;
import androidx.annotation.Nullable;
-import androidx.appcompat.app.AppCompatActivity;
import com.libremobileos.yifan.face.DirectoryFaceStorageBackend;
import com.libremobileos.yifan.face.FaceRecognizer;
@@ -37,21 +36,19 @@
import java.util.ArrayList;
import java.util.List;
-public class MainActivity extends AppCompatActivity implements CameraService.CameraCallback {
+public class MainActivity extends CameraActivity {
// AI-based detector
private FaceRecognizer faceRecognizer;
// Simple view allowing us to draw Rectangles over the Preview
private FaceBoundsOverlayView overlayView;
private boolean computingDetection = false;
- private CameraService mCameraService;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
// Initialize basic views
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
- //connectToCam(findViewById(R.id.viewFinder));
- mCameraService = new CameraService(this, this);
+ connectToCam(findViewById(R.id.viewFinder));
overlayView = findViewById(R.id.overlay);
overlayView.setOnClickListener(v -> {
@@ -61,21 +58,7 @@
}
@Override
- protected void onResume() {
- super.onResume();
- mCameraService.startBackgroundThread();
- mCameraService.openCamera();
- }
-
- @Override
- protected void onPause() {
- mCameraService.closeCamera();
- mCameraService.stopBackgroundThread();
- super.onPause();
- }
-
- @Override
- public void setupFaceRecognizer(final Size bitmapSize, int rotation) {
+ protected void setupFaceRecognizer(final Size bitmapSize) {
// Store registered Faces
// example for in-memory: FaceStorageBackend faceStorage = new VolatileFaceStorageBackend();
// example for shared preferences: FaceStorageBackend faceStorage = new SharedPreferencesFaceStorageBackend(getSharedPreferences("faces", 0));
@@ -87,28 +70,28 @@
0.6f, /* minimum confidence to consider object as face */
bitmapSize.getWidth(), /* bitmap width */
bitmapSize.getHeight(), /* bitmap height */
- rotation,
+ imageOrientation,
0.7f, /* maximum distance (to saved face model, not from camera) to track face */
1 /* minimum model count to track face */
);
}
@Override
- public void processImage(Size previewSize, Size rotatedSize, Bitmap rgbBitmap, int rotation) {
+ protected void processImage() {
// No mutex needed as this method is not reentrant.
if (computingDetection) {
- mCameraService.readyForNextImage();
+ readyForNextImage();
return;
}
computingDetection = true;
- List<FaceRecognizer.Face> data = faceRecognizer.recognize(rgbBitmap);
+ List<FaceRecognizer.Face> data = faceRecognizer.recognize(getBitmap());
computingDetection = false;
ArrayList<Pair<RectF, String>> bounds = new ArrayList<>();
// Camera is frontal so the image is flipped horizontally,
// so flip it again (and rotate Rect to match preview rotation)
- Matrix flip = ImageUtils.getTransformationMatrix(previewSize.getWidth(), previewSize.getHeight(), rotatedSize.getWidth(), rotatedSize.getHeight(), rotation, false);
- flip.preScale(1, -1, previewSize.getWidth() / 2f, previewSize.getHeight() / 2f);
+ Matrix flip = ImageUtils.getTransformationMatrix(width, height, rotatedWidth, rotatedHeight, imageOrientation, false);
+ flip.preScale(1, -1, width / 2f, height / 2f);
for (FaceRecognizer.Face face : data) {
RectF boundingBox = new RectF(face.getLocation());
@@ -128,8 +111,8 @@
}
// Pass bounds to View drawing rectangles
- overlayView.updateBounds(bounds, rotatedSize.getWidth(), rotatedSize.getHeight());
- mCameraService.readyForNextImage();
+ overlayView.updateBounds(bounds, rotatedWidth, rotatedHeight);
+ readyForNextImage();
}
}