获取Tango的相机流数据

时间:2016-07-04 17:18:06

标签: unity3d google-project-tango

我试图获得Tango的相机流,以便将自制的AR Kit与Tango结合起来。

我已经陷入了Tango编辑器模拟中所有功能正常运行的地步,而不是推送到平板电脑的应用程序。

我使用的代码如下:

YUVTexture yuvTexture = m_tangoApplication.GetVideoOverlayTextureYUV();
Texture2D yTexture = yuvTexture.m_videoOverlayTextureY;
// m_videoOverlayTextureCr is not used by Tango yet for some reason
Texture2D uvTexture = yuvTexture.m_videoOverlayTextureCb;

// convert from YV12 to RGB
for (int i = 0; i < yTexture.height; ++i)
{
    for (int j = 0; j < yTexture.width; ++j)
    {
        Color yPixel = yTexture.GetPixel(j, i);
        Color uvPixel = uvTexture.GetPixel(j, i);

        m_texture.SetPixel(4 * j + 0, yTexture.height - i - 1, YUV2Color(yPixel.r, uvPixel.r, uvPixel.g));
        m_texture.SetPixel(4 * j + 1, yTexture.height - i - 1, YUV2Color(yPixel.g, uvPixel.r, uvPixel.g));
        m_texture.SetPixel(4 * j + 2, yTexture.height - i - 1, YUV2Color(yPixel.b, uvPixel.b, uvPixel.a));
        m_texture.SetPixel(4 * j + 3, yTexture.height - i - 1, YUV2Color(yPixel.a, uvPixel.b, uvPixel.a));
    }
}

YUV2Color(摘自Tango的YUV2RGB着色器):

public static Color YUV2Color(float y_value, float u_value, float v_value)
{
    float r = y_value + 1.370705f * (v_value - 0.5f);
    float g = y_value - 0.698001f * (v_value - 0.5f) - (0.337633f * (u_value - 0.5f));
    float b = y_value + 1.732446f * (u_value - 0.5f);

    return new Color(r, g, b, 1f);
}

有人已经解决了这个问题吗?当 ITangoVideoOverlay 主要使用时,我看过很多与之相关的帖子,但当前的 IExperimentalTangoVideoOverlay

没有任何内容

我已经尝试了很多东西,到目前为止,它已经达到我所期望的最接近的水平......任何帮助都会受到高度赞赏。

1 个答案:

答案 0 :(得分:2)

You are using the Texture ID method to get the YUV texture color, this is not very common to do. A easier path would be using the Raw Byte buffer method to get color camera image, to do that:

  1. On TangoManager prefab, enable video overlay, and select Raw Byte method from the drop down box.
  2. Register to ITangoVideoOverlay interface.
  3. Convert the image buffer data from YUV to RGB, this part is exactly like the YUV2Color function, but use data from TangoImageData.data