2

I am developing an app using google-face detection API, I have used the sample project, what I need is, I want to add the overlay image (mask) based on face orientation changes, eg: if face is rotated to right side or left side I want to update the overlayed image by taking the coordinate values.How to do this?.Can anyone help.Thanks in advance.

Jack
  • 1,825
  • 3
  • 26
  • 43

1 Answers1

3

I have solved this issue by taking Euler Z value of detected face.I am posting my code:

I have rotated the rectangle and the mask bitmap on detected face when orientation changes;

RectF dest = new RectF((int) left, (int) top, (int) right, (int) bottom);

        Matrix m = new Matrix();

        m.setRotate(face.getEulerZ(),dest.centerX(),dest.centerY());
        m.mapRect(dest);

Rotated bitmap.

public Bitmap rotate_bitmap(Bitmap bmp,float degree){
    Matrix matrix = new Matrix();

    matrix.postRotate(degree);

    return Bitmap.createBitmap(bmp , 0, 0, bmp .getWidth(), bmp .getHeight(), matrix, true);
}

Drawing rotated mask on canvas.

            canvas.drawBitmap(rotate_bitmap(faceTrackerActivity.getBitmapItem("face"),face.getEulerZ()), null, dest, null);

Also, set FAST MODE to face detector.

FaceDetector detector = new FaceDetector.Builder(context)
            .setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)


            .setMode(FaceDetector.FAST_MODE)
            .build();`
Jack
  • 1,825
  • 3
  • 26
  • 43
  • i have used your code but image not changed immmediately after rotation in android – sathish mobapp dev Oct 26 '18 at 09:11
  • float xOffset = scaleX(face.getWidth() / 2.0f); float yOffset = scaleY(face.getHeight() / 2.0f); float left = x - xOffset; float top = y - yOffset; float right = x + xOffset; float bottom = y + yOffset; – sathish mobapp dev Oct 27 '18 at 07:36