【发布时间】: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