加入渲染点的代码
This commit is contained in:
@@ -18,11 +18,16 @@ import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.google.androidgamesdk.GameActivity;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.mediapipe.tasks.components.containers.NormalizedLandmark;
|
||||
import com.google.mediapipe.tasks.vision.core.RunningMode;
|
||||
import com.google.mediapipe.tasks.vision.facelandmarker.FaceLandmarkerResult;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -202,8 +207,46 @@ public class MainActivity extends GameActivity implements FaceLandmarkerHelper.L
|
||||
Log.e(TAG, "onError: Face Error");
|
||||
}
|
||||
|
||||
private ByteBuffer nativeBuffer = null;
|
||||
float[] points = new float[480 * 3];
|
||||
|
||||
|
||||
@Override
|
||||
public void onResults(FaceLandmarkerHelper.@NotNull ResultBundle resultBundle) {
|
||||
Log.e(TAG, "On Face Result");
|
||||
FaceLandmarkerResult faceLandmarkerResult = resultBundle.getResult();
|
||||
int height = resultBundle.getInputImageHeight();
|
||||
int width = resultBundle.getInputImageWidth();
|
||||
int bufferSize = 480 * 3 * 4;
|
||||
|
||||
if(nativeBuffer == null)
|
||||
{
|
||||
// 创建直接ByteBuffer(在native内存中)
|
||||
nativeBuffer = ByteBuffer.allocateDirect(bufferSize);
|
||||
nativeBuffer.order(ByteOrder.nativeOrder());
|
||||
}
|
||||
|
||||
|
||||
int index = 0;
|
||||
// Iterate through each detected face
|
||||
for (List<NormalizedLandmark> faceLandmarks : faceLandmarkerResult.faceLandmarks()) {
|
||||
//should be 1
|
||||
|
||||
int arrayIndex = 0;
|
||||
for (NormalizedLandmark p : faceLandmarks)
|
||||
{
|
||||
//Log.i(TAG, "Index" + index + " x:"+p.x() + " y:"+p.y() + " z:"+p.z());
|
||||
points[arrayIndex++] = p.x();
|
||||
points[arrayIndex++] = p.y();
|
||||
points[arrayIndex++] = p.z();
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
// 转换为FloatBuffer并填充数据
|
||||
FloatBuffer floatBuffer = nativeBuffer.asFloatBuffer();
|
||||
floatBuffer.put(points);
|
||||
floatBuffer.position(0);
|
||||
passDataToNative(nativeBuffer, index, width, height);
|
||||
}
|
||||
public native void passDataToNative(ByteBuffer buffer, int pointCount, int width, int height);
|
||||
}
|
||||
Reference in New Issue
Block a user