【问题标题】:webcamTexture rotation differs in unity3d under AndroidAndroid下unity3d中的webcamTexture旋转不同
【发布时间】:2015-03-08 13:55:17
【问题描述】:

我无法在我的 Android 设备中旋转网络摄像头纹理。

这是我在编辑器中的场景:

这是我手机中的图片:

您可以看到手机和编辑器在旋转和缩放方面的差异。

代码如下:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class Camera_pnl : MonoBehaviour {

    //// Use this for initialization
    WebCamTexture webCameraTexture;

    void Start() {
        GUITexture BackgroundTexture = gameObject.AddComponent<GUITexture>();
        BackgroundTexture.pixelInset = new Rect(0,0,Screen.width,Screen.height);
        WebCamDevice[] devices = WebCamTexture.devices;

        foreach (WebCamDevice cam in devices)
        {
            if (cam.isFrontFacing )
            {    
                webCameraTexture  = new WebCamTexture(cam.name);
                webCameraTexture.deviceName  = cam.name;
                webCameraTexture.Play();
                BackgroundTexture.texture = webCameraTexture;
            }
        }
    }

    void Update () {
        if (Input.GetKey (KeyCode.Escape)) {
            Invoke("LoadGame",0.1f);
        }
    }

    void LoadGame ()
    {
        webCameraTexture.Stop ();
        webCameraTexture = null;
        Application.LoadLevelAsync("Game");
    }
}

如何解决此问题,以便我的手机显示网络摄像头纹理的正确旋转?

【问题讨论】:

标签: android unity3d webcam


【解决方案1】:

您需要查看旋转方向,然后旋转捕获输入的预览,这可以通过实时旋转预览来完成。

int rotAngle = -webCamTexture.videoRotationAngle;
while( rotAngle < 0 ) rotAngle += 360;
while( rotAngle > 360 ) rotAngle -= 360;

以下代码来自 Camera Capture Kit 一个插件,我们使用它 (https://www.assetstore.unity3d.com/en/#!/content/56673) - 我们将它用于社交游戏/应用程序,让用户在游戏中拍摄和分享照片。

在某些情况下,当旋转 270 度或 90 度时,您还需要翻转图像。这是Android的代码。

if( Application.platform == RuntimePlatform.Android ) {
            flipY = !webCamTexture.videoVerticallyMirrored; }

在渲染网络摄像头纹理的预览以及获取像素时需要考虑这些因素,如果要保存和共享图像,图像中的像素也必须旋转,这是一个在预览中逐帧执行的昂贵过程,这就是为什么您需要在拍摄一次照片后执行此操作。

干杯

【讨论】:

    猜你喜欢
    • 2021-06-16
    • 1970-01-01
    • 2012-03-08
    • 2013-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多