日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android 人脸识别demo,Android Camera 内置人脸识别的Demo

發布時間:2024/1/1 Android 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 人脸识别demo,Android Camera 内置人脸识别的Demo 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

CameraFace

Android Camera 內置人臉識別的Demo

通過Android源生API支持的人臉識別FaceDetection,獲取到臉部矩形坐標,左右眼坐標,嘴坐標通過View動態實攝像頭實時裝飾功能

主要方法

//人臉識別設置監聽

mCamera.setFaceDetectionListener(mFaceDetectionListener);

//人臉識別監聽啟動

mCamera.startFaceDetection();

class FaceDetectionListener implements Camera.FaceDetectionListener{

@Override

public void onFaceDetection(Camera.Face[] faces, Camera camera) {

Message m = mHandler.obtainMessage();

m.what = MainActivity.AC_DRAW;

if (null == faces || faces.length == 0) {

m.obj = null;

Log.d("face", "onFaceDetection : There is no face found.");

} else {

Log.d("face", "onFaceDetection : face found.");

m.obj = faces;

for (int i = 0; i < faces.length; i++) {

Camera.Face face = faces[i];

if (face == null)return;

Rect rect = face.rect;

Log.i("face","face.score="+face.score);

Log.i("face","rect.left="+rect.left+"\nrect.top="+rect.top+"\nrect.right="+rect.right+"\nrect.bottom="+rect.bottom);

Log.i("face","id="+face.id+" \nface.leftEye.x="+face.leftEye.x+" \nface.leftEye.y"+face.leftEye.y+" \nface.mouth.x="+face.mouth.x+" \nface.mouth.y="+face.mouth.y);

}

}

m.sendToTarget();

}

}

//faces 識別出的人臉特征數據

public static class Face {

public int id;//對應id

public Point leftEye;//左眼

public Point mouth;//嘴

public Rect rect;//臉部坐標

public Point rightEye;//右眼

public int score;//識別分數

}

//繪制對應的裝飾圖片

protected void onDraw(Canvas canvas) {

if (mFaces == null || mFaces.length < 1) {

return;

}

boolean isMirror = false;

// int Id =CameraInterface.getInstance().getCameraId();

// if(Id == CameraInfo.CAMERA_FACING_BACK){

// isMirror = false; //后置Camera無需mirror

// }else if(Id == CameraInfo.CAMERA_FACING_FRONT){

isMirror = true; //前置Camera需要mirror

// }

// Util.prepareMatrix(mMatrix, isMirror, 90, mCameraW, mCameraH);

Util.prepareMatrix(mMatrix, isMirror, 90, getWidth(), getHeight());

canvas.save();

mMatrix.postRotate(0); //Matrix.postRotate默認是順時針

canvas.rotate(-0); //Canvas.rotate()默認是逆時針

if (mFaces == null){

mFaceIndicatorDraw.draw(canvas);

mLeftEyeDraw.draw(canvas);

mRightEyeDraw.draw(canvas);

mMouthDraw.draw(canvas);

}else {

for (int i = 0; i < mFaces.length; i++) {

Camera.Face face = mFaces[i];

mRect.set(face.rect);

mMatrix.mapRect(mRect);//計算出在父布局的真是坐標

//識別的Rect 系數,使裝飾圖片根據人臉與攝像頭的距離放大或者縮小

float dx = mRect.bottom - mRect.top;

if (isHeadShow){

Log.i(TAG, "FaceView dx=" +dx );

float h = dx * 0.4f;

mHeadDraw.setBounds(Math.round(mRect.left), Math.round(mRect.top - h),

Math.round(mRect.right), Math.round(mRect.bottom - h));

mHeadDraw.draw(canvas);

}

if (isFaceIndicatorShow){

mFaceIndicatorDraw.setBounds(Math.round(mRect.left), Math.round(mRect.top),

Math.round(mRect.right), Math.round(mRect.bottom));

mFaceIndicatorDraw.draw(canvas);

}

if (isLeftEyeShow){

float[] leftEye = {face.leftEye.x, face.leftEye.y};

mMatrix.mapPoints(leftEye);//計算出在父布局的真是坐標

float h = dx * 0.1f;

float w = dx * 0.15f;

mLeftEyeDraw.setBounds(Math.round(leftEye[0]-w), Math.round(leftEye[1]-h),

Math.round(leftEye[0]+w), Math.round(leftEye[1]+h));

mLeftEyeDraw.draw(canvas);

}

if (isRightEyeShow){

float[] rightEye = {face.rightEye.x, face.rightEye.y};

float w = dx * 0.15f;

float h = dx * 0.1f;

mMatrix.mapPoints(rightEye);//計算出在父布局的真是坐標

mRightEyeDraw.setBounds(Math.round(rightEye[0]-w), Math.round(rightEye[1]-h),

Math.round(rightEye[0]+w), Math.round(rightEye[1]+h));

mRightEyeDraw.draw(canvas);

}

if (isMouthShow){

float[] mouthP = {face.mouth.x, face.mouth.y};

mMatrix.mapPoints(mouthP);//計算出在父布局的真是坐標

float w = dx * 0.15f;

float h = dx * 0.2f;

mMouthDraw.setBounds(Math.round(mouthP[0]-w), Math.round(mouthP[1]-h),

Math.round(mouthP[0]+w), Math.round(mouthP[1]));

mMouthDraw.draw(canvas);

}

}

}

canvas.restore();

super.onDraw(canvas);

}

總結

以上是生活随笔為你收集整理的android 人脸识别demo,Android Camera 内置人脸识别的Demo的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。