google-ar / arcore-android-sdk

ARCore SDK for Android Studio
https://developers.google.com/ar
Other
4.96k stars 1.22k forks source link

Camera2 precapture sequence with ARCore SharedCamera #1324

Open vrebenyi opened 2 years ago

vrebenyi commented 2 years ago

SPECIFIC ISSUE ENCOUNTERED

I would like to take pictures with the proper Camera2 API way with ARCore SharedCamera:

  1. Lock focus.
  2. Run precapture sequence.
  3. Capture still picture.
  4. Unlock focus.

I try to use auto flash as well: captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH)

So based on the result of the precapture sequence I might need flash for image taking. I realized that I have to stop the AR session with ARCore Session's pause() function before starting the image taking process with lock focus to make it work.

The problem is that this does not work on all devices. Here is a table of my test results: Device OS Version Is flash working?
Samsung Galaxy A30 Android 9 YES
Samsung Galaxy A7 Android 10 YES
Samsung Galaxy Tab S3 Android 9 NO
Samsung Galaxy A20s Android 10 NO
Samsung Galaxy S20 FE Android 11 NO
Pixel2 Android 11 NO
Samsung S7 Android 8 NO
Samsung A8 Android 9 YES
Huawei Nova 2i Android 8 YES
Huawei P10 Android 9 YES
Samsung Galaxy A51 Android 11 NO

You can see that it is not related to device manufacturer or OS version.

After some tests and investigation I figured out, that if I wait for at least 1 sec after pausing the AR session the flash is working properly, however it is a very ugly workaround to fix it. It seems the in case of some device AR session needs more time to stop(?), so the camera2 part can do its job. But it just a guess.

The question is: Is there any event or workaround by which we know that ARCore session is paused successfully and Camera2 is ready to work? Or is my assumption totally wrong and it should work in a different way?

VERSIONS USED

mrousavy commented 1 year ago

Hey - Did you find out why?