Search Unity

What frame number is relative to the image provided by TryGetLatestImage

Discussion in 'Handheld AR' started by AnthonyReddan, Feb 22, 2019.

  1. AnthonyReddan

    AnthonyReddan

    Joined:
    Feb 27, 2018
    Posts:
    13
    I want to cache some data relative to each camera frame image (obtained with TryGetLatestImage from the XRCameraSubsystem extensions) for later processing. i.e. I want to know the state of a set of data for any given camera image that I process.

    Is it enough to cache my data in a ARSubsystemManager.cameraFrameReceived callback and then use that data when I call TryGetLatestImage? i.e. am I guaranteed that the result provided by TryGetLatestImage was provided at the same time cameraFrameReceived was invoked?

    I just want a way to map that image to the game data of the same frame. Currently I do nothing special and just grab the current frame data when I call TryGetLatestImage but I'm testing on a Pixel 2 and wondering if that will work on all devices or under poor performance conditions.
     
  2. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    518
    If you call TryGetLatestImage from the cameraFrameReceived callback, it will be the image rendered that frame. There is also a timestamp associated with each CameraImage. See https://docs.unity3d.com/Packages/c.../UnityEngine.XR.ARExtensions.CameraImage.html

    Note that a CameraImage is a native resource of which there are a limited quantity (I don't know how many; it varies by platform and possibly device). In practice, if you fail to dispose of about 10 of them then ARCore starts complaining about resource exhaustion and the background image stops updating, so don't hold onto them for too long.