【问题标题】:Unity3D & Realsense 2.0 D415 - Depth to TerrainUnity3D 和 Realsense 2.0 D415 - 深度到地形
【发布时间】:2020-01-02 21:05:37
【问题描述】:

我正在尝试从 RealSense 相机 D415 的深度值生成运行时地形。 我拿着相机试着为夏天做点什么。我之前在 Unity 中使用的网络摄像头从未超过网络摄像头,所以即使在浏览完所有示例场景后我也很迷茫。

我的地形是 500 x 500 x 40 使用实感 SDK 2.0 地形生成器代码在下面,它与 Perlin 噪声一起使用

using UnityEngine;
using Intel.RealSense;

/// <summary>
/// this script is made to test the new terrain in unity with intel realsense depth
/// </summary>
public class TerrainGenerator : MonoBehaviour {

    public int depth = 40;
    public int width = 500;
    public int height = 500;

    public float scale = 20f;

    public float xOffset = 10;
    public float yOffset = 10;
    private DepthFrame depthFrame;
    public bool scroll;
    public float scrollSpeed;

    private Pipeline pipe;
    private void Start()
    {
        ///
        pipe = new Pipeline();
        pipe.Start();


        ///


        xOffset = Random.Range(0f, 9999f);
        yOffset = Random.Range(0f, 9999f);

        scroll = false;
        scrollSpeed = 0;
    }
    void Update()
    {
        Terrain terrain = GetComponent<Terrain>();
        terrain.terrainData = GenerateTerrain(terrain.terrainData);

        if(scroll)
            xOffset += Time.deltaTime * scrollSpeed;

    }
    TerrainData GenerateTerrain(TerrainData tData)
    {
        tData.heightmapResolution = width + 1;
        tData.size = new Vector3(width, depth, height);
        tData.SetHeights(0, 0, GenerateHeights());
        return tData;
    }
    float[,] GenerateHeights()
    {
        float[,] heights = new float[width, height];
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {

                //heights[x, y] = CalculateHeight(x, y);
                var frames = pipe.WaitForFrames();
                var depth = frames.DepthFrame;
                heights[x, y] = depth.GetDistance(x, y);

            }
        }
        return heights;
    }

    float CalculateHeight(int x, int y)
    {
        //float xCoord = (float)x / width * scale + xOffset;
        //float yCoord = (float)y / height * scale + yOffset;
        //return depthFrame.GetDistance(x,y);
        //return Mathf.PerlinNoise(xCoord, yCoord);

        using (var frames = pipe.WaitForFrames())
        using (var depth = frames.DepthFrame)
            return depth.GetDistance(x, y);
    }

}

我正在寻找有关如何正确初始化相机深度的一些指导。我之前从未在 Unity 中使用过相机。

【问题讨论】:

    标签: c# unity3d realsense


    【解决方案1】:

    有点跑题了,但我想问一下你上面的代码运行得怎么样?您是否收到以下错误:

    ExternalException: rs2_pipeline_wait_for_frames(pipe:000000006402E3C0) Rethrow as Exception: Frame didn't arrived within 1000

    我正在尝试做类似的事情,但也遇到了问题。也许我们可以一起解决?

    干杯, 凸轮

    【讨论】:

    • 你应该把它变成评论,因为它并没有真正回答用户的问题(尽管它仍然可能有帮助)
    • 我很乐意,但我需要 50 个代表才能做到这一点!看不到任何其他向用户发送消息的方式。有什么想法吗?
    • 这是一个关于 cmets meta.stackexchange.com/a/214174 的可能有用的元问题。就我建议的事情而言,我会说让你的脚湿透回答一些你可以处理的问题,或者如果你有一些好的问题问那些(但不要只是为了问而问)跨度>
    • 我觉得我被劝阻不要使用这个网站,所以我会去别处看看。
    • 相反@CamAtlantic,我们希望您传播您的知识并帮助他人!如果您不喜欢在 StackOverflow 上获得声誉,您可以尝试任意数量的其他 StackExchange sites;通过在另一个 StackExcahnge 网站上获得 200 个声誉,您将 get +100 reputation on all other sites for being a trusted member!
    猜你喜欢
    • 2023-03-12
    • 2020-03-14
    • 1970-01-01
    • 1970-01-01
    • 2020-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多