相机 API 1 和相机 API 2 return 不同的传感器方向信息

Camera API 1 and Camera API 2 return different sensor orientation info

我正在尝试找出将 camera2 与具有硬件级别支持 LEGACY 的设备一起使用的限制。来自 official docs for android camera2 api:

LEGACY: These devices expose capabilities to apps through the Camera API2 interfaces that are approximately the same capabilities as those exposed to apps through the Camera API1 interfaces. The legacy frameworks code conceptually translates Camera API2 calls into Camera API1 calls; legacy devices do not support Camera API2 features such as per-frame controls.

我发现这是错误的...事实上,我希望通过 Camera.CameraInfo camInfo -> camInfo.orientation (docs) would be the same as cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION) (docs)

获得传感器方向

然而事实并非如此!

请注意,这是完全不同的!横向!= 逆横向!例如,它会完全破坏从屏幕预览坐标到相机传感器的矩阵变换 space.

我错过了什么吗?这是有意的行为吗? 我使用的是 Android 8.1 的小米红米 5 plus(这是制造商问题吗?)

谢谢

如果这两个查询适用于同一个摄像头,这肯定是一个bug,由小米负责。即使在主流设备上也会出现错误,并且相机 API 适配层往往比其他 API 层更容易出现错误。

您可能会发现,对于 LEGACY 设备,camera2 层会引入额外的开销,反之亦然。如果您通过已弃用的 Camera API 为 LEGACY 设备工作,并通过 camera2 API 为其他设备工作,您将获得最佳性能。 我知道支持两个版本的代码很痛苦,但是当您需要以最佳方式使用设备时,您必须付出这个代价