Search Unity

ARFoundation - How to get camera orientation?

Discussion in 'AR' started by grubertm, Apr 16, 2019.

  1. grubertm

    grubertm

    Joined:
    Jan 9, 2018
    Posts:
    8
    When calling TryGetLatestImage() I get the camera image in whatever orientation the device might consider its default. What is the recommended way to query that orientation?
    For example if I start the app in Portrait orientation the data I get from TryGetLatestImage() might be in Landscape Left or Landscape Right. Where is that information exposed?
     
  2. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    TryGetLatestImage exposes the raw, unrotated camera data. It will always be in the same orientation (landscape right, I believe). The purpose of this API is to allow for additional CPU-based image processing, such as with OpenCV or other computer vision library. These libraries usually have a means to rotate images, or accept images in various orientations, so we there is no built-in functionality to rotate the image.

    For what are you using the camera image, and why do you need to rotate it?
     
  3. grubertm

    grubertm

    Joined:
    Jan 9, 2018
    Posts:
    8
    We have an existing tensorflow segmentation model that was trained on portrait oriented images. I would like to feed the AR Foundation image to it but for that I first need to know whether any rotation needs to be applied or not.
     
  4. grubertm

    grubertm

    Joined:
    Jan 9, 2018
    Posts:
    8
    Last edited: Apr 16, 2019
  5. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
  6. grubertm

    grubertm

    Joined:
    Jan 9, 2018
    Posts:
    8
    I would think Screen.orientation only solves half the problem. It tells me how the screen is oriented. It doesn't tell me how the device's camera is oriented/mounted with regards to the screen.
     
  7. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    It should always be the same. Are you finding it different on different devices?
     
  8. grubertm

    grubertm

    Joined:
    Jan 9, 2018
    Posts:
    8
  9. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    A previous version of Google's computer vision sample for the ARCore Unity SDK obtained the physical camera's orientation. Here is how they did it: https://github.com/google-ar/arcore...sion/Scripts/ComputerVisionController.cs#L248

    Luckily, it's all in C#, so you should just be able to copy and paste
    _GetCameraImageToDisplayRotation
    for your own needs. I'll also see about getting this into AR Foundation proper.
     
    grubertm likes this.
  10. grubertm

    grubertm

    Joined:
    Jan 9, 2018
    Posts:
    8
    Great. Thank you for your help Tim!
     
  11. vincentfretin

    vincentfretin

    Joined:
    Jul 4, 2019
    Posts:
    7
    For anyone finding this thread, I put some code using Screen.orientation on this GitHub issue
     
    FaberVi likes this.
  12. FaberVi

    FaberVi

    Joined:
    Nov 11, 2014
    Posts:
    146
    Incredible how nothing has been implemented yet in the ARFoundation example. It seems to me a very fundamental thing for the full functioning of the example itself. Could I ask you to fully coexist the part of code to rotate the preview correctly? There are some parts that I can't understand. Thank you