Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

No webcams found using WebCamTexture on Surface RT

Discussion in 'Windows' started by Jonny-Roy, Jul 25, 2013.

  1. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    In C# I've added a webcam using the following code:


    public WebCamTexture camTexture;

    then in the start:

    camTexture = new WebCamTexture();
    camTexture.requestedHeight = Screen.height;
    camTexture.requestedWidth = Screen.width;

    camTexture.Play();
    W = camTexture.width;
    H = camTexture.height;

    Works fine in the editor, etc but deployed to a Surface RT I get:

    No available webcams are found. Either there is no webcam connected, or they are all in use by other applications (like skype)

    I've restarted and cold booted but it makes no difference, is the webcam not supported yet? If not does anyone have a link to unsupported features? Or the timescales for when they will be supported.

    Thanks,

    Jon
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,889
    Have you enable it in Capabalities, in Package.appxmanifest ?
     
  3. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Yes, ticked the Webcam under Capabilities in Package.appxmanifest, is there anything else you need to do?
     
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,889
    Surface RT has two cameras, I think, try querying WebCamTexture.devices, and setting which camera you want to use via WebCamTexture.deviceName
     
  5. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Hi Tomas,

    Made some progress, I used the debugger (which took a little effort to get going I think their might be a slight issue matching up the pdb to the modules) to enumerate the devices which worked great, then used the following code:

    screenRect = new Rect(0, 0, Screen.width, Screen.height);
    var devices = WebCamTexture.devices;
    var deviceName = devices[0].name;
    camTexture = new WebCamTexture(deviceName,320, 240, 30);

    This works and creates the camera okay, but the following:

    camTexture.Play();

    Fails with the following error:

    Error: Operation has failed with error 0x80000000e: A method was called at an unexpected time.

    ( [App path is here]/TaskWrapper.h:create_task::<lambda_xxx>::eek:perator() at 93)

    This was fired during the Start on a camera gameObject. Also please note replacing void Start with IEnumerable Start meant the Start did not fire at all.

    Any suggestions on what to try next?

    Thanks,

    Jon
     
  6. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Hi Thomas,

    Do you think I should report this as a bug?

    Thanks,

    Jon
     
  7. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    I get this issue too. I think it's safe to say its a bug.
     
  8. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    I filed a bug report, should be a fairly easy fix though at least.
     
  9. Lexustio

    Lexustio

    Joined:
    Jun 26, 2013
    Posts:
    18
    While running the app, swipe from the right side of the screen to open the side menu (whatever it's called), then 'settings' -> 'permissions' -> webcam.

    The app I've been developing seems to randomly drop the permission for using the webcam, and I need to give the permission from there. After that it seems to work. Not 100% if it's the same problem (error code) though.
     
  10. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Hey Lexustio, I thought too it might be that, but I tried enabling it and get this error:

    realgfxdevice == 0 || Thread::CurrentThreadIsMainThread()

    So it's definitely something odd with Windows RT or the Surface. But hey thanks for the suggestion.
     
  11. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Okay so I've made some progress with this, the following causes an error:

    material.mainTexture=camTexture;

    Though I believe the error is just caused by creating a WebCamTexture and having a MeshFilter or MeshRenderer on the same gameObject. The only work around I can find is using GUI.DrawTexture...which is a bit of a shame but for my circumstances I can work around it.

    The other issue is you cannot use:

    camTexture.GetPixels32();

    This causes the error:

    A first chance exception of type 'System.NullReferenceException' occurred in UnityEngineProxy.DLL

    However you can use:

    camTexture.GetPixels();

    Which again is fine for me as I can just convert my code to use the float values rather than the byte values.

    Few at least a workaround for my app!
     
  12. Lexustio

    Lexustio

    Joined:
    Jun 26, 2013
    Posts:
    18
    I'm quite sure I replied to this post but for some reason it didn't get through.

    I thought I was the only one getting the strange "realGfxError", but I guess i'm not alone. At least to me that error appears when I initialize open the camera in a debug/release build, NOT in the editor. Usually the camera starts like it should, even if I get that error message. I haven't tried GetPixels32, but at least GetPixels works, like with you. I believe the line in the code that triggers the error is the one where you "start" the camera, ie:

    camTexture.Play();

    Dunno if you've seen it but I posted a thread about this some time ago as well, title for the thread is "Strange problems with microphone and webcam".
     
  13. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Hi Lexustio,

    I managed to solve my issues, the thing that worked for me was:

    1) Ensure you have an issolated script that only creates the webcamtexture and wraps up the playing etc, then have the WebCamTexture public.
    2) After you call play wait until isPlaying returns true until you access any of the properties (GetPixels or try to set a texture to equal WebCamTexture)
    3) Make sure you tick WebCam in the unity permissions section for windows 8, some people say you have to do this in visual studio too, for me it was automatic.
    4) On the windows rt machine, ensure you have gone to settings in the side panel and allowed camera permissions.

    This then sorted the camera issues for me, on the main it seemed to be either having a meshrenderer on the same script, or not waiting for isPlaying, and for anyone wanting the Color32[] you can just convert the return from GetPixels, which is not big deal, you can run it within a separate thread easily enough,
     
  14. CTAai

    CTAai

    Joined:
    Mar 4, 2013
    Posts:
    3
    Jonny can you paste here a code that works around the getPixels32?
    How can I exchange getPixels32 into getPixels in my code...

    Also how can I exchange material.mainTexture = webCamTexture into something that works fine...
    Thank you.

     
  15. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Sure, it's surprisingly easy:

    Color32[] cArray=new Color32[this.c.Length];
    for(int i=0;i<this.c.Length;i++)
    {
    cArray=this.c;
    }

    Where this.c is your array from GetPixels! So very simple!

    So the material.mainTexture=WebCamTexture works fine, I did it on a seperate gameobject just to be safe!