Preview using Auto AE mode while capture using manual AE - is it possible?

342 views
Skip to first unread message

László Heller

unread,
Jun 4, 2022, 3:47:29 AM6/4/22
to Android CameraX Discussion Group
Hi!

My goal is to create a camera app which is able to take pictures using manual ISO and shutter speed settings. In other words manual AE.
When I change my preview builder's settings, the preview picture is blank and I cannot take picture:

var pb = new Preview.Builder();
var ext1 = new Camera2Interop.Extender(pb)
        .SetCaptureRequestOption(CaptureRequest.ControlAeMode, (int)ControlAEMode.Off)
        .SetCaptureRequestOption(CaptureRequest.SensorSensitivity, 400)
        .SetCaptureRequestOption(CaptureRequest.SensorExposureTime, 100000000); // 100 000 000 ns = 100 000 us = 100 ms
var preview = pb.SetTargetName("PREVIEW").Build();
preview.SetSurfaceProvider(sfcPreview.SurfaceProvider);

The same, when I keep auto AE settings for preview and use manual AE for capture:

var cb = new ImageCapture.Builder();
var ext2 = new Camera2Interop.Extender(cb)
        .SetCaptureRequestOption(CaptureRequest.ControlAeMode, (int)ControlAEMode.Off)
        .SetCaptureRequestOption(CaptureRequest.SensorSensitivity, 400)
        .SetCaptureRequestOption(CaptureRequest.SensorExposureTime, 100000000); // 100 000 000 ns = 100 000 us = 100 ms
capture = cb
        .SetTargetResolution(new Size(800, 600))
        .SetTargetName("CAPTURE")
        .Build();

So my question is: How to properly configure preview for auto AE and at the same time capture for manual AE or whether it is possible at all?

BR,

Ladislav

Scott Nien

unread,
Jun 5, 2022, 11:33:16 PM6/5/22
to László Heller, Android CameraX Discussion Group
Hi Ladislav,
Currently CameraX doesn't support setting camera2 parameters only for still capture.  The parameters you set in the ImageCapture will actually apply to the whole repeating request (hence the preview)

I may miss something but I think ensuring preview and still capture have similar camera output is quite important for users to see what they will get before capturing. 


--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/67b9e636-057b-4d20-bb74-da26d11e7bd5n%40android.com.

László Heller

unread,
Jun 6, 2022, 4:48:11 AM6/6/22
to Android CameraX Discussion Group, Scott Nien, Android CameraX Discussion Group, László Heller
Hi!

OK, but when I try to set manual settings only for preview, I get only blank/black screen in app's preview surface.
See the lines 84-91 of the IRunnable.Run() method:
Code1.png

When I comment out the lines 86-89, the preview (and also take picture) works well.

So how to enable manual exposure correctly in CameraX ?
BTW my device is Samsung Galaxy S20+ which supports manual mode!

BR,

Ladislav

Scott Nien

unread,
Jun 6, 2022, 11:36:22 PM6/6/22
to László Heller, Android CameraX Discussion Group
I tested it with the same manual AE parameters you set on Galaxy Z Fold2 and Pixel 6 and I can see the preview (it's a little bit over-exposed). 
I think this is probably the Galaxy S20+ issue.  Can you try adjusting the parameters ? 


László Heller

unread,
Jun 8, 2022, 10:16:19 AM6/8/22
to Android CameraX Discussion Group, Scott Nien, Android CameraX Discussion Group, László Heller
Can U please share your FULL code?
It is really annoying that it doesn't work for me. Tried also change the parameters, but the result is same: Blank/black preview screen.

Scott Nien

unread,
Jun 9, 2022, 12:20:57 AM6/9/22
to László Heller, Android CameraX Discussion Group

My modification is to replace the following block 
 preview = Preview.Builder()
                // We request aspect ratio but no resolution
                .setTargetAspectRatio(screenAspectRatio)
                // Set initial target rotation
                .setTargetRotation(rotation)
                .build()


with 

        val pb = Preview.Builder()
                // We request aspect ratio but no resolution
                .setTargetAspectRatio(screenAspectRatio)
                // Set initial target rotation
                .setTargetRotation(rotation)

        Camera2Interop.Extender(pb)
                .setCaptureRequestOption(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF)
                .setCaptureRequestOption(CaptureRequest.SENSOR_SENSITIVITY, 400)
                .setCaptureRequestOption(CaptureRequest.SENSOR_EXPOSURE_TIME, 100000000) // 100 000 000 ns = 100 000 us = 100 ms

        preview = pb.build()


And if I understand it correctly,  you were using Xamarin .  I am not sure if something went wrong with Xamarin. 

Scott

László Heller

unread,
Jun 9, 2022, 8:06:47 AM6/9/22
to Android CameraX Discussion Group, Scott Nien, Android CameraX Discussion Group, László Heller
Hi!

Yes, I am using Xamarin. BTW the problem was solved. Don't ask why, but for sensor exposure time value I have to tell explicitly that the value is a long.

So instead of
.SetCaptureRequestOption(CaptureRequest.SensorExposureTime, 100000000)

I had to call
.SetCaptureRequestOption(CaptureRequest.SensorExposureTime, 100000000L)

...and it works!

BR,

Ladislav

Scott Nien

unread,
Jun 9, 2022, 10:50:59 AM6/9/22
to László Heller, Android CameraX Discussion Group
Hi Ladislav, 

Very interesting.  You actually identified one potential issue of camera2Interop API. 

I realize that if you use  
     new Camera2Interop.Extender(pb)  
instead of  
     new Camera2Interop.Extender<>(pb)

The value type checking is ignored by the compiler somehow.   

If you use the new Camera2Interop.Extender<>(pb) and try to set an int to the Long key,  it will build fail. 




Reply all
Reply to author
Forward
0 new messages