Skip to content

Commit cb9f788

Browse files
author
Gonzalo Fernández
committed
Added another fields from face object to be shown (happiness level, left eye opened level and right eye opened level).
1 parent fa5c23f commit cb9f788

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

face/FaceTracker/app/src/main/java/com/google/android/gms/samples/vision/face/facetracker/FaceGraphic.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import android.graphics.Color;
2020
import android.graphics.Paint;
2121

22-
import com.google.android.gms.vision.face.Face;
2322
import com.google.android.gms.samples.vision.face.facetracker.ui.camera.GraphicOverlay;
23+
import com.google.android.gms.vision.face.Face;
2424

2525
/**
2626
* Graphic instance for rendering face position, orientation, and landmarks within an associated
@@ -50,6 +50,7 @@ class FaceGraphic extends GraphicOverlay.Graphic {
5050

5151
private volatile Face mFace;
5252
private int mFaceId;
53+
private float mFaceHappiness;
5354

5455
FaceGraphic(GraphicOverlay overlay) {
5556
super(overlay);
@@ -74,6 +75,7 @@ void setId(int id) {
7475
mFaceId = id;
7576
}
7677

78+
7779
/**
7880
* Updates the face instance from the detection of the most recent frame. Invalidates the
7981
* relevant portions of the overlay to trigger a redraw.
@@ -98,6 +100,9 @@ public void draw(Canvas canvas) {
98100
float y = translateY(face.getPosition().y + face.getHeight() / 2);
99101
canvas.drawCircle(x, y, FACE_POSITION_RADIUS, mFacePositionPaint);
100102
canvas.drawText("id: " + mFaceId, x + ID_X_OFFSET, y + ID_Y_OFFSET, mIdPaint);
103+
canvas.drawText("happiness: " + String.format("%.2f", face.getIsSmilingProbability()), x - ID_X_OFFSET, y - ID_Y_OFFSET, mIdPaint);
104+
canvas.drawText("right eye: " + String.format("%.2f", face.getIsRightEyeOpenProbability()), x + ID_X_OFFSET * 2, y + ID_Y_OFFSET * 2, mIdPaint);
105+
canvas.drawText("left eye: " + String.format("%.2f", face.getIsRightEyeOpenProbability()), x - ID_X_OFFSET*2, y - ID_Y_OFFSET*2, mIdPaint);
101106

102107
// Draws a bounding box around the face.
103108
float xOffset = scaleX(face.getWidth() / 2.0f);

face/FaceTracker/app/src/main/java/com/google/android/gms/samples/vision/face/facetracker/FaceTrackerActivity.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public void onCreate(Bundle icicle) {
5757
mGraphicOverlay = (GraphicOverlay) findViewById(R.id.faceOverlay);
5858

5959
Context context = getApplicationContext();
60-
FaceDetector detector = new FaceDetector.Builder(context).build();
60+
FaceDetector.Builder detectorBuilder = new FaceDetector.Builder(context);
61+
detectorBuilder.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS);
62+
FaceDetector detector = detectorBuilder.build();
6163
detector.setProcessor(
6264
new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory()).build());
6365

0 commit comments

Comments
 (0)