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.
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();`