DreamCamera2相机预览变形的处理

发布于:2024-11-29 ⋅ 阅读:(14) ⋅ 点赞:(0)

最近遇到一个问题,相机更换了摄像头后,发现人像角度顺时针旋转了90度,待人像角度正常后,发现 预览时图像有挤压变形,最终解决。在此记录

一人像角度的修改

先放示意图

设备预览人像角度如图1所示,顺时针旋转了90,正常效果如图2 修改如下:

//文件路径: /device/sprd/qogirn6l/ums9158_1h10/ums9158_1h10/module/camera/sensor_config.xml 
Date:   Wed Nov 27 18:02:01 2024 +0800

    修复顺时针旋转90度摄像头预览
    
    Change-Id: Ife0a46fe32ffd2c213d0ba0ab1eba07be50c8055

diff --git a/ums9158_1h10/module/camera/sensor_config.xml b/ums9158_1h10/module/camera/sensor_config.xm​‌​
l
index 20031a4..60aa732 100755
--- a/ums9158_1h10/module/camera/sensor_config.xml
+++ b/ums9158_1h10/module/camera/sensor_config.xml
@@ -6,7 +6,7 @@
         <SlotId>0</SlotId>
         <SensorName>ov8858_ft18</SensorName>
         <Facing>BACK</Facing>
-        <Orientation>270</Orientation>
+        <Orientation>180</Orientation>^M
         <Resource_cost>100</Resource_cost>
         <TuningParameter>
             <TuningName>ov8858_main_ft18</TuningName>

 如上修改,,可以相机后摄像头预览时人像角度(前摄也应该在改文件中,找front选项和对应项目名称)

二相机预览时图像挤压变形

步骤一完成后,图像角度正常了,但是内容挤压变形了。效果如下所示

图1       图2

如上图,左侧图1时被挤压时效果,右图2是修改后正常效果。

刚开始以为问题再驱动层,和同事沟通后发现,应该在应用层,相机设置里个比例设置,默认全屏模式,只是比例有问题。然后看源码,角度不对的时候无挤压,旋转后有挤压,说明比例反了(设备屏幕宽高比)做此判断,如下修改

思路:默认只是角度不对,但是没有挤压,说明原有的比例和屏幕比例一致所以正常;

旋转了角度,图像比例和屏幕比例不一致,导致挤压,根据源码,将其比例反过来就可以了。

(可以在设置中选择1:1比例图像正常,说明 比例问题)

vendor/sprd/platform/packages/apps/DreamCamera2/src/com/android/camera/settings$ git diff
diff --git a/src/com/android/camera/settings/ResolutionUtil.java b/src/com/android/camera/settings/ResolutionUtil.java
index 432e28d0..cbe823ff 100644
--- a/src/com/android/camera/settings/ResolutionUtil.java
+++ b/src/com/android/camera/settings/ResolutionUtil.java
@@ -39,6 +39,8 @@ import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
+import com.android.camera.debug.Log;
+
 
 import javax.annotation.Nonnull;
 import javax.annotation.ParametersAreNonnullByDefault;
@@ -52,6 +54,9 @@ import javax.annotation.ParametersAreNonnullByDefault;
  * user with so many options.
  */
 public class ResolutionUtil {
+
+        private static final Log.Tag TAG = new Log.Tag("ResolutionUtil");
+
     /**
      * Different aspect ratio constants.
      */
@@ -75,14 +80,20 @@ public class ResolutionUtil {
             Point point = new Point();
             Display d = activity.getWindowManager().getDefaultDisplay();
             d.getRealSize(point);
-            mFullScreenSize = point.x > point.y ? new Size(point.x, point.y) : new Size(point.y, point.x);
+            mFullScreenSize = point.x < point.y ? new Size(point.x, point.y) : new Size(point.y, point.x);
+            Log.e(TAG, "setDesiredAspectRatio, point.x:" + point.x+",point.y:" + point.y);
+            Log.e(TAG, "setDesiredAspectRatio, mFullScreenSize:" + mFullScreenSize);
 
             sDesiredAspectRatioSizes.add(new Size(4,3));
             sDesiredAspectRatioSizes.add(mFullScreenSize);
             sDesiredAspectRatioSizes.add(new Size(1,1));
 
             sDesiredAspectRatios.add(4.0f / 3.0f);
-            sDesiredAspectRatios.add(mFullScreenSize.width() / (float) mFullScreenSize.height());
+            Log.e(TAG, "setDesiredAspectRatio, mFullScreenSize.width():" + mFullScreenSize.width() +",mFullScreenSize.height():" + mFullScreenSize.height());
+            Log.e(TAG, "setDesiredAspectRatio, mFullScreenSize.width() / (float) mFullScreenSize.height()=" + mFullScreenSize.width() / (float) mFullScreenSize.height());
+            
+            // sDesiredAspectRatios.add(mFullScreenSize.width() / (float) mFullScreenSize.height());
+            sDesiredAspectRatios.add( (float) mFullScreenSize.height()/mFullScreenSize.width() );
             sDesiredAspectRatios.add(1.0f / 1.0f);
             settled = true;
         }

测试通过over!

ps:怎么判断当前的应用在项目中那个路径,可以看我的历史文章

[转]Android寻找某个包在aosp下的路径