Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

"Unity Remote" - Camera Support (sending phone camera content to desktop)

Discussion in 'Editor & General Support' started by ludos, Jul 22, 2014.

  1. ludos

    ludos

    Joined:
    Nov 14, 2011
    Posts:
    55
    I am unsure wether this is a feature not completely implemented. If it's bugged or it's just missing a working example how to use it.

    According to the documentation ( http://docs.unity3d.com/Manual/UnityRemote4.html ) and the Sourcecode of Unity Remote in the Asset Store it should be possible to transfer the recorded images from the mobile device to the Desktop Computer.

    However the manual does not describe how to do this. Nor have i found any way to implement it. I have experienced the problem on OSX and iOS. Others have had the same problem on Android ( http://forum.unity3d.com/threads/de...-using-remote-4-in-4-5f6.248484/#post-1706320 ).

    I have tried to change the Unity Remote form the Asset Store so it transfers the images without a request from the client side. However even then i am unable to capture the data on the desktop computer.

    Does anybody know how to implement this? Is a change in the Unity Remote required?
     
  2. ludos

    ludos

    Joined:
    Nov 14, 2011
    Posts:
    55
    Anybody from Unity maybe? I dont not want to believe that there was no testing of the unity remote. I just wonder why no use examples are delivered with the unity remote package in the asset store.
     
  3. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    740
    Hi Ludos,

    if you want to use WebCamTexture to get the camera stream from a device connected through Unity Remote, then you must initalize it through the constructor as it is stated in the documentation.

    You can apply following script to any object in your scene. Ensure you created a suitable material which is assigned to your object and to the script too! It should list you all cameras available on your host and remote clients!

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using System.Collections.Generic;
    4.  
    5. public class WebCamBehaviour : MonoBehaviour
    6. {
    7.     /// <summary>
    8.     /// Meta reference to the camera
    9.     /// </summary>
    10.     public Material CameraMaterial = null;
    11.    
    12.     /// <summary>
    13.     /// The number of frames per second
    14.     /// </summary>
    15.     private int m_framesPerSecond = 0;
    16.    
    17.     /// <summary>
    18.     /// The current frame count
    19.     /// </summary>
    20.     private int m_frameCount = 0;
    21.    
    22.     /// <summary>
    23.     /// The frames timer
    24.     /// </summary>
    25.     private DateTime m_timerFrames = DateTime.MinValue;
    26.    
    27.     /// <summary>
    28.     /// The selected device index
    29.     /// </summary>
    30.     private int m_indexDevice = -1;
    31.    
    32.     /// <summary>
    33.     /// The web cam texture
    34.     /// </summary>
    35.     private WebCamTexture m_texture = null;
    36.    
    37.     // Use this for initialization
    38.     void Start()
    39.     {
    40.         if (null == CameraMaterial)
    41.         {
    42.             throw new ApplicationException("Missing camera material reference");
    43.         }
    44.        
    45.         Application.RequestUserAuthorization(UserAuthorization.WebCam);
    46.     }
    47.    
    48.     void OnGUI()
    49.     {
    50.         if (m_timerFrames < DateTime.Now)
    51.         {
    52.             m_framesPerSecond = m_frameCount;
    53.             m_frameCount = 0;
    54.             m_timerFrames = DateTime.Now + TimeSpan.FromSeconds(1);
    55.         }
    56.         ++m_frameCount;
    57.        
    58.         GUILayout.Label(string.Format("Frames per second: {0}", m_framesPerSecond));
    59.        
    60.         if (m_indexDevice >= 0 && WebCamTexture.devices.Length > 0)
    61.         {
    62.             GUILayout.Label(string.Format("Selected Device: {0}", WebCamTexture.devices[m_indexDevice].name));
    63.         }
    64.        
    65.         if (Application.HasUserAuthorization(UserAuthorization.WebCam))
    66.         {
    67.             GUILayout.Label("Has WebCam Authorization");
    68.             if (null == WebCamTexture.devices)
    69.             {
    70.                 GUILayout.Label("Null web cam devices");
    71.             }
    72.             else
    73.             {
    74.                 GUILayout.Label(string.Format("{0} web cam devices", WebCamTexture.devices.Length));
    75.                 for (int index = 0; index < WebCamTexture.devices.Length; ++index)
    76.                 {
    77.                     var device = WebCamTexture.devices[index];
    78.                     if (string.IsNullOrEmpty(device.name))
    79.                     {
    80.                         GUILayout.Label("unnamed web cam device");
    81.                         continue;
    82.                     }
    83.                    
    84.                     if (GUILayout.Button(string.Format("web cam device {0}{1}{2}",
    85.                                                        m_indexDevice == index
    86.                                                        ? "["
    87.                                                        : string.Empty,
    88.                                                        device.name,
    89.                                                        m_indexDevice == index ? "]" : string.Empty),
    90.                                          GUILayout.MinWidth(200),
    91.                                          GUILayout.MinHeight(50)))
    92.                     {
    93.                         m_indexDevice = index;
    94.                        
    95.                         // stop playing
    96.                         if (null != m_texture)
    97.                         {
    98.                             if (m_texture.isPlaying)
    99.                             {
    100.                                 m_texture.Stop();
    101.                             }
    102.                         }
    103.                        
    104.                         // destroy the old texture
    105.                         if (null != m_texture)
    106.                         {
    107.                             UnityEngine.Object.DestroyImmediate(m_texture, true);
    108.                         }
    109.                        
    110.                         // use the device name
    111.                         m_texture = new WebCamTexture(device.name);
    112.                        
    113.                         // start playing
    114.                         m_texture.Play();
    115.                        
    116.                         // assign the texture
    117.                         CameraMaterial.mainTexture = m_texture;
    118.                     }
    119.                 }
    120.             }
    121.         }
    122.         else
    123.         {
    124.             GUILayout.Label("Pending WebCam Authorization...");
    125.         }
    126.     }
    127.    
    128.     // Update is called once per frame
    129.     private void Update()
    130.     {
    131.         if (null != m_texture &&
    132.             m_texture.didUpdateThisFrame)
    133.         {
    134.             CameraMaterial.mainTexture = m_texture;
    135.         }
    136.     }
    137. }
    The script was posted by tgraupmann in http://forum.unity3d.com/threads/webcam-on-android-not-working.123732/ I just added missing &&.

    Hope this helps!
     
    megadavido, CarlosMx and kenmgrimm like this.
  4. ludos

    ludos

    Joined:
    Nov 14, 2011
    Posts:
    55
    Thanks, yes this version also works on ios.

    my fault was to check for the available camera's only on "OnEnable"
     
    David-Berger likes this.
  5. ciruelica

    ciruelica

    Joined:
    Apr 3, 2013
    Posts:
    15
    Hi,

    I am developing an AR app with Vuforia. I am using remote app with the aim of playing the camera from my android on the unity editor for testing.
    I used the suggested script but I didn't make it work. The "suitable material" you talk about, does it need to have any particular property?
    Do I need to modify the profiles.xml file in order to add my android device camera? Where can I get the camera name?

    Thanks for your help in advance!
     
  6. ciruelica

    ciruelica

    Joined:
    Apr 3, 2013
    Posts:
    15
    This is what I get when I use remote with my phone. However there's no way to make the stream change when I click any of the options. I already added "Remote Camera 0" and "Remote Camera 1" to profiles.xml file but still doesn't work. Any suggestion?
     

    Attached Files:

  7. ludos

    ludos

    Joined:
    Nov 14, 2011
    Posts:
    55
    vuforia should have a selection field to chose the camera i think
     
  8. ciruelica

    ciruelica

    Joined:
    Apr 3, 2013
    Posts:
    15
    Right, vuforias has it, but it only shows the laptop camera. Until you press play button, the camera and the pc are not connected, so Unity editor doesn't recognise the device camera.
     
  9. ludos

    ludos

    Joined:
    Nov 14, 2011
    Posts:
    55
    right, sorry i mixed something up. i'm using a separate usb camera for vuforia testing. if you find a way of using unity remote i'd be interested as well :) but i currently lack the time to test that.
     
  10. Anlasa

    Anlasa

    Joined:
    May 27, 2013
    Posts:
    2
    Hi,

    Any update on this?

    I experimented the same problem, so I tried it using an Android cam as "webcam to PC" app (DroidCam, IP WebCam and WO WebCam), Vuforia recognized them as Camera Devices, but DroidCam and WO WebCam didn't run in background, so I can't use Unity remote simultaneously (my AR app works fine in PC with my Android camera as webcam). IP WebCam does run in background, but Unity didn't found the device when Vuforia called it.

    I used the suggested script, I can enable my android cameras in Vuforia using the Background Plane material (AR Camera>Camera>BackgroundPlane) only after playing my app, but Vuforia continued using my laptop camera to search for the Trackable image.

    Maybe using Android Stuido for enabling device cameras......or another third party software to connect android camera as webcam.
     
  11. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    740
    This sounds like a bug, could someone please create a bug report with a minimal reproducible so we can test and see the behaviour? A good description would help a lot too! When submitted please add the bug number in this thread so we don't miss it :)
     
  12. TobiasWa

    TobiasWa

    Joined:
    Mar 14, 2016
    Posts:
    5
    Any updates on this? It would be really helpful to have this working for Vuforia, since it takes so much time to build the project every time.
     
  13. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    848
    As far as I can tell there is still no solution for this. Do let me know if I am wrong.
     
  14. dnt505

    dnt505

    Joined:
    Nov 8, 2015
    Posts:
    1
    Hi, Vuforia still doesn´t support this? I would be really helpfull
     
    YCE2010 likes this.
  15. Tommy_Wong

    Tommy_Wong

    Joined:
    Nov 23, 2018
    Posts:
    1
    I also have this problems. Can anyone help me?
     
  16. ImperialDynamics

    ImperialDynamics

    Joined:
    Jun 21, 2018
    Posts:
    21
    same here!
    I'm using Vuforia with DroidCam to read the phone's camera and it works great.
    However I also want to use Unity Remote at the same time to read the phone's GPS coordinates.
    But whenever I enable Unity Remote DroidCam no longer works and vice versa! I need both Unity Remote and DroidCam at the same time :(
     
    SCIITS likes this.
  17. starwalker097

    starwalker097

    Joined:
    Apr 25, 2019
    Posts:
    1
    Kindly someone tell me how to use DroidCam with Unity for testing.
     
  18. paokuanwu0412

    paokuanwu0412

    Joined:
    Aug 17, 2019
    Posts:
    1
    If you want to use Iphone cam to switch PC webcam in unity AR project(by Vuforia). I've tried using IVCam, and it works. The process is pretty simple. Just download IVCam APP on your Iphone and client software for windows(https://www.e2esoft.com/ivcam/). Then open the APP and the client software to try to change your Iphone as webcam. Then open your unity AR project, you will find that the camera list has two cameras you can choose. There is one thing you have to notice. The original screen view is reverse, but you still can switch the screen view directly by the button on IVCam APP after you rating the APP. Good luck!
     
  19. berilyalcinkayaa

    berilyalcinkayaa

    Joined:
    Jan 11, 2019
    Posts:
    2
    Hello everyone :) The script which is shared by David Berger works well, if you are seeing black screen, it may happen because your phone does not acces to the App ( in my case it is Unity Remote 5 ). So, I allowed my phone camera to work for Unity Remote 5 from my phone Settings and it works well.
     
  20. unity_7i79S5ys7f7DcQ

    unity_7i79S5ys7f7DcQ

    Joined:
    Aug 22, 2020
    Posts:
    1
    Hello Berilyalcinkayaa, thanks for your information, I used that script to allow IPhone to use the camera success, but after that still black screen once the play mode. Any other setting in need? thanks a lot for your sharing.
     
  21. chantey

    chantey

    Joined:
    Mar 5, 2017
    Posts:
    49
    Me too, turns out the built in devices are available a few frames before the remote ones.