Closed andnovar closed 4 years ago
I added this script to the AR Camera
GameObject in the SimpleAR sample and ran it on a Pixel 3a XL:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
[RequireComponent(typeof(ARCameraManager))]
public class PrintCameraIntrinsics : MonoBehaviour
{
XRCameraIntrinsics? m_CameraIntrinsics;
void Start()
{
GetComponent<ARCameraManager>().frameReceived += OnFrameReceived;
}
void OnFrameReceived(ARCameraFrameEventArgs eventArgs)
{
if (GetComponent<ARCameraManager>().TryGetIntrinsics(out var intrinsics))
{
m_CameraIntrinsics = intrinsics;
}
else
{
m_CameraIntrinsics = null;
}
}
// Update is called once per frame
void OnGUI()
{
if (m_CameraIntrinsics.HasValue)
{
GUI.skin.label.fontSize = 100;
GUILayout.Label($"Camera intrinsics: {m_CameraIntrinsics.Value.ToString()}");
}
}
}
Camera intrinsics were displayed as expected.
The problem was on my end. Thanks for sharing code about it. I was not doing TryGetIntrinsics inside OnFrameReceived. I am just using XRCpuImage and reading the raw pixels.
You can call TryGetIntrinsics
from anywhere (doesn't have to be in the frameReceived
callback), but you need to have gotten a new ARFrame that frame. It takes a few frames to establish the session, which is why calling it once from Start
would quite likely return false
.
Unity bug report case number Unity bug case number 1257094.
Describe the bug TryGetIntrinsics(out XRCameraIntrinsics) is always returning false. I am using ARFoundation 4.0
To Reproduce Steps to reproduce the behavior:
Expected behavior I expect to get the focal length for further CV processing.
Actual behavior GetIntrinsics is not returning any values.
Smartphone (please complete the following information):