Android camera2 face detection

后端 未结 3 1800
抹茶落季
抹茶落季 2020-12-15 16:38

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

I set face detection mo

3条回答
  •  佛祖请我去吃肉
    2020-12-15 16:48

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

    to

    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.

提交回复
热议问题