如何在实时预览中检测人脸方向变化,人脸检测安卓



我正在使用谷歌人脸检测 API 开发一个应用程序,我已经使用了示例项目,我需要的是,我想根据人脸方向变化添加叠加图像(蒙版(,例如:如果人脸向右侧或左侧旋转,我想通过获取坐标值来更新叠加图像。怎么做?.谁能帮忙。提前谢谢。

我已经通过获取检测到的人脸的欧拉 Z 值解决了这个问题。我正在发布我的代码:

当方向改变时,我已经旋转了检测到的脸上的矩形和遮罩位图;

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);

旋转的位图。

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);
}

在画布上绘制旋转蒙版。

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

此外,将快速模式设置为人脸检测器。

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

            .setMode(FaceDetector.FAST_MODE)
            .build();`

最新更新