投影矩阵与全息透镜1上的PhotoCapture不可用



我开发了一个小应用程序来测试Hololens的PhotoCapture API,以捕获带有位置矩阵的屏幕截图。截图是正确的,并在游戏对象上添加纹理,但是TryGetProjectionMatrix和TryGetCameraToWorldMatrix方法总是返回false。尽管在网上研究了几个小时,我还是找不到位置数据无法访问的原因。我在unity(电脑)和Hololens上直接尝试了游戏模式,但结果是一样的。

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

Unity版本:2019.4.27f1全息版:1Hololens SDK: 10.0.17763.0激活的功能:InternetClient, WebCam,麦克风,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执行工具栏。它在我的全息眼镜上起作用了。我的问题解决了。感谢Hernando的回答。

相关内容

  • 没有找到相关文章

最新更新