Search Unity

Resolved AR on Surface Pro 7 - Unable to Use Camera

Discussion in 'AR' started by Cornysam, Dec 1, 2021.

  1. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,464
    Hello,

    I have made several apps on my Android device with ARFoundation. We recently got some Microsoft Surface Pro 7s and I am tasked with converting the Android AR apps to these tablets. I know that they run Windows 10 and I haven't had any issues getting them to build and run on the tablets.

    My issue is this: I cannot get the built-in webcam to work while running the built app. My UI shows up and works, but the AR features do not since the camera is just black. The light actually comes on near the cameras since I changed some of the Project Settings to allow Webcam, microphone, etc. but nothing from the camera is displayed on the screen.

    My questions:
    • Does AR Foundation even work with Windows 10?
    • If it doesn't work with W10, what should i be using? I believe it is capable of AR (unity3d - Windows Mixed Reality for Surface App - Stack Overflow). From other research i believe it is, but i could be wrong of course.
    • Am I just not enabling the camera properly (see code below)?
    • Is there something wrong with my scene setup that is not allowing it (aka wrong camera or something)?
    I have looked at some other forums but haven't found anything too different from the code below that works. Here is what i have been using just trying to test out the camera functionality:

    Code (CSharp):
    1. private static WebCamTexture webCam;
    2.  
    3.     private void Awake()
    4.     {
    5.         WebCamDevice[] devices = WebCamTexture.devices;
    6.         int cameraIndex = 0;
    7.         if (devices.Length == 0)
    8.         {
    9.             return;
    10.         }
    11.  
    12.         foreach (WebCamDevice cam in devices)
    13.         {
    14.             if (cam.isFrontFacing)
    15.             {
    16.                 webCam = new WebCamTexture(cameraIndex, Screen.width, Screen.height);
    17.                 webCam.deviceName = cam.name;
    18.                 webCam.Play();
    19.             }
    20.         }
    21.     }
    I have also tried a bit of code that allows me to see the camera's output as a texture on a RawImage or other objects, but it just overlays the UI and it also doesn't even detect the ground and such. This is not what i do on my Android AR apps so i figured it wasn't the right approach either. I can show that code if it actually is the right path.

    Any guidance would be appreciated.
     
  2. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,142
    AR Foundation doesn't do any image processing, it delegates it to native AR providers such as ARKit and ARCore. There is no such provider for Windows 10, so AR Foundation will not work there.
     
    andyb-unity and Cornysam like this.
  3. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,464
    Thank you for the response. Last night i learned basically the same thing. Thankfully, i also learned that using Vuforia or EasyAR will work for the Surface Pros. Now i am on that path, wish me luck.
     
  4. imayinone

    imayinone

    Joined:
    Jul 7, 2022
    Posts:
    1
    I'm currently using Vuforia, but I get the same error you're getting with the camera not being used. How did you fix this using Vuforia or did it work post-build without any tweaks? I'm building to the Surface Pro X,
    Thank you.
     
  5. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,464
    I never ended up figuring it out. I didn't actually need to use it and all of the forums i found at the time were very complicated and required more time than i was allowed to put in at work.

    I ended up getting a tablet than ran on Android and not Windows and made apps like i do for my phone.