[Camera]摄像头镜像

2020-05-06  本文已影响0人  Letcos
platform:RK3399
OS:Android 7.1
参考:
1.石先 https://www.jianshu.com/p/7d88ec1347b6
2.KrisFei https://blog.csdn.net/kris_fei/article/details/103024505
3.KrisFei https://blog.csdn.net/kris_fei/article/details/79298971
4.KrisFei https://blog.csdn.net/kris_fei/article/details/79550161

1. Camra简介

1.1 Camera常见类型

在RK HAL中,规定了不同类型的adapter,对应不用类型的camera

总的来说,Camera常见的类型就是MIPI接口,DVP接口和USB接口三种类型.

1.2 Camera方向

前置和后置

Android系统是区分前置和后置摄像头的.以手机来说:屏幕上方的摄像头一般为前置摄像头;手机背面的摄像头一般为后置摄像头.

在Android系统中,前置摄像头一般使用"Front"表示;后置摄像头一般使用"Back"表示.

一般来说,前置摄像头使用的是镜像;后置摄像头使用的是正常视角.所以在不是那么区分前后摄像头的设备上,比如机器人,就有可能因为前后置摄像头问题导致预览和拍照出现镜像问题.这也是解决镜像问题的主要思路.

预览和拍照

Camera的数据是来自于摄像头硬件的图像传感器,摄像头一旦被固定之后是有一个默认的取景方向的.如下图所示.

在这里插入图片描述

2. Camera镜像

2.1 MIPI Camera方向

--- a/Config/cam_board_rk3399.xml
+++ b/Config/cam_board_rk3399.xml
@@ -22,7 +22,7 @@
                                        <SensorFacing facing="front"></SensorFacing>
                                        <SensorInterface interface="MIPI"></SensorInterface>
                                        <SensorMirrorFlip mirror="0"></SensorMirrorFlip>
-                                       <SensorOrientation orientation="180"></SensorOrientation>
+                                       <SensorOrientation orientation="0"></SensorOrientation>

2.2 USB Camera镜像

方法一:

--- a/services/camera/libcameraservice/api1/CameraClient.cpp
+++ b/services/camera/libcameraservice/api1/CameraClient.cpp
@@ -55,6 +55,7 @@ CameraClient::CameraClient(const sp<CameraService>& cameraService,
     // Callback is disabled by default
     mPreviewCallbackFlag = CAMERA_FRAME_CALLBACK_FLAG_NOOP;
     mOrientation = getOrientation(0, mCameraFacing == CAMERA_FACING_FRONT);
+    mOrientation = 1;
     mLegacyMode = legacyMode;
     mPlayShutterSound = true;
     LOG1("CameraClient::CameraClient X (pid %d, id %d)", callingPid, cameraId);
@@ -721,6 +722,7 @@ status_t CameraClient::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) {
     if (cmd == CAMERA_CMD_SET_DISPLAY_ORIENTATION) {
         // Mirror the preview if the camera is front-facing.
         orientation = getOrientation(arg1, mCameraFacing == CAMERA_FACING_FRONT);
+       orientation = 1;
         if (orientation == -1) return BAD_VALUE;
 
         if (mOrientation != orientation) {

方法二:

--- a/kernel/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/kernel/drivers/media/usb/uvc/uvc_v4l2.c
@@ -548,13 +548,27 @@ static int uvc_v4l2_release(struct file *file)
 static int uvc_ioctl_querycap(struct file *file, void *fh,
                              struct v4l2_capability *cap)
 {
-       struct video_device *vdev = video_devdata(file);
+       //struct video_device *vdev = video_devdata(file);
        struct uvc_fh *handle = file->private_data;
        struct uvc_video_chain *chain = handle->chain;
        struct uvc_streaming *stream = handle->stream;
        //如果sensor型号不一样,也可以通过product vendor id来区分。
+       printk("kris idVendor:0x%x idProduct:0x%x\n ", stream->dev->udev->descriptor.idVendor, 
+               stream->dev->udev->descriptor.idProduct);
+
        strlcpy(cap->driver, "uvcvideo", sizeof(cap->driver));
+#if 0
        strlcpy(cap->card, vdev->name, sizeof(cap->card));
+#else
+       if(stream->dev->udev->bus->busnum == 3) {
+               strcpy(cap->card, "front");
+       } else {
+               strcpy(cap->card, "back");
+       }
+
+#endif
        usb_make_path(stream->dev->udev, cap->bus_info, sizeof(cap->bus_info));
        cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING

方法三:

直接让USB厂商修改ISP固件,直出数据就直接镜像.

其他方式可参考USB Camera旋转图像方法

2.3 DVP Camera镜像

参考:DVP Camera旋转预览和回调数据

主要思路是:通过修改模组寄存器的flip参数,来修改方向.

上一篇下一篇

猜你喜欢

热点阅读