title: Who has a material how to work with the Face Detection Camera 2 API?
body: <p>On the official sources did not find the information ... There are many examples of how to work with the Camera API, but how to work with Camera2API anything ... a couple of discussions at Stake and all ... there is a similar question to me, but I have a problem not solved. ..</p>
  
  <p><strong>link to the same quetion :</strong>
  <a href="https://stackoverflow.com/questions/30334319/android-camera2-face-recognition">Android camera2 face recognition</a></p>
  
  <p><strong>I took the example of <a href="https://github.com/googlesamples/android-Camera2Basic" rel="nofollow noreferrer">Google's API for Camera 2</a></strong>.</p>
  
  <p>That's what I did, but I did not detect a face :</p>
  
  <p>I added events</p>
  
  <pre><code>    private void createCameraPreviewSession() {
      try {
          SurfaceTexture texture = mTextureView.getSurfaceTexture();
          assert texture != null;
  
          // We configure the size of default buffer to be the size of camera preview we want.
          texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
  
          // This is the output Surface we need to start preview.
          Surface surface = new Surface(texture);
  
          // We set up a CaptureRequest.Builder with the output Surface.
          mPreviewRequestBuilder
                  = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
          mPreviewRequestBuilder.addTarget(surface);
  
          // Here, we create a CameraCaptureSession for camera preview.
          mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),
                  new CameraCaptureSession.StateCallback() {
  
                      @Override
                      public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
                          // The camera is already closed
                          if (null == mCameraDevice) {
                              return;
                          }
  
                          // When the session is ready, we start displaying the preview.
                          mCaptureSession = cameraCaptureSession;
                          try {
  
  
  
  //           ----&gt;&gt;         Установка модуля распознания лица
                              mPreviewRequestBuilder.set(CaptureRequest.STATISTICS_FACE_DETECT_MODE,
                                      CameraMetadata.STATISTICS_FACE_DETECT_MODE_FULL);
  
  
  
                              // Auto focus should be continuous for camera preview.
                              mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                                      CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
  
                              // Flash is automatically enabled when necessary.
                              setAutoFlash(mPreviewRequestBuilder);
  
                              // Finally, we start displaying the camera preview.
                              mPreviewRequest = mPreviewRequestBuilder.build();
  
                              mCaptureSession.setRepeatingRequest(mPreviewRequest,
                                      mCaptureCallback, mBackgroundHandler);
                          } catch (CameraAccessException e) {
                              e.printStackTrace();
                          }
                      }
  
                      @Override
                      public void onConfigureFailed(
                              @NonNull CameraCaptureSession cameraCaptureSession) {
                          System.out.println("Failed строка 757");
                      }
                  }, null
          );
      } catch (CameraAccessException e) {
          e.printStackTrace();
      }
  }
  
  private CameraCaptureSession.CaptureCallback mCaptureCallback
          = new CameraCaptureSession.CaptureCallback() {
  
      @Override
      public void onCaptureProgressed(@NonNull CameraCaptureSession session,
                                      @NonNull CaptureRequest request,
                                      @NonNull CaptureResult partialResult) {
          process(partialResult);
      }
  
      @Override
      public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                                     @NonNull CaptureRequest request,
                                     @NonNull TotalCaptureResult result) {
          process(result);
      }
  
      private void process(CaptureResult result) {
  
  
  ---&gt;   //здесь проверяю получает ли он массив лиц или нет + непонятный мод
          Integer mode = result.get(CaptureResult.STATISTICS_FACE_DETECT_MODE);
          Face[] faces = result.get(CaptureResult.STATISTICS_FACES);
          if(faces != null &amp;&amp; mode != null)
              System.out.println("tagDDDDDDDDDDDDDDDDDDDDDDDD" + "faces : " +
                      faces.length + " , mode : " + mode);
  
          switch (mState) {
              case STATE_PREVIEW: {
                  // We have nothing to do when the camera preview is working normally.
  
  //                  Here i set Face Detection
                  mPreviewRequestBuilder.set(CaptureRequest.STATISTICS_FACE_DETECT_MODE,
                          CameraMetadata.STATISTICS_FACE_DETECT_MODE_FULL);
                  break;
              }
  </code></pre>
  
  <p><strong>here i am checking max count of faces that camera can get</strong></p>
  
  <pre><code>    private void setUpCameraOutputs(int width, int height) {
  
      CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
      try {
          for (String cameraId : manager.getCameraIdList()) {
              CameraCharacteristics characteristics
                      = manager.getCameraCharacteristics(cameraId);
  
              // We don't use a front facing camera in this sample.
              Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
              if (facing != null &amp;&amp; facing == CameraCharacteristics.LENS_FACING_FRONT) {
                  continue;
              }
  
              max_count = characteristics.get(
                      CameraCharacteristics.STATISTICS_INFO_MAX_FACE_COUNT);
              modes = characteristics.get(
                      CameraCharacteristics.STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES);
  
              System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! max_count " + max_count + " modes " + modes);
  </code></pre>
  
  <p>** Output is: **</p>
  
  <pre><code>I/System.out: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! max_count 16 modes [I@3e2907e8
  </code></pre>
  
  <p>** And this is what a log prints **</p>
  
  <pre><code>    03-08 18:34:07.018 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
  03-08 18:34:07.048 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
  03-08 18:34:07.078 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
  03-08 18:34:07.118 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
  03-08 18:34:07.148 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
  03-08 18:34:07.178 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
  03-08 18:34:07.218 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
  03-08 18:34:07.258 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
  03-08 18:34:07.288 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
  03-08 18:34:07.308 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
  03-08 18:34:07.348 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
  </code></pre>
  
  <p>Why it isn't reterning face? If someone have a correct working exsample, give please a link. How i can make face detection with camera2API. Throughout the week, I can not understand((</p>