我正在使用google-face detection API开发应用程序,我使用了示例项目,我需要的是,我想根据面部方向的变化来添加叠加图像(蒙版),例如:如果将面部旋转到右侧或我想通过获取坐标值来更新覆盖的图像。如何执行此操作?任何人都可以帮忙。
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();`
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.