Hololens 2上的可定位相机(图像捕捉)

问题描述 投票:0回答:1

我在Hololens 2上使用PhotoCapture时遇到2个问题,它们可能已连接。它们不是在Hololens 1上发生的。

  • 唯一可获得的分辨率是3904x2196
  • 获取CameraToWorldMatrix总是失败

docs中可以看出,该分辨率没有与之关联的帧速率。我的假设是CameraToWorldMatrix仅可用于分辨率较低的相机配置文件。

如何更改分辨率并在Unity中获得矩阵?


最小可复制示例

我正在使用Unity 2019.2.19f1和Visual Studio 2019社区(16.4.5)

  1. 按照步骤here创建一个新的Unity Project,除了使用IL2CPP作为脚本后端而不是.NET之外
  2. 播放器设置:功能]中,在<< [玩家设置:支持的设备家族选择全息创建一个新的空游戏对象并添加以下脚本: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(); } } 更改构建设置:enter image description here构建,打开VS解决方案,将构建目标设置为ARM64Debug并部署到
  3. Device
  4. 我在Hololens 2上使用PhotoCapture时遇到2个问题,它们可能已连接。它们不是在Hololens 1上发生的。唯一可获得的分辨率是3904x2196。获取...

  5. CameraCapture插件可能适合您。这是Unity的本地插件。 readme.txt包含有关构建它的信息。基本上,您需要在尝试打开Unity示例之前构建本机插件变体。如果您尚未构建C ++ / WinRT组件,则可能需要完成设置步骤here。 SpatialCameraTracker.cs文件显示了如何接收相机矩阵。对此几乎没有支持,但是所有代码都在回购中
unity3d hololens windows-mixed-reality
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.