Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

Android Pie AOSP default Camera orientation issue: Camera sensor roated to 90 degrees right and Display is in reverse landscape mode

I am using an (Android Pie) AOSP Camera2 application. (packages/apps/Camera2)

We are using Camera module OV5640. Able to preview and capture the image and video in reverse landscape mode (But mirror enabled). But for the mechanical enclosure fitting, camera sensor module rotated to 90 degrees right physically. And in camera application for preview, image is coming as 90 degree left and mirror also enabled. Even after capture the image or video also same behaviour.

Please can you suggest me what changes I need to do in camera application (packages/apps/Camera2) related to: Reverse landscpe and camera sensor module rotated to 90 Degrees right

I tried as below, this time camera image capture preview came same as in camera direction, but preview size is less. And after capturing the image image also saved in proper direction. Still mirror issue is there.

But video preview is still came as 90 degress rotated left but after capturing the video, saved video is coming properly. Still mirror issue is there.

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;

Thank and Regards, Devendra


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Are you returning the correct sensor orientation values from the HAL's camera metadata? Also, there is a general requirement in the Android CDD that the long side of the sensor must line up with the long side of the screen, which most applications expect to be true.

The Android OS also flips images from front-facing camera for preview, but should not do so for still captures or recorded video. If this is a back-facing camera, and you are producing mirrored images from the sensor module, you need to unmirror at the HAL or hardware level.

In general, applications cannot rotate/flip images drawn into a SurfaceView, so there's not much you can do to fix this in the app. And if you fix it in app, all 3P apps will still be broken. This may not matter if this device is not intended to run other apps, or be certified as Android-compatible, of course.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...