获取 Tango 的相机流数据

Getting Tango's camera stream data

我正在尝试获取 Tango 的相机流,以便将自制的 AR 套件与 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 时,我看到了很多与它相关的 post,但与当前的 IExperimentalTangoVideoOverlay[= 无关12=]

我已经尝试了很多东西,到目前为止,它是我最接近预期的...任何帮助将不胜感激。

您正在使用Texture ID方法获取YUV纹理颜色,这不是很常见。一个更简单的方法是使用 Raw Byte 缓冲方法来获取彩色相机图像,为此:

  1. TangoManager 预制件上,启用视频叠加,并从下拉框中选择 select Raw Byte 方法。
  2. 注册到ITangoVideoOverlay界面。
  3. 将图像缓冲区数据从 YUV 转换为 RGB,这部分与 YUV2Color 函数完全相同,但使用来自 TangoImageData.data
  4. 的数据