how to open auxiliary camera

1,070 views
Skip to first unread message

Bob Smith

unread,
Nov 20, 2020, 4:44:55 AM11/20/20
to Android CameraX Discussion Group
When using camera2 api, I can use func createCaptureSession(
SessionConfiguration config) to open auxiliary camera and get image data.

In current camerax api,I use cameraSelector to decide which camera to open,but cameraSelector only can fliter the camera which is back or front ,support hdr extension or not.I cannot make the camerax api to open which camera directly.CameraX always decide to open main camera,thus aux camera is never opened.

would you please tell me whether I can open aux camera with current camerax api?

Thanks

TY Chang

unread,
Nov 20, 2020, 6:55:41 AM11/20/20
to Android CameraX Discussion Group, lss19...@gmail.com
Thanks for the question. There are experimental APIs CameraSelector.Builder#addCameraFilter which allows you to add requirements when selecting camera, and Camera2CameraFilter provides the interface to implement the filtering logic based on Camera2 ID and CameraCharacteristics. So for selecting auxiliary camera, first you have to know what characteristic you want (or specific camera ID). Then the implementation may looks like
        CameraFilter cameraFilter = Camera2CameraFilter.createCameraFilter((idCharMap) -> {
               // Return the map that contatins the camera ID/CameraCharacteristics that matches requirements.
        });
        CameraSelector cameraSelector = new CameraSelector.Builder().addCameraFilter(cameraFilter).build();
Then the CameraSelector can be used to open a camera other than default. But please note that the APIs are still under development and are subject to change.

Bob Smith

unread,
Nov 22, 2020, 9:09:18 PM11/22/20
to Android CameraX Discussion Group, tonyt...@google.com, Bob Smith
Thanks for your answering

In my case,I must use cameras of specific Physical CameraId which I can get from Func getPhysicalCameraIds.For example,"2" and "3" are what I get and what I need in google pixel5.
However,in the Func createCameraFilter,I could only get logical cameraid like "0" and "1",which present back and front camera.

Could you tell me is there more imformation I can get in this Func or is there any way else?

tonyt...@google.com

unread,
Nov 23, 2020, 12:18:41 AM11/23/20
to Android CameraX Discussion Group, lss19...@gmail.com, tonyt...@google.com
So is the camera you need listed in CameraManager#getCameraIdList or it's just part of a logical camera? Now CameraFilter only provides the camera IDs from getCameraIdList.

Bob Smith

unread,
Nov 23, 2020, 1:03:48 AM11/23/20
to Android CameraX Discussion Group, tonyt...@google.com, Bob Smith
The camera exactly I want is part of a logical camera and cannot be found in getCameraIdList.

I use CameraCharacteristics to get Physical CameraId.

CameraFilter cameraFilter = Camera2CameraFilter.createCameraFilter((idCharMap) -> {
    LinkedHashMap<String, CameraCharacteristics> resultCameras=new  LinkedHashMap<String, CameraCharacteristics>();
    for(Map.Entry<String, CameraCharacteristics> entry : idCharMap.entrySet()) {
        Set<String> ID=entry.getValue().getPhysicalCameraIds();
     }
    return resultCameras;
});

In google pixel5,it returns "2" and "3".

When using Camera2 api,I can use code like below to decide which camera to use by Physical CameraId which I get from Func getPhysicalCameraIds().


OutputConfiguration outputConfiguration1 = new OutputConfiguration(mCameraImageReader1.getSurface());
outputConfiguration1.setPhysicalCameraId("2");
outputConfigurationList.add((outputConfiguration1));
OutputConfiguration outputConfiguration2 = new OutputConfiguration(mCameraImageReader2.getSurface());
outputConfiguration2.setPhysicalCameraId("3");
outputConfigurationList.add((outputConfiguration2));

SessionConfiguration sessionConfiguration = new SessionConfiguration(SessionConfiguration.SESSION_REGULAR,
outputConfigurationList, AsyncTask.THREAD_POOL_EXECUTOR, myStateCallback);
mCamera.createCaptureSession(sessionConfiguration);


Then I can get 2 different image data stream from two back cameras.

The logical cameraid returned by getCameraIdList are different from Physical CameraId.

Just to confirm.
You say "Now CameraFilter only provides the camera IDs from getCameraIdList.".
Does it mean that currently cameraFilter just cannot distinguish different back cameras?

Thanks a lot

tonyt...@google.com

unread,
Nov 23, 2020, 8:23:06 AM11/23/20
to Android CameraX Discussion Group, lss19...@gmail.com, tonyt...@google.com, Scott Nien
It depends on whether these cameras are in getCameraIdList. If not, CameraX doesn't support forcing a logical camera to output image from a specific physical camera. We'll consider this as a future feature request.

An alternative way may be relying on the logical camera switching logic. If you're trying to get image from the normal lens and the wide-angle lens on Pixel5, it could be done by applying different CameraControl#setZoomRatio

Hey Scott,
Do you happen to know what zoomRatio switches between the cameras on pixel5?

Scott Nien

unread,
Nov 24, 2020, 2:01:13 AM11/24/20
to Android CameraX Discussion Group, tonyt...@google.com, lss19...@gmail.com, Scott Nien

Yes  you can use CameraControl#setZoomRatio() to switch the wide angle lens / normal lens on pixel 5 / pixel 4a (or other android 11 devices that support it). 
You can check CameraInfo#getZoomState().getValue().getMinZoomRatio() first,  if the minZoomRatio < 1 ,  it means the camera supports zoom-out from 1.0 which means wide angle.   and then you can set the zoomRatio with the minZoomRatio value to switch to wide angle lens. 

Caveats are ,  if you want to have zoom functionality working on each lens,   you might have to manage the zoom ratio separately. Specifically,  for wide angle lens,  the zoom ratio range should become minZoomRatio ~ 0.9999 (not 1 otherwise it will switch to normal lens),  and for the normal lens,  use zoom ratio 1.0 ~ maxZoomRatio. 
 
Reply all
Reply to author
Forward
0 new messages