Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug ARCameraManager currentConfiguration does not report resolution

Discussion in 'AR' started by Lanre, Aug 14, 2020.

  1. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,960
    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:
    Code (CSharp):
    1. IEnumerator Start ()
    2. {
    3.     yield return new WaitUntil(() => ARSession.state == ARSessionState.SessionInitializing || ARSession.state ==  ARSessionState.SessionTracking);
    4.     Debug.Log("Config is null? " + cameraManager.currentConfiguration == null);
    5.     Debug.Log("Config resolution: " + cameraManager.currentConfiguration?.resolution);
    6. }
    But the resolution (and the individual `width` and `height` properties) always return zero:
    Code (CSharp):
    1. 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>
    2. Config is null? False
    3. UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
    4. UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    5. UnityEngine.Logger:Log(LogType, Object)
    6. UnityEngine.Debug:Log(Object)
    7. <Start>d__7:MoveNext()
    8. UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
    9. (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
    10.  
    11. Config resolution: (0, 0)
    12. UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
    13. UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    14. UnityEngine.Logger:Log(LogType, Object)
    15. UnityEngine.Debug:Log(Object)
    16. <Start>d__7:MoveNext()
    17. 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.
     
  2. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,960
    Bump.
     
  3. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,070
    In my tests, ARCameraManager.currentConfiguration is correctly reported only after the first frameReceived event.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Assertions;
    3. using UnityEngine.XR.ARFoundation;
    4.  
    5.  
    6. public class CameraConfigurationTest : MonoBehaviour {
    7.     [SerializeField] ARCameraManager cameraManager = null;
    8.  
    9.     bool firstFrameReceived;
    10.  
    11.  
    12.     void OnEnable() {
    13.         cameraManager.frameReceived += frameReceived;
    14.     }
    15.  
    16.     void OnDisable() {
    17.         cameraManager.frameReceived -= frameReceived;
    18.     }
    19.  
    20.     void frameReceived(ARCameraFrameEventArgs _) {
    21.         if (!firstFrameReceived) {
    22.             firstFrameReceived = true;
    23.  
    24.             if (cameraManager.descriptor.supportsCameraConfigurations) {
    25.                 var cameraConfiguration = cameraManager.currentConfiguration;
    26.                 Assert.IsTrue(cameraConfiguration.HasValue);
    27.                 print($"resolution: {cameraConfiguration.Value.resolution}");
    28.             }
    29.         }
    30.     }
    31. }
    32.  
     
    andyb-unity likes this.
  4. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,960
    I've been able to reproduce this. I wish this was mentioned in the documentation. Thanks!
     
  5. MuhammadKamranUnityDev

    MuhammadKamranUnityDev

    Joined:
    Feb 14, 2022
    Posts:
    1
    Lanre AR Camera resolution always 640*480 in android device. How to change resolution by dynamically according to device?
     
  6. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,960
    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.