Search in sources :

Example 1 with Landmark

use of com.google.android.gms.vision.face.Landmark in project android-vision by googlesamples.

the class GooglyFaceTracker method getLandmarkPosition.

/**
     * Finds a specific landmark position, or approximates the position based on past observations
     * if it is not present.
     */
private PointF getLandmarkPosition(Face face, int landmarkId) {
    for (Landmark landmark : face.getLandmarks()) {
        if (landmark.getType() == landmarkId) {
            return landmark.getPosition();
        }
    }
    PointF prop = mPreviousProportions.get(landmarkId);
    if (prop == null) {
        return null;
    }
    float x = face.getPosition().x + (prop.x * face.getWidth());
    float y = face.getPosition().y + (prop.y * face.getHeight());
    return new PointF(x, y);
}
Also used : Landmark(com.google.android.gms.vision.face.Landmark) PointF(android.graphics.PointF)

Example 2 with Landmark

use of com.google.android.gms.vision.face.Landmark in project android-vision by googlesamples.

the class GooglyFaceTracker method updatePreviousProportions.

//==============================================================================================
// Private
//==============================================================================================
private void updatePreviousProportions(Face face) {
    for (Landmark landmark : face.getLandmarks()) {
        PointF position = landmark.getPosition();
        float xProp = (position.x - face.getPosition().x) / face.getWidth();
        float yProp = (position.y - face.getPosition().y) / face.getHeight();
        mPreviousProportions.put(landmark.getType(), new PointF(xProp, yProp));
    }
}
Also used : Landmark(com.google.android.gms.vision.face.Landmark) PointF(android.graphics.PointF)

Example 3 with Landmark

use of com.google.android.gms.vision.face.Landmark in project android-vision by googlesamples.

the class FaceView method drawFaceAnnotations.

/**
     * Draws a small circle for each detected landmark, centered at the detected landmark position.
     * <p>
     *
     * Note that eye landmarks are defined to be the midpoint between the detected eye corner
     * positions, which tends to place the eye landmarks at the lower eyelid rather than at the
     * pupil position.
     */
private void drawFaceAnnotations(Canvas canvas, double scale) {
    Paint paint = new Paint();
    paint.setColor(Color.GREEN);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(5);
    for (int i = 0; i < mFaces.size(); ++i) {
        Face face = mFaces.valueAt(i);
        for (Landmark landmark : face.getLandmarks()) {
            int cx = (int) (landmark.getPosition().x * scale);
            int cy = (int) (landmark.getPosition().y * scale);
            canvas.drawCircle(cx, cy, 10, paint);
        }
    }
}
Also used : Landmark(com.google.android.gms.vision.face.Landmark) Paint(android.graphics.Paint) Face(com.google.android.gms.vision.face.Face) Paint(android.graphics.Paint)

Aggregations

Landmark (com.google.android.gms.vision.face.Landmark)3 PointF (android.graphics.PointF)2 Paint (android.graphics.Paint)1 Face (com.google.android.gms.vision.face.Face)1