Search Unity

Bug Hololens 2 WebcamTexture locatable camera byte[] encoding problem

Discussion in 'AR' started by tv-gc, Sep 16, 2021.

  1. tv-gc

    tv-gc

    Joined:
    Sep 16, 2021
    Posts:
    9
    Hi!

    I'm able to show the live feed on a RawImage, using WebcamTexture but the byte[] conversion using .EncodeToPNG() (or Jpeg) scrambles the image.
    The same code works sending the Android's webcam feed over to the Hololens. (the image doesn't get scrambled)
    Does anyone have an idea why only this specific resolution of 896x504 works when converting it to a byte[] or is this a bug?
    What i found for this resolution is that is used on the 1st Hololens, in low power mode.
    But i'm using the 2nd Hololens...

    Expected behavior
    Encoding to byte[] would show the same image as being rendered on a RawImage.

    Actual behavior
    Image gets scrambled.


    Steps to reproduce
    //grab webcam and set it to a WebcamTexture
    Code (CSharp):
    1. WebCamDevice[] webcamDevices = WebCamTexture.devices;
    2.  
    3. for (int i = 0; i < webcamDevices.Length; ++i)
    4. {
    5.    print("Webcam available: " + webcamDevices[i].name);
    6.  
    7.    webCamTexture = new WebCamTexture(webcamDevices[i].name, width, height, fps);
    8.  
    9.    if (rawImage.texture == null)
    10.    {
    11.        rawImage.texture = webCamTexture;
    12.  
    13.        webCamTexture.Play();
    14.  
    15.        break;
    16.    }
    17. }
    //Using the WebcamTexture, copy color[] over to a Texture2D
    Code (CSharp):
    1. webcamTexture = new Texture2D(webcamManager.width, webcamManager.height);
    2.  
    3. if (webcamTexture && webcamManager && webcamManager.webCamTexture)
    4.    webcamTexture.SetPixels(webcamManager.webCamTexture.GetPixels());
    5.  
    6. byte[] byteArray = webcamTexture.EncodeToJPG();
    Unity editor version
    I tried with 2020.3.14f, 16f and 18f

    Mixed Reality Toolkit release version
    2.7.2.0
     
    Last edited: Sep 21, 2021
    Jules_io likes this.
  2. tv-gc

    tv-gc

    Joined:
    Sep 16, 2021
    Posts:
    9
    Hi!

    I've managed to make the webcamtexture work but only with this strange resolution: 896x504

    Does anyone have an idea why only this specific resolution works when converting it to a byte[] or is this a bug?
    What i found for this resolution is that is used on the 1st Hololens, in low power mode.
    But i'm using the 2nd Hololens...

    Thanks!
     
    Last edited: Sep 20, 2021
  3. wwr774926

    wwr774926

    Joined:
    Oct 30, 2018
    Posts:
    1
    I have get the same error.
    I alreay set WebCamTexture widht height and fps to 1280x720 30,but the resolution still stand 896x504.

    Did you fixed it?
     
    Last edited: Sep 28, 2021
  4. tv-gc

    tv-gc

    Joined:
    Sep 16, 2021
    Posts:
    9
    Nope,
    I needed holograms and depth information from the webcam so dropped this method and went with the media capture+frame reader path to get access to the correct camera and settings.

    But i do believe this is a bug because it's grabbing a resolution from the previous hololens in power save mode, which shouldn't be happening while using the hololens 2.
     
    wwr774926 likes this.