37.8 AugmentedFace API

less than 1 minute read

Create Session

  void onCreate(Bundle savedInstanceState) {
    session = new Session(this, EnumSet.of(Session.Feature.FRONT_CAMERA));
    Config config = new Config(session);
    config.setAugmentedFaceMode(AugmentedFaceMode.MESH3D);
    session.configure(config);
    session.setCameraTextureName(backgroud_texture_id);
  }

The update loop

  void onDrawFrame(GL10 gl) {
    try {
      Frame frame = session.update();
      Collection<AugmentedFace> faces = session.getAllTrackables(AugmentedFace.class);
      for (AugmentedFace face : faces) {
        // Do your rendering work with the face data
      }
    } catch(Throwable t) {
      ...
    }
  }

Get tracking state

  face.getTrackingstate();
  ...
  TrackingState trackingState = face.getTrackingstate();
  ...

Trackable API

  // tracking face
  public class AugmentedFace extends TrackingBase {
    public FloatBuffer getMeshVertices();
    public FloatBuffer getMeshNormals();
    public ShortBuffer getMeshTriangleIndices();
    public Pose getCenterPose();
    public Pose getRegionPose(RegionType regionType);
  }

  // tracking plane
  public class Plane extends TrackableBase {
    public Plane.Type getType();
    public Plane getSubsumedBy();
    public Pose getCenterPose();
  }

  // tracking point
  public class Point extends TrackableBase {
    public com.google.ar.core.Pose getPose();
    public com.google.ar.core.Point.OrientationMode getOrientationMode();
  }

  // tracking image
  public class AugmentedImage extends TrackableBase {
    public Pose getCenterPose();
  }

Pose API

参考