Android Question [Solved] Camera2 API in "manual mode"

Discussion in 'Android Questions' started by freedom2000, May 22, 2019.

  1. freedom2000

    freedom2000 Well-Known Member Licensed User

    Dear all,

    I am currently testing camera2 lib and it works really well with the provided example on my Samsung Galaxy S7.

    I would like to use the camera in fully manual mode to setup a DIY spectrometer with the smartphone (more on this on a future post !)

    To do that I would need to access to :
    manual focus and manual speed and sensor sentitivity and of course AE exposure off and finally (for now) the lens aperture

    So reading the API it seems feasible, but I must admit that I am still a little lost into the camera2 API.
    So if you had some existing code, it would help me a lot :oops:

    I can't help showing you my first try of my 3D printed spectrometer (image taken with the legacy App of my phone...). With such a nice result, you can imagine how it would be exciting to plot the 2D spectrum in real time... Another story !

    CFL_spectrum.jpg
     
    Last edited: May 22, 2019
  2. freedom2000

    freedom2000 Well-Known Member Licensed User

    Hi again,

    After digging a little into the code, I already got the AE_Exposure_OFF from this sub : setAutoExposureMode ("OFF")

    I can also disable the Auto Focus from this sub : setFocusMode("OFF")

    Still missing how to set the manual focus distance, the manual speed, the sensor sensitivity and the lens aperture...

    And seems that I am stuck for the available apertures... Only one in the Float list
    android.lens.info.availableApertures: [1.7] --> [F

    so will have to play with exposure time :
    android.sensor.info.exposureTimeRange: [22000, 100000000] --> android.util.Range

    and ISO values :
    android.sensor.info.sensitivityRange: [64, 1600] --> android.util.Range

    BTW @Erel : you made a great job with this class and lib. Thanks
     
    Last edited: May 22, 2019
  3. freedom2000

    freedom2000 Well-Known Member Licensed User

    After digging even more I found this link : https://www.b4x.com/android/forum/threads/how-to-preserve-focusmode-of-a-camera.102621/#post-643855

    Where it is said :
    If the desired focus distance is constant then you might be able to set it manually by setting the LENS_FOCUS_DISTANCE: https://developer.android.com/reference/android/hardware/camera2/CaptureRequest#LENS_FOCUS_DISTANCE
    You need to put this key in CaptureSettingMap and PreviewSettingsMap. The value should be a float number.

    I guess that you need to set AutoFocus to OFF for this.

    This is exactly what I would like to do !

    So now : how ?

    --> should be there ? Sub SetBothMaps(Key As String, Value As Object)
     
  4. freedom2000

    freedom2000 Well-Known Member Licensed User

    YES it works !

    Just added this in the CamEx2 class :

    Code:
    Public Sub setManualFocus (Dist As Float)
        SetBothMaps(
    "LENS_FOCUS_DISTANCE", Dist)
    End Sub
    and now I can force manual focus while Auto Focus is Off :

    Code:
    If (focuses.Get(i) = "OFF"Then
        cam.ManualFocus=
    10.0
    End If
     
  5. DonManfred

    DonManfred Expert Licensed User

    in camex2 class you can find for ex

    Code:
    Public Sub setAutoExposureMode (Mode As String)
        SetBothMaps(
    "CONTROL_AE_MODE", AE_MODE.IndexOf(Mode))
        PreviewSettingsMap.Put(
    "FLASH_MODE", FLASH_MODE.IndexOf("OFF"))
        
    If Mode = "ON_ALWAYS_FLASH" Then
            CaptureSettingMap.Put(
    "FLASH_MODE", FLASH_MODE.IndexOf("SINGLE"))
        
    End If
    End Sub
    You need to add it to the CaptureSettingMap i guess.

    Code:
    CaptureSettingMap.Put("LENS_FOCUS_DISTANCE", value)
     
    freedom2000 likes this.
  6. freedom2000

    freedom2000 Well-Known Member Licensed User

    works also in "MACRO" focus mode with even shorter distances :

    Code:
    If (focuses.Get(i) = "MACRO"Then
        cam.ManualFocus=
    5.0
    End If
     
  7. freedom2000

    freedom2000 Well-Known Member Licensed User

    Yep I found it !
    Thanks
     
  8. freedom2000

    freedom2000 Well-Known Member Licensed User

    So here is the modified code for "full manual mode"

    into CamEx2 class add :
    Code:
    Public Sub setManualFocus (Dist As Float)
        SetBothMaps(
    "LENS_FOCUS_DISTANCE", Dist)
    End Sub

    Public Sub setSensorSensitivity (Iso As Int)
        SetBothMaps(
    "SENSOR_SENSITIVITY", Iso)
    End Sub

    Public Sub setExposureTime (ttime As Long)
        SetBothMaps(
    "SENSOR_EXPOSURE_TIME", ttime)
    End Sub
    then use it when autoExposure is OFF
    and Auto focus is OFF or MACRO

    Code:
    If (flashes.Get(i) = "OFF"Then
            cam.SensorSensitivity = 
    50
            cam.ExposureTime = 
    22000000.0
        
    End If
    Code:
    If (focuses.Get(i) = "MACRO"Then
        cam.ManualFocus=
    8.0
    End If
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice