【问题标题】:Android Pie AOSP default Camera orientation issue: Camera sensor roated to 90 degrees right and Display is in reverse landscape modeAndroid Pie AOSP 默认相机方向问题:相机传感器向右旋转 90 度,显示器处于反向横向模式
【发布时间】:2021-04-17 12:24:08
【问题描述】:

我正在使用 (Android Pie) AOSP Camera2 应用程序。 (包/应用程序/Camera2)

我们正在使用相机模块 OV5640。能够以反向横向模式预览和捕获图像和视频(但启用镜像)。 但对于机械外壳配件,摄像头传感器模块在物理上向右旋转了 90 度。 在用于预览的相机应用程序中,图像向左 90 度出现,并且也启用了镜像。即使在捕获图像或视频后也有相同的行为。

您能否建议我在相机应用程序(包/应用程序/Camera2)中需要做哪些更改,这些更改与以下相关: 反向横向和相机传感器模块向右旋转 90 度

我尝试如下,这次相机图像捕捉预览与相机方向相同,但预览尺寸更小。并且在捕获图像图像后还保存在正确的方向。仍然存在镜像问题。

但视频预览仍然是向左旋转 90 度,但在捕获视频后,保存的视频会正常显示。仍然存在镜像问题。

packages/apps/Camera2/src/com/android/camera/app/OrientationManager.java

            public static DeviceOrientation from(int degrees) {
        switch (degrees) {
            case 0:
                return CLOCKWISE_90;
            case 90:
                return CLOCKWISE_0;
            case 180:
                return CLOCKWISE_270;
            case 270:
                return CLOCKWISE_180;
            default:
                return CLOCKWISE_90;
           }
         }

packages/apps/Camera2/src/com/android/camera/processing/imagebackend/TaskCompressImageToJpeg.java

                    final DeviceOrientation exifDerivedRotation;
                if (exifOrientation == null) {
                    // No existing rotation value is assumed to be 0
                    // rotation.
                    exifDerivedRotation = DeviceOrientation.CLOCKWISE_90;
                } else {
                    //exifDerivedRotation = DeviceOrientation
                      //      .from(exifOrientation);
                    exifDerivedRotation = DeviceOrientation.CLOCKWISE_90;
                }

    // Resulting image will be rotated so that viewers won't
    // have to rotate. That's why the resulting image will have 0
    // rotation.
            resultImage = new TaskImage(
            DeviceOrientation.CLOCKWISE_90, resultSize.getWidth(),
                      resultSize.getHeight(),
                      ImageFormat.JPEG, null);
    // Image rotation is already encoded into the bytes.

src/com/android/camera/TextureViewHelper.java

            // This rotation code assumes that the aspect ratio of the content
    // (not of necessarily the surface) equals the aspect ratio of view that is receiving
    // the preview.  So, a 4:3 surface that contains 16:9 data will look correct as
    // long as the view is also 16:9.
    switch (deviceOrientation) {

        case CLOCKWISE_90:
            transform.setRectToRect(rotatedRect, desiredBounds, Matrix.ScaleToFit.FILL);
            transform.preRotate(270, mWidth / 2, mHeight / 2);
            break;
        case CLOCKWISE_180:
            transform.setRectToRect(normalRect, desiredBounds, Matrix.ScaleToFit.FILL);
            transform.preRotate(180, mWidth / 2, mHeight / 2);
            break;
        case CLOCKWISE_270:
            transform.setRectToRect(rotatedRect, desiredBounds, Matrix.ScaleToFit.FILL);
            transform.preRotate(90, mWidth / 2, mHeight / 2);
            break;
        case CLOCKWISE_0:
        default:
            transform.setRectToRect(normalRect, desiredBounds, Matrix.ScaleToFit.FILL);
            break;

感谢和问候, 德文德拉

【问题讨论】:

    标签: android camera orientation


    【解决方案1】:

    您是否从 HAL 的相机元数据中返回了正确的传感器方向值?此外,Android CDD 中有一个通用要求,即传感器的长边必须与屏幕的长边对齐,这是大多数应用程序所期望的。

    Android 操作系统还会翻转来自前置摄像头的图像以进行预览,但对于静态捕捉或录制的视频不应这样做。如果这是一个后置摄像头,并且您正在从传感器模块生成镜像图像,则需要在 HAL 或硬件级别取消镜像。

    通常,应用程序无法旋转/翻转绘制到 SurfaceView 中的图像,因此您无法在应用程序中解决此问题。如果你在应用程序中修复它,所有 3P 应用程序仍然会被破坏。当然,如果此设备不打算运行其他应用程序或被认证为与 Android 兼容,这可能无关紧要。

    【讨论】:

      猜你喜欢
      • 2020-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-09
      • 2021-03-01
      • 2016-05-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多