簡體   English   中英

Unity3D & Realsense 2.0 D415 - 地形深度

[英]Unity3D & Realsense 2.0 D415 - Depth to Terrain

我正在嘗試根據實感攝像頭 D415 的深度值生成運行時地形。 我拿起相機嘗試為夏天做點什么。 之前我在 Unity 中從未使用過網絡攝像頭,所以即使在瀏覽了所有示例場景后,我也非常迷茫。

我的地形是 500 x 500 x 40 使用 RealSense 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 中使用過相機。

有點跑題,但我想問一下你上面的代碼運行得如何? 您是否收到以下錯誤:

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

我正在嘗試做類似的事情,但也遇到了問題。 也許我們可以一起解決?

干杯,凸輪

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM