Search Unity

Streaming ZED cam video on separate eyes of HTC Vive

Discussion in 'AR/VR (XR) Discussion' started by echizenryoma, Jul 15, 2018.

  1. echizenryoma

    echizenryoma

    Joined:
    Jul 10, 2018
    Posts:
    3
    I am trying to use the two cameras on my ZED Cam to stream separately from either camera on to the respective eye on a HTC Vive set. So I've set up 2 cameras- one for left eye and one for right eye with the SteamVR Camera script && then configuring each cam to render on separate eyes and separate displays.

    I attached a script to each camera which creates a WebCamTexture & allows me display it on a RawImage UI component in Unity:

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6.  
    7. public class CameraRender : MonoBehaviour {
    8.  
    9.     private WebCamTexture wt1;
    10.  
    11.  
    12.     private bool camAvailable;
    13.     private Texture defaultBackground;
    14.  
    15.     public RawImage background1;
    16.     //public RawImage background2;
    17.  
    18.    public AspectRatioFitter fit;
    19.    // Use this for initialization
    20.  
    21.    void Start () {
    22.  
    23.         WebCamDevice[] devices= WebCamTexture.devices;
    24.  
    25.         if (devices.Length>0)   {
    26.             wt1= new WebCamTexture(devices[0].name);
    27.             //wt2= new WebCamTexture(devices[0].name);
    28.         }
    29.  
    30.         if (wt1 ==null) {
    31.             return;
    32.         }
    33.  
    34.         wt1.Play();
    35.         background1.texture= wt1;
    36.         camAvailable= true;
    37.  
    38.        //wt2.Play();
    39.        //background2.texture= wt2;
    40.        //camAvailable= true;
    41.  
    42.     }
    43.  
    44.     // Update is called once per frame
    45.    void Update () {
    46.  
    47.         if (! camAvailable)
    48.              return;
    49.  
    50.        float ratio= (float)wt1.width/(float)wt1.height;
    51.        fit.aspectRatio=ratio;  
    52.     }
    53. }
    So it seems to be working on only one side at all times, the other side is completely black: https://imgur.com/a/OpCvO47

    And either side actually works as it seems to work on one side when I remove the WebcamTexture script from the other. So I am thinking that there's some kind of problem with my script.

    Weirdly, I tried the same thing on my dad's Macbook & it worked fine with both sides streaming & I managed to crop out the required side of the image. But when I try do it on the Linux machine, it doesn't work. I am using the exact same code except 1 is used in wt1= new WebCamTexture(devices[0].name); instead of 0 since the macbook has a built in webcam.

    I've tried redoing what I did on my mac using the Linux countless times but have failed. I have to do my entire project using the Linux machine so I cannot simply just use the macbook for this. So if anyone can offer any suggestions, I would be most grateful.

    here is how it should look (done on the Mac):
    https://imgur.com/a/yPJFMyv