[英]How to detect face orientation changes on live preview ,face detection android
我正在使用google-face detection API開發應用程序,我使用了示例項目,我需要的是,我想根據面部方向的變化來添加疊加圖像(蒙版),例如:如果將面部旋轉到右側或我想通過獲取坐標值來更新覆蓋的圖像。如何執行此操作?任何人都可以幫忙。
我已經通過獲取檢測到的人臉的Euler 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();`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.