我已经下载并更改了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
参数的get将返回一个大于1的数组。华为P30 Pro还具有超宽相机,据我了解,LENS_RADIAL_DISTORTION
应该返回除0
之外的其他一些参数。
我已经用具有4个摄像头的小米Mi 9测试了这个示例,而我只有2个。
我的问题是:这是怎么回事?为什么我得到所有与应显示的数据不一致的数据?我对应该显示的内容的理解是否正确,因此我的示例是否正确?
答案 0 :(得分:1)
这种观察是非常悲伤和真实的。从第一天开始,错误的报告就困扰着Android相机。多家制造商没有足够的动力为安装在其多种设备上的多个摄像机提供准确的价格。
他们只会确保预先安装的相机应用程序运行正常,并测试一些重量级的第三方应用程序,例如Instagram和Snapchat。这些应用未使用的参数可以具有任意值。
我们最终保留了基于设备型号和内部版本号的调整列表。有时类似的设备有类似的错误,有时却没有。 OTA更新修复了一些错误,此类更新引入了其他错误。这些调整中的大多数都可以推送到设备,而无需强制从PlayStore升级应用。
很抱歉,您没有为此常见的麻烦服用魔术药。