【发布时间】:2020-02-26 14:58:03
【问题描述】:
在 Hololens 2 上使用 PhotoCapture 时有 2 个问题,它们可能已连接。它们没有出现在 Hololens 1 上。
- 唯一可获得的分辨率是 3904x2196
- 获取 CameraToWorldMatrix 总是失败
从docs 中可以看出,此分辨率没有与之关联的帧率。 我的假设是 CameraToWorldMatrix 仅适用于分辨率较低的相机配置文件。
如何在 Unity 中更改分辨率并获取矩阵?
最小可重现示例
我正在使用 Unity 2019.2.19f1 和 Visual Studio 2019 Community (16.4.5)
- 按照here 的步骤创建一个新的 Unity 项目,但使用 IL2CPP 而不是 .NET 作为脚本后端
- 在 Player Settings: Capabilities 中启用 InternetClient、InternetClientServer、PrivateNetworkClientServer、Webcam、麦克风和空间感知,在播放器设置:支持的设备系列中选择全息
-
创建一个新的空游戏对象并添加以下脚本:
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(); } } - 更改构建设置:
- 构建,打开 VS 解决方案,将构建目标设置为 ARM64,Debug 并部署到 Device
【问题讨论】:
-
你能添加你正在使用的代码吗?
-
@derHugo 基本上是从 Unity Docs 和 MS Docs 复制而来的,并稍作调整
-
您使用的是哪个版本的 unity?是否有任何步骤发生错误?目前,我们很难从您当前的帖子中找到问题的原因。建议您提供 MVCE(stackoverflow.com/help/minimal-reproducible-example) 和重现问题的步骤,以便我们定位问题或找到解决方案。
-
@Hernando-MSFT 你认识没有遇到这两个问题的人吗?我可以提供代码,但我真的怀疑问题是否在我这边,因为相同的代码在 Hololens 1 上按预期工作
-
@Hernando-MSFT 问题出现在 Unity 2019.2.19 和 2018.4.17 (LTS) 中
标签: unity3d hololens windows-mixed-reality