Camera 2 CameraCharacteristics seem to show incorrect data

早过忘川 提交于 2019-12-08 00:51:38

问题


I have downloaded and changed Google's Camera 2 Basic example. My changes add iterating through camera devices and showing some of their characteristics. I created this function:

private void printCameraCharacteristics() {
    Log.d(TAG, "printCameraCharacteristics");
    Activity activity = getActivity();
    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        for (String cameraId : manager.getCameraIdList()) {
            Log.d(TAG, "------------------------------ "+ cameraId +" ----------------------------------");
            CameraCharacteristics characteristics
                    = manager.getCameraCharacteristics(cameraId);

            // Examine the LENS_FACING characteristic
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
            if(facing == null){
                Log.d(TAG, "Facing: NULL");
            }
            else if(facing == CameraCharacteristics.LENS_FACING_BACK){
                Log.d(TAG, "Facing: BACK");
            } else if(facing == CameraCharacteristics.LENS_FACING_FRONT){
                Log.d(TAG, "Facing: FRONT");
            } else if(facing == CameraCharacteristics.LENS_FACING_EXTERNAL){
                Log.d(TAG, "Facing: EXTERNAL");
            } else {
                Log.d(TAG, "Facing: UNKNOWN");
            }

            // Check if the flash is supported.
            Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
            if(available == null){
                Log.d(TAG, "Flash unknown");
            }
            else if(available){
                Log.d(TAG, "Flash supported");
            } else {
                Log.d(TAG, "Flash unsupported");
            }

            // Check how much the zoom is supported
            Float zoom = characteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
            Log.d(TAG, "Max supported digital zoom: " + zoom);

            // Write all the available focal lengths
            float[] focalLengths = characteristics.get(CameraCharacteristics.LENS_INFO_AVAILABLE_FOCAL_LENGTHS);
            Log.d(TAG, "Available focal lengths: " + Arrays.toString(focalLengths));

            // Check the distortion
            if (Build.VERSION.SDK_INT >= 23) {
                float[] lensDistortionCoefficients = characteristics.get(CameraCharacteristics.LENS_RADIAL_DISTORTION);
                Log.d(TAG, "Lens distortion coefficients : " + Arrays.toString(lensDistortionCoefficients));
            }

            Log.d(TAG, "----------------------------------------------------------------");
        }
    } catch (CameraAccessException e) {
        Log.d(TAG, "CameraAccessException: " + e.getMessage());
    } catch (NullPointerException e) {
        Log.d(TAG, "NullPointerException: " + e.getMessage());
    }
}

And I just added it to the example by changing onCreateView:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    printCameraCharacteristics();
    return inflater.inflate(R.layout.fragment_camera2_basic, container, false);
}

And I got the following output for Huawei P30 Pro:

D/Camera2BasicFragment: ------------------------------ 0 ----------------------------------
D/Camera2BasicFragment: Facing: BACK
    Flash supported
    Max supported digital zoom: 10.0
D/Camera2BasicFragment: Available focal lengths: [5.56]
    Lens distortion coefficients : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]        
    ----------------------------------------------------------------
    ------------------------------ 1 ----------------------------------
    Facing: FRONT
    Flash unsupported
    Max supported digital zoom: 6.0
    Available focal lengths: [3.36]
    Lens distortion coefficients : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]        
    ----------------------------------------------------------------
D/Camera2BasicFragment: ------------------------------ 2 ----------------------------------
    Facing: BACK
    Flash unsupported
    Max supported digital zoom: 10.0
    Available focal lengths: [5.56]
    Lens distortion coefficients : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]    
    ----------------------------------------------------------------
    ------------------------------ 3 ----------------------------------
D/Camera2BasicFragment: Facing: BACK
    Flash unsupported
    Max supported digital zoom: 10.0
    Available focal lengths: [2.35]
    Lens distortion coefficients : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]       
    ----------------------------------------------------------------
    ------------------------------ 4 ----------------------------------
    Facing: BACK
    Flash unsupported
    Max supported digital zoom: 10.0
    Available focal lengths: [14.46]
D/Camera2BasicFragment: Lens distortion coefficients : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]        
    ----------------------------------------------------------------

However, some of the output seems inconsistent. P30 Pro has one camera with 5x zoom and the documentation says that the get for the LENS_INFO_AVAILABLE_FOCAL_LENGTHS parameter will return an array longer than 1 for a camera that supports optical zoom. Huawei P30 Pro also has an ultrawide camera and, from my understanding, the LENS_RADIAL_DISTORTION should return some other parameters than 0.

I have tested this example with Xiaomi Mi 9, which has 4 cameras, and I only get 2.

My question is: what is going on here? Why am I getting all this data that is inconsistent with what should be shown? Is my understanding of what should be shown, and thus my example, wrong?


回答1:


This observation is very sad and very true. Wrong reporting has haunted Android cameras since day one. The multiple manufacturers have not enough incentive to provide accurate values for multiple cameras they install on their multiple devices.

They would only make sure that their preinstalled camera app works decently, and test few heavyweight 3rd party apps like Instagram and Snapchat. Parameters that are not used by these apps may have arbitrary values.

We end up keeping a list of tweaks, based on device model and build number. Sometimes similar devices have similar bugs, sometimes they don't. Some bugs are fixed with OTA updates, other bugs are introduced with such updates. Most of these tweaks can be pushed to the devices without forcing app upgrade from PlayStore.

Sorry for not having a magic pill for this common trouble.



来源:https://stackoverflow.com/questions/57115158/camera-2-cameracharacteristics-seem-to-show-incorrect-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!