阿斯蒂芬
This commit is contained in:
@@ -23,6 +23,7 @@ import com.google.androidgamesdk.GameActivity;
|
|||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.mediapipe.tasks.components.containers.NormalizedLandmark;
|
import com.google.mediapipe.tasks.components.containers.NormalizedLandmark;
|
||||||
import com.google.mediapipe.tasks.vision.core.RunningMode;
|
import com.google.mediapipe.tasks.vision.core.RunningMode;
|
||||||
|
import com.google.mediapipe.tasks.vision.facelandmarker.FaceLandmarker;
|
||||||
import com.google.mediapipe.tasks.vision.facelandmarker.FaceLandmarkerResult;
|
import com.google.mediapipe.tasks.vision.facelandmarker.FaceLandmarkerResult;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -30,6 +31,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
@@ -264,6 +266,41 @@ public class MainActivity extends GameActivity implements FaceLandmarkerHelper.L
|
|||||||
float[] points = new float[480 * 3];
|
float[] points = new float[480 * 3];
|
||||||
|
|
||||||
|
|
||||||
|
public class Vector {
|
||||||
|
public float x, y, z;
|
||||||
|
|
||||||
|
public Vector(float x, float y, float z) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toObjString(ArrayList<Vector> vertices, ArrayList<Integer> triangleIndices) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
// 写入顶点数据 (v x y z)
|
||||||
|
for (Vector v : vertices) {
|
||||||
|
sb.append(String.format("v %.6f %.6f %.6f\n", v.x, v.y, v.z));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 写入面数据 (f i1 i2 i3),OBJ索引从1开始,因此每个索引+1
|
||||||
|
int size = triangleIndices.size();
|
||||||
|
for (int i = 0; i < size; i += 3) {
|
||||||
|
if (i + 2 < size) {
|
||||||
|
int i1 = triangleIndices.get(i) + 1;
|
||||||
|
int i2 = triangleIndices.get(i + 1) + 1;
|
||||||
|
int i3 = triangleIndices.get(i + 2) + 1;
|
||||||
|
sb.append(String.format("f %d %d %d\n", i1, i2, i3));
|
||||||
|
} else {
|
||||||
|
// 如果剩余索引不足3个,说明数据不完整
|
||||||
|
System.err.println("Warning: Incomplete triangle face at the end of index list.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResults(FaceLandmarkerHelper.@NotNull ResultBundle resultBundle) {
|
public void onResults(FaceLandmarkerHelper.@NotNull ResultBundle resultBundle) {
|
||||||
FaceLandmarkerResult faceLandmarkerResult = resultBundle.getResult();
|
FaceLandmarkerResult faceLandmarkerResult = resultBundle.getResult();
|
||||||
@@ -278,6 +315,19 @@ public class MainActivity extends GameActivity implements FaceLandmarkerHelper.L
|
|||||||
nativeBuffer.order(ByteOrder.nativeOrder());
|
nativeBuffer.order(ByteOrder.nativeOrder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ArrayList<Vector> vertexs = new ArrayList<>();
|
||||||
|
// ArrayList<Integer> triangle_index = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// for (var conn : FaceLandmarker.FACE_LANDMARKS_TESSELATION) {
|
||||||
|
// triangle_index.add(conn.start());
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// StringBuilder sb = new StringBuilder();
|
||||||
|
// sb.append("[");
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
// Iterate through each detected face
|
// Iterate through each detected face
|
||||||
for (List<NormalizedLandmark> faceLandmarks : faceLandmarkerResult.faceLandmarks()) {
|
for (List<NormalizedLandmark> faceLandmarks : faceLandmarkerResult.faceLandmarks()) {
|
||||||
@@ -286,14 +336,25 @@ public class MainActivity extends GameActivity implements FaceLandmarkerHelper.L
|
|||||||
int arrayIndex = 0;
|
int arrayIndex = 0;
|
||||||
for (NormalizedLandmark p : faceLandmarks)
|
for (NormalizedLandmark p : faceLandmarks)
|
||||||
{
|
{
|
||||||
|
//sb.append("[");
|
||||||
//Log.i(TAG, "Index" + index + " x:"+p.x() + " y:"+p.y() + " z:"+p.z());
|
//Log.i(TAG, "Index" + index + " x:"+p.x() + " y:"+p.y() + " z:"+p.z());
|
||||||
points[arrayIndex++] = p.x();
|
points[arrayIndex++] = p.x();
|
||||||
|
//sb.append(""+p.x()+",");
|
||||||
points[arrayIndex++] = p.y();
|
points[arrayIndex++] = p.y();
|
||||||
|
//sb.append(""+p.y()+",");
|
||||||
points[arrayIndex++] = p.z() * z_rate;
|
points[arrayIndex++] = p.z() * z_rate;
|
||||||
|
//sb.append(""+p.z());
|
||||||
|
//vertexs.add(new Vector(p.x(), p.y(), p.z()));
|
||||||
|
//sb.append("],");
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//sb.append("]");
|
||||||
|
//String objStr = sb.toString();
|
||||||
|
|
||||||
|
//String objStr = toObjString(vertexs, triangle_index);
|
||||||
|
|
||||||
// 转换为FloatBuffer并填充数据
|
// 转换为FloatBuffer并填充数据
|
||||||
FloatBuffer floatBuffer = nativeBuffer.asFloatBuffer();
|
FloatBuffer floatBuffer = nativeBuffer.asFloatBuffer();
|
||||||
floatBuffer.put(points);
|
floatBuffer.put(points);
|
||||||
|
|||||||
Reference in New Issue
Block a user