Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble with FOCUS_MODE_CONTINUOUS_PICTURE on Galaxy S5

I'm working on an Android app that uses the camera to preview and take pictures. I use FOCUS_MODE_CONTINUOUS_PICTURE with the galaxy S4 and find that the focusing works very well.

However, on the galaxy S5 the FOCUS_MODE_CONTINUOUS_PICTURE rarely ever finds the focus properly. The camera will zoom into focus, but then zoom back out of focus repeatedly.

Does anyone have an idea of why the FOCUS_MODE_CONTINUOUS_PICTURE works so poorly on the S5, or can anyone confirm whether or not they have the same issue?

like image 574
bcorso Avatar asked Aug 15 '14 06:08

bcorso


1 Answers

I too have experienced these same issues.

The Galaxy S5, and possibly other devices, don't seem to have reliable behavior in continuous picture focus mode. This is very frustrating as a developer, when code works perfectly on most devices, but then along comes the S5 (a very popular device) and we look pretty bad.

After much head scratching, I think I have a solution (more of a workaround) that is working well.

  1. set camera to FOCUS_MODE_CONTINUOUS_PICTURE
  2. in gesture handler for taking a photo (e.g. button tap, touch event), switch camera to FOCUS_MODE_AUTO, then call Camera.autoFocus() in a deferred manner

this provides the nice continuous focus UI during photo preview, but takes the picture in reliable auto-focus mode.

Here is the code:

 protected void onTakePicture()
 {

  // mCamera is the Camera object
  // mAutoFocusCallback is a Camera.AutoFocusCallback handler

  try
  {

   // determine current focus mode
   Camera.Parameters params = mCamera.getParameters();
          if (params.getFocusMode().equals(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE))
   {
    mCamera.cancelAutoFocus();      // cancels continuous focus

    List<String> lModes = params.getSupportedFocusModes();
    if (lModes != null)
    {
     if (lModes.contains(Camera.Parameters.FOCUS_MODE_AUTO))
     {
      params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); // auto-focus mode if supported
      mCamera.setParameters(params);        // set parameters on device
     }
    }

    // start an auto-focus after a slight (100ms) delay
    new Handler().postDelayed(new Runnable() {

     public void run()
     {
      mCamera.autoFocus(mAutoFocusCallback);    // auto-focus now
     }

    }, 100);

    return;
   }

   mCamera.autoFocus(mAutoFocusCallback);       // do the focus, callback is mAutoFocusCallback

  }
  catch (Exception e)
  {
   Log.e("myApp", e.getMessage());
  }
}

please give this a try and report back your results

like image 168
CSmith Avatar answered Oct 15 '22 11:10

CSmith