1. Are you ready for the Galaxy S20? Here is everything we know so far!

Manually setting auto-focus using camera2

Discussion in 'Android Devices' started by Joshua Martinez, Jun 13, 2017.

  1. Joshua Martinez

    Thread Starter

    Using WebCamTexture in your Unity3D program (as a way of cross-platform accessing the camera of devices) unfortunately messes with your Android device focus mode, so it requires a manual fix, hence my trying to write a small Android plug-in for Unity3D, in order to set my Android device camera auto-focus manually for scanning and character recognition (i.e. constant sharp focus).

    I am, however, finding it difficult to get used to the new camera2 API. I need a little help turning the old Camera API code (commented out bit at the bottom) into the new camera2 compatible program, just so I can then turn this Android program into a plug-in and then call it from within a Unity3D C# program.

    My variable declarations are obviously fine, but the other 3 lines are all underlined red as error. Could someone please help me get this right?

    Code (Text):
    1.  
    2. package com.example.ocrfocusunityplugin;
    3.  
    4. import android.hardware.camera2.*;
    5. import java.util.List;
    6.  
    7. public class OcrFocusPluginClass
    8. {
    9.     public void EnableAutofocus()
    10.     {
    11.         String cameraId;                // camera ID -> 0 for Back and 1 for Front
    12.         CameraDevice camera;
    13.         CameraManager manager;
    14.         CameraCaptureSession session;
    15.         CameraDevice.StateCallback callback;
    16.  
    17.         cameraId = manager.getCameraIdList()[0];
    18.         manager.openCamera(cameraId, callback, null);
    19.         CameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES);
    20.  
    21.         /*
    22.             camera = Camera.open();
    23.             Camera.Parameters parameters = camera.getParameters();
    24.             List<String> focusModes = parameters.getSupportedFocusModes();
    25.  
    26.             if ( focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO) )
    27.             {
    28.                 parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    29.             }
    30.  
    31.             camera.setParameters(parameters);
    32.         */
    33.     }
    34. }
    35.  
     



    1. Download the Forums for Android™ app!


      Download

       
  2. Joshua Martinez

    Thread Starter

    Has anyone on this forum ever developed and deployed to Android a Unity3D game/app that used camera or WebCamTexture???
     
  3. Phalon4

    Phalon4 Android Enthusiast

    I hope you have all the device systems original format backed up somewhere became messing around with the device platform can be irreversible if you're not sure about what you're doing. All of what you asked would fall under Device Development Programming. I would try getting information such as that from Android Studio software.
     
  4. Joshua Martinez

    Thread Starter

    I am not sure if I understand you...
    What I am trying to do is achieve the suggested solution in this post:
    https://stackoverflow.com/questions...o-focus-with-unity3d#comment76064590_19076316
    setting the auto focus of a galaxy tablet via code.
     

Samsung Galaxy Tab S2 Forum

The Samsung Galaxy Tab S2 release date was September 2015. Features and Specs include a 8.0" inch screen, 8MP camera, 3GB RAM, Exynos 5433 processor, and 4000mAh battery.

September 2015
Release Date
0
Reviews
Loading...
Similar Threads - Manually setting auto
  1. halfbeing
    Replies:
    3
    Views:
    597
  2. marctronixx
    Replies:
    1
    Views:
    421
  3. marctronixx
    Replies:
    0
    Views:
    507
  4. Vladdelia012
    Replies:
    3
    Views:
    446
  5. OnGoGS7A
    Replies:
    2
    Views:
    1,174
  6. Earendil_Strife
    Replies:
    5
    Views:
    1,376
  7. jewu
    Replies:
    2
    Views:
    693
  8. Android Idiot 587
    Replies:
    4
    Views:
    533
  9. kn0ckkn0ck
    Replies:
    2
    Views:
    387
  10. fennee
    Replies:
    8
    Views:
    1,432

Share This Page

Loading...