ARCameraManager currentConfiguration does not report resolution

,

Hi all. As far as I can tell, there’s no way to get the camera preview resolution from ARFoundation. I wrote a script to do this:

IEnumerator Start ()
{
    yield return new WaitUntil(() => ARSession.state == ARSessionState.SessionInitializing || ARSession.state ==  ARSessionState.SessionTracking);
    Debug.Log("Config is null? " + cameraManager.currentConfiguration == null);
    Debug.Log("Config resolution: " + cameraManager.currentConfiguration?.resolution);
}

But the resolution (and the individual width and height properties) always return zero:

2020-08-14 15:46:51.914133-0400 AR-Playground[18193:3770299] UnityARKit: Updating ARSession configuration with <ARWorldTrackingConfiguration: 0x283c2e440 worldAlignment=Gravity lightEstimation=Disabled frameSemantics=None videoFormat=<ARVideoFormat: 0x282e51bd0 imageResolution=(1920, 1440) framesPerSecond=(60)> autoFocus=Enabled environmentTexturing=None wantsHDREnvironmentTextures=Enabled planeDetection=Horizontal collaboration=Disabled userFaceTracking=Disabled>
Config is null? False
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
<Start>d__7:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
(Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)

Config resolution: (0, 0)
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
<Start>d__7:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

And interestingly enough, right above the logs from my code, ARKit clearly states that the resolution is 1920x1440 @60Hz. So I wonder why ARF is unable to report this.

Bump.

In my tests, ARCameraManager.currentConfiguration is correctly reported only after the first frameReceived event.

using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.XR.ARFoundation;


public class CameraConfigurationTest : MonoBehaviour {
    [SerializeField] ARCameraManager cameraManager = null;

    bool firstFrameReceived;
 

    void OnEnable() {
        cameraManager.frameReceived += frameReceived;
    }

    void OnDisable() {
        cameraManager.frameReceived -= frameReceived;
    }

    void frameReceived(ARCameraFrameEventArgs _) {
        if (!firstFrameReceived) {
            firstFrameReceived = true;

            if (cameraManager.descriptor.supportsCameraConfigurations) {
                var cameraConfiguration = cameraManager.currentConfiguration;
                Assert.IsTrue(cameraConfiguration.HasValue);
                print($"resolution: {cameraConfiguration.Value.resolution}");
            }
        }
    }
}
1 Like

I’ve been able to reproduce this. I wish this was mentioned in the documentation. Thanks!

Lanre AR Camera resolution always 640*480 in android device. How to change resolution by dynamically according to device?

Hm I’m not too sure; IIRC, you’ll have to set the ARCameraManager configuration in your Start method. I haven’t worked with ARFoundation in quite a while.