【发布时间】:2020-11-04 21:16:31
【问题描述】:
我正在使用 Hololens 2 和 Unity 2019.4.6。
使用 PhotoCaptureFrame 类,我正在拍摄一张照片,对其进行分析以找到一个特定的标记,然后在标记所在的位置创建一个全息图。我的代码与 Unity 编辑器中的网络摄像头配合良好。但是在全息透镜上,全息图和标记之间存在偏移。
我尝试使用 cameraToWorld 矩阵(通过 photocaptureframe 类获得)来纠正它。如果我理解得很好,它代表了hololens相机和RGB相机(拍照的那个)之间的偏移量。
问题是:我不知道我是否很好地使用了这个矩阵,我的全息图位置总是很奇怪......我尝试使用这个教程:https://forum.unity.com/threads/holographic-photo-blending-with-photocapture.416023/ 结果也是错误的!实例化的四边形旋转并位于原始起点之后(当我启动应用程序时)。它不跟随相机。
我需要转换矩阵吗? 有人可以向我解释我做错了什么吗? 提前致谢!
获取矩阵的简单示例:CameraToWorld 矩阵和 Projection 矩阵的打印结果为 true,但是当您从另一个位置移动并拍照时,矩阵不会更新。
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Windows.WebCam;
public class HoloLensSnapshotTest : MonoBehaviour
{
PhotoCapture m_PhotoCaptureObj;
CameraParameters m_CameraParameters;
bool m_CapturingPhoto = false;
void Start()
{
Initialize();
}
[ContextMenu("TakePicture")]
public void TakePicture() // called by button for now
{
if (m_CapturingPhoto)
{
return;
}
m_CapturingPhoto = true;
Debug.Log("Taking picture...");
m_PhotoCaptureObj.TakePhotoAsync(OnPhotoCaptured);
}
void Initialize()
{
Debug.Log("Initializing...");
List<Resolution> resolutions = new List<Resolution>(PhotoCapture.SupportedResolutions);
Resolution selectedResolution = resolutions[0];
m_CameraParameters = new CameraParameters(WebCamMode.PhotoMode);
m_CameraParameters.cameraResolutionWidth = selectedResolution.width;
m_CameraParameters.cameraResolutionHeight = selectedResolution.height;
m_CameraParameters.hologramOpacity = 0.0f;
m_CameraParameters.pixelFormat = CapturePixelFormat.BGRA32;
PhotoCapture.CreateAsync(false, OnCreatedPhotoCaptureObject);
}
void OnCreatedPhotoCaptureObject(PhotoCapture captureObject)
{
m_PhotoCaptureObj = captureObject;
m_PhotoCaptureObj.StartPhotoModeAsync(m_CameraParameters, OnStartPhotoMode);
}
void OnStartPhotoMode(PhotoCapture.PhotoCaptureResult result)
{
m_CapturingPhoto = false;
Debug.Log("Ready");
}
void OnPhotoCaptured(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame)
{
Matrix4x4 cameraToWorldMatrix;
bool cameraToWorldMatrixResult = photoCaptureFrame.TryGetCameraToWorldMatrix(out cameraToWorldMatrix);
Matrix4x4 projectionMatrix;
bool projectionMatrixResult = photoCaptureFrame.TryGetProjectionMatrix(out projectionMatrix);
Debug.Log("CamToWorld : " + Environment.NewLine + cameraToWorldMatrixResult + Environment.NewLine + $"{cameraToWorldMatrix.ToString()}");
Debug.Log("Projection : " + Environment.NewLine + projectionMatrixResult + Environment.NewLine + $"{projectionMatrix.ToString()}");
Debug.Log("Took picture!");
m_CapturingPhoto = false;
}
}
我的矩阵是: 相机走向世界:
0.00650 -0.99959 -0.02805 0.00211
-0.99965 -0.00577 -0.02588 -0.04999
0.02571 0.02821 -0.99927 -0.01216
0.00000 0.00000 0.00000 1.00000
投影:
-0.06754 1.52561 0.00000 0.00000
-2.71531 -0.12021 0.00000 0.00000
0.05028 0.01975 -1.00401 -0.20040
0.00000 0.00000 0.00000 1.00000
【问题讨论】:
标签: c# unity3d augmented-reality hololens windows-mixed-reality