Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

How to choose a specific physical camera with Camerax API?

159 views
Skip to first unread message
Assigned to tonyt...@google.com by charco...@google.com

jun jiang

unread,
May 8, 2025, 10:06:39 PMMay 8
to Android CameraX Discussion Group
Hi, experts of Camerax!

I'm a developer of a camera APP with camerax. Because I need to take photos in macro mode to get more detail features of the subject, I need to choose a specific physical camera to take photo, e.g. the telephoto camera.

I'm using a Sumsung Galaxy S23 Ultra model to test. There are four physical lens in S23, which are the ultra-wide、wide、telephoto(3x)、telephoto(10x) respectively.

I used cameraManager.getCameraIdList() to get the logical cameras. The logical camera with ID "0" is composed of 4 physical cameras(IDs are 2,5,6,7).

I have tried two ways to set the specific physical camera, but still got failed. There was no effect, the defalt camera was always used.

Method 1:

I used the setPhysicalCameraId() of the CameraSelector.Builder() to set the specific physical camera(e.g. the physical camera "5"). The api was added in camerax 1.4.0. The camerax version I used is v1.4.2.

for (String id : logicCameraIds) {
                    CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics(id);
                    Set<String> physicalCameraIds = cameraCharacteristics.getPhysicalCameraIds();

                    if (physicalCameraIds.contains(targetPhysicalCameraId)) {
                        targetLogicalCameraId = id;
                        return new CameraSelector.Builder()
                                .addCameraFilter(cameraInfos -> {
                                    return cameraInfos.stream().filter(camInfo -> {
                                        String thisCamId = Camera2CameraInfo.from(camInfo).getCameraId();
                                        return thisCamId.equals(id);
                                    }).collect(Collectors.toList());
                                })
                                .setPhysicalCameraId(targetPhysicalCameraId)
                                .build();
                    }
                    else{
                        continue;
                    }
                }

Method 2:

I used the  Camera2Interop.Extender.setPhysicalCameraId to set the specific physical camera.  Firstly, I got the cameraselector with the logical camera "0", then set the specific physical camera "5" with the Camera2Interop.Extender.setPhysicalCameraId.

Preview.Builder previewBuilder = new Preview.Builder();
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
               Camera2Interop.Extender previewExtender = new Camera2Interop.Extender(previewBuilder).setPhysicalCameraId(targetPhysicalCamera);
            }
Preview preview = previewBuilder
                    //.setPreviewStabilizationEnabled(true)
                    .build();
preview.setSurfaceProvider(viewBinding.viewFinder.getSurfaceProvider());


ImageCapture.Builder imageCaptureBuilder = new ImageCapture.Builder();
           if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
               Camera2Interop.Extender imageCaptureExtender = new Camera2Interop.Extender(imageCaptureBuilder).setPhysicalCameraId(targetPhysicalCamera);
            }
imageCapture = imageCaptureBuilder.build();

Unfortunately, there was no effect with the two methods above, the default camera was used and it can't switch to the  specific physical camera.

Is there anyone could tell me have to switch to specific physical camera? This function is very common for users, so I suggest to consider adding the function to the camerax.  

tonyt...@google.com

unread,
May 14, 2025, 1:50:48 AMMay 14
to Android CameraX Discussion Group, justi...@gmail.com
Hi, thanks for the question. So to be clear, are camera ID [2, 5, 6, 7] contained in CameraCharacteristics.getPhysicalCameraIds of camera 0?

jun jiang

unread,
May 14, 2025, 7:45:43 AMMay 14
to Android CameraX Discussion Group, tonyt...@google.com, jun jiang
Thanks for your reply!

Yes, the physical camera ID [2, 5, 6, 7] are contained in CameraCharacteristics.getPhysicalCameraIds of the logical camera 0.

I have tried to implement the function mentioned above with the camera2 framework. The result is that I can switch to the specific physical camera freely with no problem. I used the OutputConfiguration.setPhysicalCameraId(id) to set the physical camera.

However, it's weird that there is no effect with CameraX API. Could help me to check the problem. Thanks!

jun jiang

unread,
May 28, 2025, 10:25:56 PMMay 28
to Android CameraX Discussion Group, jun jiang, tonyt...@google.com
I'm still struggling with this problem. Is there anybody can help me to sovle this problem? Thanks!~

Scott Nien

unread,
May 29, 2025, 12:09:24 AMMay 29
to jun jiang, Android CameraX Discussion Group, tonyt...@google.com
Do you bind any other use cases ?  

To make the physicalCameraId works,  all use case needs to have physicalCameraId being set using Camera2Interop.Extender

--
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 visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/714dbc61-39af-44b4-8d49-ef7a46ab0f4bn%40android.com.

jun jiang

unread,
Jun 2, 2025, 11:14:05 PM (11 days ago) Jun 2
to Android CameraX Discussion Group, scot...@google.com, Android CameraX Discussion Group, tonyt...@google.com, jun jiang
I use the Preview and ImageCapture two use cases, in which the physicalCameraId have been set using Camera2Interop.Extender both.

Is the physical multi-camera switching function behaving normally in your use case  using Camera2Interop.Extender?  

Scott Nien

unread,
Jun 5, 2025, 12:17:57 AM (9 days ago) Jun 5
to jun jiang, Android CameraX Discussion Group, tonyt...@google.com
Hi Jun, 

Can you show your code snippet on how you set up the use cases to enable the physical camera id ?  


Reply all
Reply to author
Forward
0 new messages