Setting a continuous focus area in RNCamera












0















I'm working on a React Native camera app, trying to move the main focus point of the camera away from the center, because we've been running into some issues with finding steady focus there. Tap to focus has worked as a stopgap solution so far, but what I'm really after is continuous focus on a different area of the camera view.



Working on Android, react native version 0.55.2, with a modified version of RNCamera 1.1.2



To start with I tried to set it on the same trigger as the tap to focus, and managed to make it focus on the assigned area, but only once, and only on a touch. Using this function, inserted into Camera1.java, called by overriding OnTouch in CameraView.java



public void submitFocusAreaRect(final Camera.Area focusArea)
{
if (mCameraParameters.getMaxNumFocusAreas() == 0) { return; }

// Submit focus area to camera
ArrayList<Camera.Area> focusAreas = new ArrayList<Camera.Area>();
//focusAreas.add(focusArea);
focusAreas.add(new Camera.Area(new Rect(0, -1000, 1000, 1000), 1000));

mCameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
mCameraParameters.setFocusAreas(focusAreas);
mCamera.setParameters(mCameraParameters);

// Start the autofocus operation
mCamera.autoFocus(new Camera.AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
mCamera.cancelAutoFocus();
}
});
}


So, it at least looks possible, but I'm having a real hard time trying to make it continuous. What I've tried so far:




  • Setting the focus mode to FOCUS_MODE_CONTINUOUS_PICTURE or FOCUS_MODE_CONTINUOUS_VIDEO seems to lock the focus in place when called. Documentation gives the impression it should resume after calling cancelAutoFocus, but that doesn't seem to be happening?


  • Inserting the relevant lines into adjustCameraParameters or setAutoFocusInternal seems to have no effect.



Does anybody have any advice on how to make the focus continuous?










share|improve this question



























    0















    I'm working on a React Native camera app, trying to move the main focus point of the camera away from the center, because we've been running into some issues with finding steady focus there. Tap to focus has worked as a stopgap solution so far, but what I'm really after is continuous focus on a different area of the camera view.



    Working on Android, react native version 0.55.2, with a modified version of RNCamera 1.1.2



    To start with I tried to set it on the same trigger as the tap to focus, and managed to make it focus on the assigned area, but only once, and only on a touch. Using this function, inserted into Camera1.java, called by overriding OnTouch in CameraView.java



    public void submitFocusAreaRect(final Camera.Area focusArea)
    {
    if (mCameraParameters.getMaxNumFocusAreas() == 0) { return; }

    // Submit focus area to camera
    ArrayList<Camera.Area> focusAreas = new ArrayList<Camera.Area>();
    //focusAreas.add(focusArea);
    focusAreas.add(new Camera.Area(new Rect(0, -1000, 1000, 1000), 1000));

    mCameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    mCameraParameters.setFocusAreas(focusAreas);
    mCamera.setParameters(mCameraParameters);

    // Start the autofocus operation
    mCamera.autoFocus(new Camera.AutoFocusCallback() {
    @Override
    public void onAutoFocus(boolean success, Camera camera) {
    mCamera.cancelAutoFocus();
    }
    });
    }


    So, it at least looks possible, but I'm having a real hard time trying to make it continuous. What I've tried so far:




    • Setting the focus mode to FOCUS_MODE_CONTINUOUS_PICTURE or FOCUS_MODE_CONTINUOUS_VIDEO seems to lock the focus in place when called. Documentation gives the impression it should resume after calling cancelAutoFocus, but that doesn't seem to be happening?


    • Inserting the relevant lines into adjustCameraParameters or setAutoFocusInternal seems to have no effect.



    Does anybody have any advice on how to make the focus continuous?










    share|improve this question

























      0












      0








      0








      I'm working on a React Native camera app, trying to move the main focus point of the camera away from the center, because we've been running into some issues with finding steady focus there. Tap to focus has worked as a stopgap solution so far, but what I'm really after is continuous focus on a different area of the camera view.



      Working on Android, react native version 0.55.2, with a modified version of RNCamera 1.1.2



      To start with I tried to set it on the same trigger as the tap to focus, and managed to make it focus on the assigned area, but only once, and only on a touch. Using this function, inserted into Camera1.java, called by overriding OnTouch in CameraView.java



      public void submitFocusAreaRect(final Camera.Area focusArea)
      {
      if (mCameraParameters.getMaxNumFocusAreas() == 0) { return; }

      // Submit focus area to camera
      ArrayList<Camera.Area> focusAreas = new ArrayList<Camera.Area>();
      //focusAreas.add(focusArea);
      focusAreas.add(new Camera.Area(new Rect(0, -1000, 1000, 1000), 1000));

      mCameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
      mCameraParameters.setFocusAreas(focusAreas);
      mCamera.setParameters(mCameraParameters);

      // Start the autofocus operation
      mCamera.autoFocus(new Camera.AutoFocusCallback() {
      @Override
      public void onAutoFocus(boolean success, Camera camera) {
      mCamera.cancelAutoFocus();
      }
      });
      }


      So, it at least looks possible, but I'm having a real hard time trying to make it continuous. What I've tried so far:




      • Setting the focus mode to FOCUS_MODE_CONTINUOUS_PICTURE or FOCUS_MODE_CONTINUOUS_VIDEO seems to lock the focus in place when called. Documentation gives the impression it should resume after calling cancelAutoFocus, but that doesn't seem to be happening?


      • Inserting the relevant lines into adjustCameraParameters or setAutoFocusInternal seems to have no effect.



      Does anybody have any advice on how to make the focus continuous?










      share|improve this question














      I'm working on a React Native camera app, trying to move the main focus point of the camera away from the center, because we've been running into some issues with finding steady focus there. Tap to focus has worked as a stopgap solution so far, but what I'm really after is continuous focus on a different area of the camera view.



      Working on Android, react native version 0.55.2, with a modified version of RNCamera 1.1.2



      To start with I tried to set it on the same trigger as the tap to focus, and managed to make it focus on the assigned area, but only once, and only on a touch. Using this function, inserted into Camera1.java, called by overriding OnTouch in CameraView.java



      public void submitFocusAreaRect(final Camera.Area focusArea)
      {
      if (mCameraParameters.getMaxNumFocusAreas() == 0) { return; }

      // Submit focus area to camera
      ArrayList<Camera.Area> focusAreas = new ArrayList<Camera.Area>();
      //focusAreas.add(focusArea);
      focusAreas.add(new Camera.Area(new Rect(0, -1000, 1000, 1000), 1000));

      mCameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
      mCameraParameters.setFocusAreas(focusAreas);
      mCamera.setParameters(mCameraParameters);

      // Start the autofocus operation
      mCamera.autoFocus(new Camera.AutoFocusCallback() {
      @Override
      public void onAutoFocus(boolean success, Camera camera) {
      mCamera.cancelAutoFocus();
      }
      });
      }


      So, it at least looks possible, but I'm having a real hard time trying to make it continuous. What I've tried so far:




      • Setting the focus mode to FOCUS_MODE_CONTINUOUS_PICTURE or FOCUS_MODE_CONTINUOUS_VIDEO seems to lock the focus in place when called. Documentation gives the impression it should resume after calling cancelAutoFocus, but that doesn't seem to be happening?


      • Inserting the relevant lines into adjustCameraParameters or setAutoFocusInternal seems to have no effect.



      Does anybody have any advice on how to make the focus continuous?







      android react-native autofocus react-native-camera






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 10:11









      SocrateaseSocratease

      768




      768
























          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335620%2fsetting-a-continuous-focus-area-in-rncamera%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335620%2fsetting-a-continuous-focus-area-in-rncamera%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues