おそらく接続されている Hololens 2 で PhotoCapture を使用すると、2 つの問題が発生します。Hololens 1 では発生しませんでした。
- 取得できる解像度は 3904x2196 のみです
- CameraToWorldMatrix の取得は常に失敗します
docsに見られるように、この解像度にはフレームレートが関連付けられていません。私の推測では、CameraToWorldMatrix は解像度が低いカメラ プロファイルでのみ取得可能です。
Unity 内で解像度を変更してマトリックスを取得するにはどうすればよいですか?
最小限の再現例
Unity 2019.2.19f1 と Visual Studio 2019 Community (16.4.5) を使用しています。
- .NET の代わりに IL2CPP をスクリプティング バックエンドとして使用することを除いて、こちらの手順に従って新しい Unity プロジェクトを作成します。
- プレーヤーの設定: 機能によりInternetClient、InternetClientServer、PrivateNetworkClientServer、Webcam、Microphone、およびSpatialPerceptionが有効になり、プレーヤーの設定: サポートされているデバイス ファミリでHolographicが選択されます。
新しい空のゲーム オブジェクトを作成し、次のスクリプトを追加します。
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に設定し、デバッグしてデバイスにデプロイします。