Camera 2 CameraCharacteristics 似乎显示不正确的数据

Camera 2 CameraCharacteristics seem to show incorrect data

我已经下载并更改了 Google 的 Camera 2 Basic 示例。我的更改增加了对相机设备的迭代并显示了它们的一些特征。我创建了这个函数:

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());
    }
}

我只是通过更改 onCreateView:

将其添加到示例中
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    printCameraCharacteristics();
    return inflater.inflate(R.layout.fragment_camera2_basic, container, false);
}

我得到了华为 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]        
    ----------------------------------------------------------------

但是,有些输出似乎不一致。 P30 Pro 有一个 5 倍变焦和 the documentation says 的相机,LENS_INFO_AVAILABLE_FOCAL_LENGTHS 参数的获取将 return 一个支持光学变焦的相机的数组长于 1。华为 P30 Pro 也有一个超广角相机,据我了解, LENS_RADIAL_DISTORTION 应该 return 除了 0 之外的一些其他参数。

我用小米9测试了这个例子,有4个摄像头,我只得到2个。

我的问题是:这是怎么回事?为什么我得到的所有这些数据与应显示的内容不一致?我对应该显示的内容的理解以及我的示例是否错误?

这个观察很悲伤也很真实。从第一天起,错误的报道就一直困扰着 Android 个摄像头。多个制造商没有足够的动力为他们在多个设备上安装的多个摄像头提供准确的值。

他们只会确保他们预装的相机应用程序正常运行,并测试一些重量级的第 3 方应用程序,如 Instagram 和 Snapchat。这些应用程序未使用的参数可能具有任意值。

我们最终根据设备型号和版本号保留了一个调整列表。有时类似的设备有类似的错误,有时则没有。 OTA 更新修复了一些错误,此类更新引入了其他错误。大多数这些调整都可以推送到设备,而无需强制从 PlayStore 升级应用程序。

很抱歉没有解决这个常见问题的灵丹妙药。