Android camera2人脸检测 [英] Android camera2 face detection

查看:104
本文介绍了Android camera2人脸检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有足够的有关camera2人脸检测机制的信息.我使用了Google的Camera2示例: https://github.com/android/camera-samples

There is not enough info about camera2 face detection mechanism. I used Camera2 sample from Google: https://github.com/android/camera-samples

我将面部检测模式设置为FULL.

I set face detection mode to FULL.

mPreviewRequestBuilder.set(CaptureRequest.STATISTICS_FACE_DETECT_MODE,
                                    CameraMetadata.STATISTICS_FACE_DETECT_MODE_FULL);

我也检查了

STATISTICS_INFO_MAX_FACE_COUNTSTATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES:

int max_count = characteristics.get(
CameraCharacteristics.STATISTICS_INFO_MAX_FACE_COUNT);
int modes [] = characteristics.get(
CameraCharacteristics.STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES);

输出: maxCount:5,模式:[0,2]

我的CaptureCallback:

My CaptureCallback:

 private CameraCaptureSession.CaptureCallback mCaptureCallback
 = new CameraCaptureSession.CaptureCallback() {

    private void process(CaptureResult result) {
                Integer mode = result.get(CaptureResult.STATISTICS_FACE_DETECT_MODE);
                Face [] faces = result.get(CaptureResult.STATISTICS_FACES);
                if(faces != null && mode != null)
                    Log.e("tag", "faces : " + faces.length + " , mode : " + mode ); 
    }

    @Override
    public void onCaptureProgressed(CameraCaptureSession session, CaptureRequest request,
                                    CaptureResult partialResult) {
        process(partialResult);
    }

    @Override
    public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
                                   TotalCaptureResult result) {
        process(result);
    }

输出:面孔:0,模式:2

 public static final int STATISTICS_FACE_DETECT_MODE_FULL = 2;

脸部长度始终为0.看起来它无法正确检测到脸部,或者我错过了某些东西.

Faces length is constantly 0. Looks like it doesn't detect a face properly or I missed something.

我知道使用 FaceDetector 的方法.我只是想检查一下它如何与新的camera2 Face .

I know approach with FaceDetector. I just wanted to check how it works with new camera2 Face.

推荐答案

我发现只有在STATE_PREVIEW的情况下,您才能处理结果以显示人脸长.

I found that only in case STATE_PREVIEW, you can process the result to show faces lenth. Change from

private CameraCaptureSession.CaptureCallback mCaptureCallback
        = new CameraCaptureSession.CaptureCallback() {

    private void process(CaptureResult result) {
        Integer mode = result.get(CaptureResult.STATISTICS_FACE_DETECT_MODE);
        Face[] faces = result.get(CaptureResult.STATISTICS_FACES);
        if(faces != null && mode != null) {
            Log.e("tag", "faces : " + faces.length + " , mode : " + mode);
        }

        switch (mState) {
            case STATE_PREVIEW: {
                // We have nothing to do when the camera preview is working normally.
                break;
            }
...

private CameraCaptureSession.CaptureCallback mCaptureCallback
        = new CameraCaptureSession.CaptureCallback() {

    private void process(CaptureResult result) {


        switch (mState) {
            case STATE_PREVIEW: {
              Face[] faces = result.get(CaptureResult.STATISTICS_FACES);
              if (faces != null && faces.length > 0) {
                  Log.e("tag", "faces : " + faces.length);
              }
                break;
            }

请尝试此操作,看看是否有效.

Please try this to see if it works.

这篇关于Android camera2人脸检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆