Exemple #1
0
    void Awake()
    {
        UNHVD.unhvd_net_config net_config = new UNHVD.unhvd_net_config {
            ip = this.ip, port = this.port, timeout_ms = 500
        };
        UNHVD.unhvd_hw_config[] hw_config = new UNHVD.unhvd_hw_config[]
        {
            new UNHVD.unhvd_hw_config {
                hardware = "vaapi", codec = "hevc", device = this.device, pixel_format = "p010le", width = 848, height = 480, profile = 2
            },
            new UNHVD.unhvd_hw_config {
                hardware = "vaapi", codec = "hevc", device = this.device, pixel_format = "rgb0", width = 848, height = 480, profile = 1
            }
        };

        //For depth config explanation see:
        //https://github.com/bmegli/unity-network-hardware-video-decoder/wiki/Point-clouds-configuration

        //For MinZ formula see BKMs_Tuning_RealSense_D4xx_Cam.pdf
        //For D435 at 848x480 the MinZ is ~16.8cm, in our result unit min_margin is 0.168
        //max_margin is arbitrarilly set

        DepthConfig dc = new DepthConfig {
            ppx = 421.353f, ppy = 240.93f, fx = 426.768f, fy = 426.768f, depth_unit = 0.0001f, min_margin = 0.168f, max_margin = 0.01f
        };

        //DepthConfig dc = new DepthConfig {ppx = 421.353f, ppy=240.93f, fx=426.768f, fy=426.768f, depth_unit = 0.0000390625f, min_margin = 0.168f, max_margin = 0.01f};
        //DepthConfig dc - new DepthConfig {ppx = 421.353f, ppy=240.93f, fx=426.768f, fy=426.768f, depth_unit = 0.00003125f, min_margin = 0.168f, max_margin = 0.01f};

        //sample config for depth + color, depth aligned to 848x480 color (so we use color intrinsics, not depth intrinsics)
        //DepthConfig dc = new DepthConfig{ppx = 425.038f, ppy=249.114f, fx=618.377f, fy=618.411f, depth_unit = 0.0001f, min_margin = 0.168f, max_margin = 0.01f};

        //sample config for L515 640x480 with depth units resulting in 2.5 mm precision and 2.5575 m range (alignment to depth)
        //DepthConfig dc = new DepthConfig{ppx = 358.781f, ppy=246.297f, fx=470.941f, fy=470.762f, depth_unit = 0.0000390625f, min_margin = 0.19f, max_margin = 0.01f};

        //sample config for L515 1280x720 with depth units resulting in 2.5 mm precision and 2.5575 m range (alignment to color)
        //DepthConfig dc = new DepthConfig{ppx = 647.881f, ppy=368.939f, fx=906.795f, fy=906.768f, depth_unit = 0.0000390625f, min_margin = 0.19f, max_margin = 0.01f};
        //DepthConfig dc = new DepthConfig{ppx = 647.881f, ppy=368.939f, fx=906.795f, fy=906.768f, depth_unit = 0.000250f, min_margin = 0.19f, max_margin = 0.01f};

        //sample config for D455 848x480 with depth units resulting in 2.5 mm precision and 2.5575 m range, MinZ at 848x480 is 350 mm, for depth, depth + ir, depth aligned color
        //DepthConfig dc = new DepthConfig{ppx = 426.33f, ppy=239.446f, fx=422.768f, fy=422.768f, depth_unit = 0.0000390625f, min_margin = 0.35f, max_margin = 0.01f};
        //as above, alignment to color, distortion model ignored
        //DepthConfig dc = new DepthConfig{ppx = 419.278f, ppy=244.24f, fx=419.909f, fy=418.804f, depth_unit = 0.0000390625f, min_margin = 0.35f, max_margin = 0.01f};

        UNHVD.unhvd_depth_config depth_config = new UNHVD.unhvd_depth_config {
            ppx = dc.ppx, ppy = dc.ppy, fx = dc.fx, fy = dc.fy, depth_unit = dc.depth_unit, min_margin = dc.min_margin, max_margin = dc.max_margin
        };

        unhvd = UNHVD.unhvd_init(ref net_config, hw_config, hw_config.Length, ref depth_config);

        if (unhvd == IntPtr.Zero)
        {
            Debug.Log("failed to initialize UNHVD");
            gameObject.SetActive(false);
        }
    }
Exemple #2
0
    void Awake()
    {
        //Application.targetFrameRate = 30;

        UNHVD.unhvd_net_config net_config = new UNHVD.unhvd_net_config {
            ip = this.ip, port = this.port, timeout_ms = 500
        };
        UNHVD.unhvd_hw_config[] hw_config = new UNHVD.unhvd_hw_config[]
        {
            new UNHVD.unhvd_hw_config {
                hardware = "vaapi", codec = "hevc", device = this.device, pixel_format = "p010le", width = 848, height = 480, profile = 2
            },
            new UNHVD.unhvd_hw_config {
                hardware = "vaapi", codec = "hevc", device = this.device, pixel_format = "rgb0", width = 848, height = 480, profile = 1
            }
        };

        IntPtr nullPtr = IntPtr.Zero;

        unhvd = UNHVD.unhvd_init(ref net_config, hw_config, hw_config.Length, IntPtr.Zero);

        if (unhvd == IntPtr.Zero)
        {
            Debug.Log("failed to initialize UNHVD");
            gameObject.SetActive(false);
            return;
        }

        argsBuffer = new ComputeBuffer(4, sizeof(int), ComputeBufferType.IndirectArguments);
        //vertex count per instance, instance count, start vertex location, start instance location
        //see https://docs.unity3d.com/2019.4/Documentation/ScriptReference/Graphics.DrawProceduralIndirectNow.html
        argsBuffer.SetData(new int[] { 0, 1, 0, 0 });

        //For depth config explanation see:
        //https://github.com/bmegli/unity-network-hardware-video-decoder/wiki/Point-clouds-configuration

        //For D435 at 848x480 the MinZ is ~16.8cm, in our result unit min_margin is 0.168
        //max_margin is arbitrarilly set
        DepthConfig dc = new DepthConfig {
            ppx = 421.353f, ppy = 240.93f, fx = 426.768f, fy = 426.768f, depth_unit = 0.0001f, min_margin = 0.168f, max_margin = 0.01f
        };

        //DepthConfig dc = new DepthConfig {ppx = 421.353f, ppy=240.93f, fx=426.768f, fy=426.768f, depth_unit = 0.0000390625f, min_margin = 0.168f, max_margin = 0.01f};

        //sample config for D455 848x480 with depth units resulting in 2.5 mm precision and 2.5575 m range, MinZ at 848x480 is 350 mm, for depth, depth + ir, depth aligned color
        //DepthConfig dc = new DepthConfig{ppx = 426.33f, ppy=239.446f, fx=422.768f, fy=422.768f, depth_unit = 0.0000390625f, min_margin = 0.35f, max_margin = 0.01f};

        SetDepthConfig(dc);
    }
Exemple #3
0
    void SetDepthConfig(DepthConfig dc)
    {
        //The depth texture values will be normalied in the shader, 16 bit to [0, 1]
        float maxDistance = dc.depth_unit * 0xffff;
        //Normalize also valid ranges
        float minValidDistance = dc.min_margin / maxDistance;
        //Our depth encoding uses P010LE format for depth texture which uses 10 MSB of 16 bits (0xffc0 is 10 "1" and 6 "0")
        float maxValidDistance = (dc.depth_unit * 0xffc0 - dc.max_margin) / maxDistance;

        //The multiplier renormalizes [0, 1] to real world units again and is part of unprojection
        float[] unprojectionMultiplier = { maxDistance / dc.fx, maxDistance / dc.fy, maxDistance };

        unprojectionShader.SetFloats("UnprojectionMultiplier", unprojectionMultiplier);
        unprojectionShader.SetFloat("PPX", dc.ppx);
        unprojectionShader.SetFloat("PPY", dc.ppy);
        unprojectionShader.SetFloat("MinDistance", minValidDistance);
        unprojectionShader.SetFloat("MaxDistance", maxValidDistance);
    }