Search code examples
unity-game-enginegoogle-project-tango

m_videoOverlayTextureY pixels are not valid, but the texture render correctly with GUI.DrawTexture


I'm trying to get the YUV image from the camera but when I try to read the pixels in the YUVTexure provided by GetVideoOverlayTextureYUV() all the pixels are set to '205'. The weird thing is I can draw the the 'Y' texture withGUI.DrawTexture(someRect, _texture.m_videoOverlayTextureY); and I can see the image is there, I just can't read it with getPixels().

I'm also using the Tango AR Camera prefab in the project so m_useExperimentalVideoOverlay is set to true. We tried to use the non experimental API but then the AR Camera prefab stopped working.

As anyone been able to acces the image data in Unity using IExperimentalTangoVideoOverlay?


Solution

  • The texture from GetVideoOverlayTextureYUV is different than the regular Unity Texture2D. In the Tango Unity SDK, it creates a Texture2D object on the Unity level and passes the textureID to native C++ API to filled out. So the texture pixel value is not stored to Unity, instead, it gets copied to GPU memory directly from native code, and Unity texture only have the textureID of it. That's why it can be rendered out, but can not be read.

    To get the actual byte buffer from color camera, you should used the ITangoVideoOverlay interface. The callback returns a YUV buffer, the conversion function to RGB is same as the one in the YUV2RGB.shader