Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Ar Foundation Camera Resolution

Discussion in 'Handheld AR' started by suitor, Apr 13, 2020.

  1. suitor

    suitor

    Joined:
    May 6, 2019
    Posts:
    6
    Hey!

    Currently I'm trying to change the camera resolution in ar foundation. The accessible ar background image is pretty small (640x480) and basically only useful as reference. I'm aiming for a "okayish" video quality, at least 1280x720, the goal would be 1920x1080.

    I can imagine that it causes problems to process a high-resolution image in ar foundation, but maybe there is a way to feed it to some subsystem before compressing and processing it?

    Thanks a lot in advance!
    Best regards
     
  2. mdurand

    mdurand

    Unity Technologies

    Joined:
    Aug 1, 2016
    Posts:
    39
  3. suitor

    suitor

    Joined:
    May 6, 2019
    Posts:
    6
    I'm accessing the camera Image already, sadly the captured image has the described resolution.
    It's about setting the camera configuration to get a better one.

    Ar Core (while using ArFoundation?) seems to usually use 640x480 - preview resolution which gets upscaled to 1920x1080. That leads to a blurry image. The camera resolution seems to be changeable using ArCore. In the ArCameraManager class we can get the current camera configuration but I don't know how to set it.

    Edit:
    I think I'm pretty close now, what I need to access is the native array in the ArCameraManager. Most likely I'm able to get a list of XRCameraConfigurations which can be set (even if not recommended).

    Code (CSharp):
    1. public NativeArray<XRCameraConfiguration> GetConfigurations(Allocator allocator)
    2.  
    What's the allocator to turn in? Does anyone know how to access the list?
     
    Last edited: Apr 14, 2020
  4. suitor

    suitor

    Joined:
    May 6, 2019
    Posts:
    6
    I think I solved it myself, just not sure if it's the right allocator, can somebody confirm?

    Code (CSharp):
    1. allocator = Allocator.Temp;
    2. NativeArray<XRCameraConfiguration> configurations = new NativeArray<XRCameraConfiguration>();
    3.  
    4. private void GetAvailableConfig()
    5.         {
    6.             configurations = arCameraManager.GetConfigurations(allocator: allocator);
    7.  
    8.             foreach(XRCameraConfiguration config in configurations)
    9.             {
    10.                 Debug.Log(config);
    11.             }
    12.         }
     
  5. MartijnPostmaNedap

    MartijnPostmaNedap

    Joined:
    Dec 4, 2019
    Posts:
    1
    Hey @suitor , how did you manage to use this to set the configuration? When I try to set the ARCameraManager.currentConfiguration = configurations[0]; I get an error: ARCore session is not valid
     
  6. nagybalintgyorgy

    nagybalintgyorgy

    Joined:
    Nov 23, 2018
    Posts:
    1
    Hey,

    you can change the resolution when ARCameraManager's first frameReceived event fires:

    Code (CSharp):
    1.     public ARCameraManager cameraManager;
    2.     bool init = false;
    3.  
    4.     void OnEnable() {
    5.         cameraManager.frameReceived += OnCameraFrameReceived;
    6.     }
    7.  
    8.     void OnDisable() {
    9.         cameraManager.frameReceived -= OnCameraFrameReceived;
    10.     }
    11.  
    12.     void OnCameraFrameReceived(ARCameraFrameEventArgs eventArgs) {
    13.         if (!init)
    14.         {
    15.             cameraManager.subsystem.currentConfiguration = cameraManager.GetConfigurations(Allocator.Temp)[1]; //In my case 0=640*480, 1= 1280*720, 2=1920*1080
    16.             init = true;
    17.         }
     
  7. suitor

    suitor

    Joined:
    May 6, 2019
    Posts:
    6
    as nagybalintgyorgy has written, after you received the frame you can change the resolution
    Code (CSharp):
    1.  
    2. private void Start()
    3.         {
    4.             arCameraManager = this.gameObject.GetComponent<ARCameraManager>();
    5.             allocator = Allocator.Temp;
    6.         }
    7.  
    8. public void SetCameraConfig(int configIndex)
    9.         {
    10.             configurations = arCameraManager.GetConfigurations(allocator: allocator);
    11.  
    12.             if (arCameraManager.subsystem.currentConfiguration != configurations[configIndex])
    13.             {
    14.                 arCameraManager.subsystem.currentConfiguration = configurations[configIndex];
    15.                 Debug.Log("Set camera configuration: " + configurations[configIndex]);
    16.             }
    17.  
    18.             else
    19.             {
    20.                 Debug.Log("Configuration didn't change, choosing same configuration");
    21.             }
    22.         }
    the previous snippet shows how to get the available configs, hope that helps!
     
unityunity