【问题标题】:How to get ARCore AcquireCameraImageBytes() in color?如何获得 ARCore AcquireCameraImageBytes() 的颜色?
【发布时间】:2018-06-15 15:54:00
【问题描述】:

我已经被这个问题困扰了好几天了。我正在尝试对我的项目进行一些图像处理。我查看了ARCore 提供的计算机视觉示例,但它只显示了如何访问黑白相机帧。我的图像需要颜色。我已经看过Save AcquireCameraImageBytes() from Unity ARCore to storage as an image 并且没有运气。

我有一个名为GetImage() 的函数,它应该将相机帧作为纹理返回。

public Texture GetImage() {

    if (!Frame.CameraImage.AcquireCameraImageBytes().IsAvailable) {
        return null;
    }

    var ptr = Frame.CameraImage.AcquireCameraImageBytes();
    var bufferSize = ptr.Width * ptr.Height * 4;

    if (_tex == null) {
        _tex = new Texture2D(ptr.Width, ptr.Height, TextureFormat.RGBA32, false, false);
    }

    if (_bytes == null) {
        _bytes = new byte[bufferSize];
    }

    Marshal.Copy(_ptr.Y, _bytes, 0, bufferSize);
    _tex.LoadRawTextureData(_bytes);
    _tex.Apply();
    return _tex;
}

我在这段代码中遇到了两个问题。

首先,几秒钟后,我的应用程序因错误“无法获取相机图像而状态错误资源耗尽”而冻结。

第二个问题是,如果我确实设法显示图像,它不是彩色的,并且像这篇帖子 ARCore for Unity save camera image 一样重复四次。

是否有人有访问彩色 ARCore 图像的工作示例或知道我的代码有什么问题?

【问题讨论】:

    标签: android unity3d computer-vision arcore


    【解决方案1】:

    使用“Frame.CameraImage.AcquireCameraImageBytes();”您将获得 YUV-420-888 格式的灰度图像(see doc) 因此,通过正确的 YUV 到 RGB 转换,您应该获得彩色相机图像。 (但我还没有找到合适的 YUV 到 RGB 转换) 我有一个类似的问题:ARCore Save Camera Image (Unity C#) on Button click 在我更新的问题中我发布了从 AcquireCameraImagesBytes() 获取灰度图像的代码。

    如果您想做图像处理,您是否已经看过Unity Computer Vision Example. 示例?请参阅_OnImageAvailable 使用 TextureReader API,您可以获得彩色图像。 这个 github 问题也可能会有所帮助:https://github.com/google-ar/arcore-unity-sdk/issues/221

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-19
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-30
      相关资源
      最近更新 更多