Unity3d 全息透镜2上的定位摄像机(光拍)

Unity3d 全息透镜2上的定位摄像机(光拍),unity3d,hololens,windows-mixed-reality,Unity3d,Hololens,Windows Mixed Reality,在全息透镜2上使用PhotoCapture时,我有两个问题,它们可能是连接的。它们没有出现在全息透镜1上 唯一可获得的分辨率是3904x2196 获取CameraToWorldMatrix总是失败 从中可以看出,此分辨率没有与之关联的帧率。 我的假设是,CameraToWorldMatrix仅可用于分辨率较低的相机配置文件 我如何改变分辨率并得到统一的矩阵 最小可重复示例 我正在使用Unity 2019.2.19f1和Visual Studio 2019社区(16.4.5) 按照以下步骤创

在全息透镜2上使用PhotoCapture时,我有两个问题,它们可能是连接的。它们没有出现在全息透镜1上

  • 唯一可获得的分辨率是3904x2196
  • 获取CameraToWorldMatrix总是失败
从中可以看出,此分辨率没有与之关联的帧率。 我的假设是,CameraToWorldMatrix仅可用于分辨率较低的相机配置文件

我如何改变分辨率并得到统一的矩阵


最小可重复示例 我正在使用Unity 2019.2.19f1和Visual Studio 2019社区(16.4.5)

  • 按照以下步骤创建一个新的Unity项目,除了使用IL2CPP作为脚本后端而不是.NET之外
  • 播放器设置:功能中启用Internet客户端、Internet客户端服务器、私有网络客户端服务器、网络摄像头、麦克风和空间感知,在播放器设置:支持的设备系列中选择全息
  • 创建一个新的空游戏对象并添加以下脚本:

    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using UnityEngine;
    using UnityEngine.Windows.WebCam;
    
    public class PhotoCaptureController : MonoBehaviour
    {
        PhotoCapture photoCaptureObject = null;
    
        bool isRunning = false;
    
        void Start()
        {
            StartCoroutine(StartCameraCapture());
        }
    
        private IEnumerator StartCameraCapture()
        {
            if (!Application.HasUserAuthorization(UserAuthorization.WebCam))
            {
                yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
            }
            if (Application.HasUserAuthorization(UserAuthorization.WebCam))
            {
                Debug.Log("Creating PhotoCapture");
                PhotoCapture.CreateAsync(false, OnPhotoCaptureCreated);
            }
            else
            {
                Debug.Log("Webcam Permission not granted");
            }
        }
    
        private void Update()
        {
            if (isRunning)
            {
                photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
            }
        }
    
        void OnPhotoCaptureCreated(PhotoCapture captureObject)
        {
            photoCaptureObject = captureObject;
    
            IEnumerable<Resolution> availableResolutions = PhotoCapture.SupportedResolutions;
    
            foreach (var res in availableResolutions)
            {
                Debug.Log("PhotoCapture Resolution: " + res.width + "x" + res.height);
            }
    
            Resolution cameraResolution = availableResolutions.OrderByDescending((res) => res.width * res.height).First();
    
            CameraParameters c = new CameraParameters();
            c.hologramOpacity = 0.0f;
            c.cameraResolutionWidth = cameraResolution.width;
            c.cameraResolutionHeight = cameraResolution.height;
            c.pixelFormat = CapturePixelFormat.BGRA32;
    
            captureObject.StartPhotoModeAsync(c, OnPhotoModeStarted);
        }
    
        private void OnPhotoModeStarted(PhotoCapture.PhotoCaptureResult result)
        {
            if (result.success)
            {
                isRunning = true;
                photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
            }
        }
    
        void OnCapturedPhotoToMemory(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame frame)
        {
            if (result.success)
            {
                if (frame.TryGetCameraToWorldMatrix(out Matrix4x4 cameraToWorldMatrix))
                {
                    Debug.Log("Successfully obtained CameraToWorldMatrix: " + cameraToWorldMatrix.ToString());
    
                }
                else
                {
                    Debug.Log("Failed to obtain CameraToWorldMatrix");
                }
            }
            frame.Dispose();
        }
    }
    
    使用系统集合;
    使用System.Collections.Generic;
    使用System.Linq;
    使用UnityEngine;
    使用UnityEngine.Windows.WebCam;
    公共类光电捕获控制器:单行为
    {
    PhotoCapture photoCaptureObject=null;
    bool isRunning=false;
    void Start()
    {
    startcroutine(StartCameraCapture());
    }
    私人IEnumerator StartCameraCapture()
    {
    if(!Application.HasUserAuthorization(UserAuthorization.WebCam))
    {
    生成返回应用程序.RequestUserAuthorization(UserAuthorization.WebCam);
    }
    if(Application.HasUserAuthorization(UserAuthorization.WebCam))
    {
    Log(“创建PhotoCapture”);
    CreateAsync(false,OnPhotoCaptureCreated);
    }
    其他的
    {
    Debug.Log(“未授予网络摄像头权限”);
    }
    }
    私有void更新()
    {
    如果(正在运行)
    {
    TakePhotoAsync(OnCapturedPhotoToMemory);
    }
    }
    void OnPhotoCaptureCreated(PhotoCaptureCaptureObject)
    {
    photoCaptureObject=captureObject;
    IEnumerable availableResolutions=PhotoCapture.SupportedResolutions;
    foreach(可用解决方案中的var res)
    {
    调试日志(“光电捕获分辨率:+res.width+“x”+res.height);
    }
    分辨率cameraResolution=availableResolutions.OrderByDescending((res)=>res.width*res.height).First();
    CameraParameters c=新的CameraParameters();
    c、 全息容量=0.0f;
    c、 cameraResolutionWidth=cameraResolution.width;
    c、 cameraResolutionHeight=cameraResolution.height;
    c、 pixelFormat=CapturePixelFormat.BGRA32;
    captureObject.StartPhotoModeAsync(c,OnPhotoModeStarted);
    }
    已启动PhotoCodes上的私有无效(PhotoCapture.PhotoCaptureResult)
    {
    如果(结果、成功)
    {
    isRunning=true;
    TakePhotoAsync(OnCapturedPhotoToMemory);
    }
    }
    void onCapturedPhototomory(PhotoCapture.PhotoCaptureResult结果,PhotoCaptureFrame)
    {
    如果(结果、成功)
    {
    if(帧TryGetCameraToWorldMatrix(输出矩阵x4x4 cameraToWorldMatrix))
    {
    Log(“成功获取CameraToWorldMatrix:+CameraToWorldMatrix.ToString());
    }
    其他的
    {
    Log(“未能获取CameraToWorldMatrix”);
    }
    }
    frame.Dispose();
    }
    }
    
  • 更改生成设置:
  • 构建,打开VS解决方案,将构建目标设置为ARM64,调试并部署到设备
  • 这个插件可能适合你。它是Unity的本地插件。readme.txt包含关于构建它的信息。基本上,在尝试打开Unity示例之前,您需要构建本机插件变体。如果尚未构建C++/WinRT组件,则可能需要完成安装步骤。SpatialCameraTracker.cs文件显示了如何接收相机矩阵


    这方面的支持很少,但是所有的代码都在repo中

    您可以添加您正在使用的代码吗?@derHugo-its基本上是从比特复制并改编的,您使用的是什么版本的unity?是否在任何步骤中发生错误?目前,我们很难从您当前的帖子中找到问题的原因。我们建议您提供MVCE()和重现问题的步骤,以便我们能够找到问题或找到解决方案。@Hernando MSFT您知道有谁没有遇到过这两个问题吗?我可以提供代码,但我真的怀疑问题是否在我这边,因为相同的代码在Hololens上按预期工作1@Hernando-MSFT的问题发生在Unity 2019.2.19和2018.4.17(LTS)上。谢谢,看起来很有用-很遗憾,我现在没有时间检查这个问题