10

How to capture images or videos from the camera2 api wide angle camera? or the telescopic camera? I know how to handle camera capture for front & back camera. I just can't understand how to open the camera and choose the wide/telescopic camera?

I guess it has something to do with setting one of the following :

CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA
CameraCharacteristics.getPhysicalCameraIds()
CameraCharacteristics.getAvailablePhysicalCameraRequestKeys()
CameraDevice.createCaptureSession(SessionConfiguration config)
CameraCharactersitics.LOGICAL_MULTI_CAMERA_SENSOR_SYNC_TYPE

But I fail to understand the scenario of setting it up and I didn;t find any good explanation. I will appreciate any kind of tutorial or explanation. Last question - how to test it with no phsical device? I mean - how to setup the Avd/emulator?

kfir
  • 635
  • 8
  • 27
  • Hi man! Have you found any solution to your problem? How did you solve your task with the choice of cameras? – Vlad Feb 05 '20 at 08:35
  • I am still researching. On Android 10, the other cameras are also physical cameras, It means that you can open camera like any other camera. the camera Ids are the big question. for some the wide cameraID is 3, for some the wide camera is cameraID = 2. – kfir Feb 06 '20 at 09:38
  • 1
    Same needs here. I can not find a way to use the wide angle camera. Google says that it is not the way it works with camerax: the approach is use case based... But the we need a use case 'wide angle'. – Steeve Favre Apr 14 '20 at 18:36

2 Answers2

4

So I asked this on the CameraX discussion group and here is the reply from google:

For CameraX to support wide angle cameras we are working with manufacturers to expose those via camera2 first. Some devices indeed do so today in an non-determinstic manner. Will keep you posted as we progress, thanks!

Steeve Favre
  • 248
  • 3
  • 9
-1

So, If somebody still looks for the answer: Almost no manufacturer supported that until android 10. from android 10 - all physical camera are logical cameras. It means that you can see those cameras on

manager.getCameraIdList()

you will get a list of all available camera, just look for the CameraCharacteristics.LENS_FACING direction. and populate a list.

Here is the full code:

public CameraItem[] GetCameraListFirstTime() {
    List<CameraItem> listValuesItems = new ArrayList<CameraItem>();
    boolean IsMain = false;
    boolean IsSelfie = false;
    if(manager == null)
        manager = (CameraManager)mContext.getSystemService(CAMERA_SERVICE);
    try {

        for (String cameraId : manager.getCameraIdList()) {
            CameraCharacteristics chars = manager.getCameraCharacteristics(cameraId);
            if (!IsMain && chars.get(CameraCharacteristics.LENS_FACING) == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                listValuesItems.add(new CameraItem(Integer.parseInt(cameraId), "Main"));
                IsMain = true;
            }
            else if (!IsSelfie && chars.get(CameraCharacteristics.LENS_FACING) == Camera.CameraInfo.CAMERA_FACING_BACK) {

                    listValuesItems.add(new CameraItem(Integer.parseInt(cameraId), "Selfie"));
                    IsSelfie = true;
            }
            else
                listValuesItems.add(new CameraItem(Integer.parseInt(cameraId), "Wide or Other"));
        }

    }
    catch (CameraAccessException e) {
        Log.e(TAG, e.toString());

    }
    return listValuesItems.toArray(new CameraItem[0]);
}

public class CameraItem implements java.io.Serializable{
public int Key;
public String Description;
public CameraItem(int key, String desc)
{
    Key=key;
    Description = desc;
}
kfir
  • 635
  • 8
  • 27
  • I think this logic is incorrect. If the camera is not main and not selfie, then we are just assuming it is a wide angle camera. This practically is not a necessary && not enough condition for the remaining one to be a wide angle camera. Additionally it is not coming from the system. Also we are not taking into consideration the focul length, image size it gives, the angles etc params to determine if the camera is wide angle one. I am open to thoughts/discussion here. – JaydeepW Sep 30 '20 at 08:07
  • 1
    This question was about how to open the other cameras : "wide angle camera? or the telescopic". I have tested it on many real devices. the code works and run on my apps. your comment is correct, but I did write "Wide or Other". to understand if the camera is wide or not - it is more then the scope of this question. And to get this data - you need to open each camera, question its parameters, and close afterward. for each of the cameras. I would not recommend it. you will get many errors per users(camera exceptions) – kfir Sep 30 '20 at 10:17
  • `getCameraIdList` only returns rear or front cameras id, also mb external usb camera id (if you have one connected to your smartphone device), it has nothing to do with wide ange camera from multicamera – user25 Nov 18 '20 at 14:35
  • so read https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Builder#setPhysicalCameraKey(android.hardware.camera2.CaptureRequest.Key%3CT%3E,%20T,%20java.lang.String) – user25 Nov 18 '20 at 14:35
  • very bad answer... I guess you are a new to Android, don't do not rush to answer if don't know for sure how it works – user25 Nov 18 '20 at 14:36
  • It works. I using this code on my app, I made a screen recording for you on S10 & S20 that shows how to switch between 4 of those cameras. you can see in the recording that the angles of the different cameras is different. here is the recording https://youtu.be/-DtveB1jvsE You can also see in the recording that in case of Pixel4a which have only 2 physicals cameras, it shows only 2. – kfir Nov 19 '20 at 09:30
  • Here is the explanation https://developer.android.com/training/camera/multi-camera I get good reviews from people who are happy to choose different cameras. You can check it by yourself on my app which has almost half a million downloads https://play.google.com/store/apps/details?id=com.arbelsolutions.BVRUltimate – kfir Nov 19 '20 at 09:32
  • And why the attitude? you can just stay professional, if I am wrong - I will be happy to be corrected - no need to get personal – kfir Nov 19 '20 at 09:33
  • Another test on Samsing S20 Ultra - works like charm https://youtu.be/LSHdfnAnRsc – kfir Nov 21 '20 at 07:51
  • @kfir you provided a well-known link about multi-camera, but why in your answer `getPhysicalCameraIds()` is missing? – user25 Nov 21 '20 at 18:45
  • Xiaomi MI 9, Pixel 4 has multi-camera but `manager.getCameraIdList()` will return only front and back cameras `[0, 1]`, so answer mb will work for Samsung devices but not for other Manufacture devices – user25 Nov 21 '20 at 18:46
  • Try Pixel 4 emulator, it will only return `[12, 13, 14]` for Front camera when using `cameraCharacteristics.physicalCameraIds` – user25 Nov 21 '20 at 19:09
  • Pixel 4 have 3 cameras on the getCameraIdList. https://youtu.be/iYDmVefkZAU – kfir Nov 21 '20 at 20:55
  • Pixel 4 have 3 cameras(GSMArena) also on the getCameraIdList. As can be seen by the test I just made using my BVR Ultimate app, https://youtu.be/iYDmVefkZAU .In the previous video I was testing Pixel 4a which have 2 cameras, You can see also in the recording the label upstairs (GSMArena). So it is still correct. I do not have Xiaomi on my lab service. I have proven it for samsung & google devices. You say that "getPhysicalCameraIds" gives more info? I will check it out, I can assure you that I have tried to follow diffrent paths like getPhysicalCameraIds - and none of them was successful – kfir Nov 21 '20 at 21:01
  • It seems like Google for changing camera still wants us to use just one logical camera https://developer.android.com/training/camera/multi-camera and camera will be chosen based on selected zoom or focal length. I checked Xiaomi MI 9 default camera app and it has default zoom 1.0 (max 10.0) but it also has one lower value - 0.6, and when I select this one it changes field of view, so it automatically switches to wide camera. There is `CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE` and mb I will get this lowest zoom value, but yes, mb, Xiaomi just doesn't allow it. – user25 Nov 22 '20 at 11:05
  • I just don't like the idea of using different camera ids and opening the camera with specific one. It seems Pixel4 emulators doesn't really have similar camera info as a real device. I just don't have a real device Pixel – user25 Nov 22 '20 at 11:07
  • You have mentioned CONTROL_ZOOM_RATIO_RANGE. you are welcome to test it on my app - pinch with 2 fingers on the preview menu. you can reach zoom lower then 1.0 and let's declare this answer as correct – kfir Jan 14 '21 at 17:50