From 2b4066fa324f4b473f93b98e7ec611726280e868 Mon Sep 17 00:00:00 2001 From: Xiang Silian Date: Tue, 16 Sep 2025 23:48:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5=E4=BA=BA=E8=84=B8=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../khronos/vulkan_samples/MainActivity.java | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/app/android/java/com/khronos/vulkan_samples/MainActivity.java b/app/android/java/com/khronos/vulkan_samples/MainActivity.java index dd15825..30f544f 100644 --- a/app/android/java/com/khronos/vulkan_samples/MainActivity.java +++ b/app/android/java/com/khronos/vulkan_samples/MainActivity.java @@ -29,13 +29,17 @@ import androidx.core.content.ContextCompat; import com.google.androidgamesdk.GameActivity; import com.google.common.util.concurrent.ListenableFuture; +import com.google.mediapipe.examples.facelandmarker.FaceLandmarkerHelper; +import com.google.mediapipe.tasks.vision.core.RunningMode; + +import org.jetbrains.annotations.NotNull; import java.nio.ByteBuffer; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -public class MainActivity extends GameActivity { +public class MainActivity extends GameActivity implements FaceLandmarkerHelper.LandmarkerListener{ private ProcessCameraProvider cameraProvider; private void initCamera(){ backgroundExecutor = Executors.newSingleThreadExecutor(); @@ -46,6 +50,18 @@ public class MainActivity extends GameActivity { } } + private void detectFace(ImageProxy imageProxy) { + backgroundExecutor.execute(new Runnable() { + @Override + public void run() { + faceLandmarkerHelper.detectLiveStream( + imageProxy,true + ); + } + }); + + } + @Override protected void onCreate(Bundle savedInstanceState) { @@ -63,6 +79,25 @@ public class MainActivity extends GameActivity { initCamera(); + backgroundExecutor.execute(new Runnable() { + @Override + public void run() { + faceLandmarkerHelper = new FaceLandmarkerHelper( + 0.5f, + 0.5f, + 0.5f, + 1, + 0, + RunningMode.LIVE_STREAM, + MainActivity.this, + MainActivity.this + ); + } + }); + + + + Log.i("MainActivity", "onCreate: "); } @@ -80,6 +115,7 @@ public class MainActivity extends GameActivity { private static final int REQUEST_CAMERA_PERMISSION = 1001; ImageAnalysis imageAnalyzer; ExecutorService backgroundExecutor; + FaceLandmarkerHelper faceLandmarkerHelper; private void startCamera() { ListenableFuture cameraProviderFuture = @@ -106,6 +142,7 @@ public class MainActivity extends GameActivity { public void analyze(@NonNull ImageProxy image) { try { Log.d("Camera", "Received image: " + image.getWidth() + "x" + image.getHeight()); + detectFace(image); processImageForVulkan(image); } finally { image.close(); // 确保在这里关闭 @@ -177,4 +214,14 @@ public class MainActivity extends GameActivity { } private native void sendArgumentsToPlatform(String[] args); + + @Override + public void onError(@NotNull String error, int errorCode) { + Log.e(TAG, "onError: Face Error"); + } + + @Override + public void onResults(FaceLandmarkerHelper.@NotNull ResultBundle resultBundle) { + Log.e(TAG, "On Face Result"); + } } \ No newline at end of file