Hololens 1 上带 PhotoCapture 的投影矩阵不可用

Projection Matrix with PhotoCapture on Hololens 1 not available

我开发了一个小应用程序来测试 Hololens 的 PhotoCapture API 以捕获带有位置矩阵的屏幕截图。屏幕截图已正确截取并添加为游戏对象的纹理,但方法 TryGetProjectionMatrix 和 TryGetCameraToWorldMatrix return 始终为 false。尽管在 Web 上进行了数小时的研究,但我没有找到无法访问位置数据的原因。 unity(电脑)的播放模式和直接在Hololens上都试过了,结果是一样的

我需要它们,因为我必须提取虚拟元素背后真实环境的像素。

Unity版本:2019.4.27f1 全息镜版本:1 全息镜头 SDK:10.0.17763.0 已激活的功能:InternetClient、网络摄像头、麦克风、SpatialPerception、GazeInput

您可以在 MixedRealityPlayscape 下找到与主摄像头关联的脚本。

我希望有人能帮助我。 最好的祝福, 马克西姆

using UnityEngine;
using System.Collections;
using System.Linq;
using UnityEngine.Windows.WebCam;

public class AutomaticColorAdaptation : MonoBehaviour
{
    PhotoCapture photoCaptureObject = null;
    Texture2D targetTexture = null;

    // Start is called before the first frame update
    void Start()
    {
        Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
        targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);

        // Create a PhotoCapture object
        PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject) {
            photoCaptureObject = captureObject;
            CameraParameters cameraParameters = new CameraParameters(WebCamMode.PhotoMode);
            cameraParameters.hologramOpacity = 0.0f;
            cameraParameters.cameraResolutionWidth = cameraResolution.width;
            cameraParameters.cameraResolutionHeight = cameraResolution.height;
            cameraParameters.pixelFormat = CapturePixelFormat.BGRA32;
         
            // Activate the camera
            photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate(PhotoCapture.PhotoCaptureResult result) {
                // Take a picture
                photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
            });
        });
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    void OnCapturedPhotoToMemory(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame)
    {
        Debug.Log(result.success); // Display True
        Debug.Log(photoCaptureFrame.hasLocationData); // Display False

        Matrix4x4 m1 = new Matrix4x4();
        Matrix4x4 m2 = new Matrix4x4();

        Debug.Log(photoCaptureFrame.TryGetCameraToWorldMatrix(out m1)); // Display False
        Debug.Log(photoCaptureFrame.TryGetProjectionMatrix(out m2)); // Display False

        Debug.Log(m1); // Display Identity matrix
        Debug.Log(m2); // Display Identity matrix

        // Copy the raw image data into our target texture
        photoCaptureFrame.UploadImageDataToTexture(targetTexture);

        // Create a gameobject that we can apply our texture to
        GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
        Renderer quadRenderer = quad.GetComponent<Renderer>() as Renderer;
        quadRenderer.material = new Material(Shader.Find("Unlit/Texture"));

        quad.transform.parent = this.transform;
        quad.transform.localPosition = new Vector3(0.0f, 0.0f, 3.0f);

        quadRenderer.material.SetTexture("_MainTex", targetTexture);

        // Deactivate our camera
        photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode);
    }

    void OnStoppedPhotoMode(PhotoCapture.PhotoCaptureResult result)
    {
        // Shutdown our photo capture resource
        photoCaptureObject.Dispose();
        photoCaptureObject = null;
    }
}

我使用 Unity 2019.4.27f1 和 MRTK 2.7.2 创建了一个新项目。这一次,我没有克隆 MRTK 配置文件来禁用 CPU 执行者栏。它适用于我的 Hololens 1。我的问题已解决。感谢 Hernando 的回答。