接入人脸检测报错
This commit is contained in:
@@ -29,13 +29,17 @@ import androidx.core.content.ContextCompat;
|
|||||||
|
|
||||||
import com.google.androidgamesdk.GameActivity;
|
import com.google.androidgamesdk.GameActivity;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
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.nio.ByteBuffer;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class MainActivity extends GameActivity {
|
public class MainActivity extends GameActivity implements FaceLandmarkerHelper.LandmarkerListener{
|
||||||
private ProcessCameraProvider cameraProvider;
|
private ProcessCameraProvider cameraProvider;
|
||||||
private void initCamera(){
|
private void initCamera(){
|
||||||
backgroundExecutor = Executors.newSingleThreadExecutor();
|
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
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -63,6 +79,25 @@ public class MainActivity extends GameActivity {
|
|||||||
|
|
||||||
initCamera();
|
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: ");
|
Log.i("MainActivity", "onCreate: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +115,7 @@ public class MainActivity extends GameActivity {
|
|||||||
private static final int REQUEST_CAMERA_PERMISSION = 1001;
|
private static final int REQUEST_CAMERA_PERMISSION = 1001;
|
||||||
ImageAnalysis imageAnalyzer;
|
ImageAnalysis imageAnalyzer;
|
||||||
ExecutorService backgroundExecutor;
|
ExecutorService backgroundExecutor;
|
||||||
|
FaceLandmarkerHelper faceLandmarkerHelper;
|
||||||
|
|
||||||
private void startCamera() {
|
private void startCamera() {
|
||||||
ListenableFuture<ProcessCameraProvider> cameraProviderFuture =
|
ListenableFuture<ProcessCameraProvider> cameraProviderFuture =
|
||||||
@@ -106,6 +142,7 @@ public class MainActivity extends GameActivity {
|
|||||||
public void analyze(@NonNull ImageProxy image) {
|
public void analyze(@NonNull ImageProxy image) {
|
||||||
try {
|
try {
|
||||||
Log.d("Camera", "Received image: " + image.getWidth() + "x" + image.getHeight());
|
Log.d("Camera", "Received image: " + image.getWidth() + "x" + image.getHeight());
|
||||||
|
detectFace(image);
|
||||||
processImageForVulkan(image);
|
processImageForVulkan(image);
|
||||||
} finally {
|
} finally {
|
||||||
image.close(); // 确保在这里关闭
|
image.close(); // 确保在这里关闭
|
||||||
@@ -177,4 +214,14 @@ public class MainActivity extends GameActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private native void sendArgumentsToPlatform(String[] args);
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user