コード例 #1
0
    public static BGRA ColorizeBlueToRed(short depthPixel, Tuple <int, int> min_max)
    {
        int min = min_max.Item1;
        int max = min_max.Item2;

        byte PixelMax = Byte.MaxValue;

        BGRA result = new BGRA(0, 0, 0, PixelMax);

        if (depthPixel == 0)
        {
            return(result);
        }

        int clampedValue = depthPixel;

        clampedValue = Math.Min(clampedValue, max);
        clampedValue = Math.Max(clampedValue, min);
        float hue = (float)(clampedValue - min) / (float)(max - min);

        float range = 2.0f / 3.0f;

        hue *= range;
        hue  = range - hue;

        float fRed   = 0.0f;
        float fGreen = 0.0f;
        float fBlue  = 0.0f;

        StaticImageProperties.ColorConvertHSVtoRGB(hue, 1.0f, 1.0f, ref fRed, ref fGreen, ref fBlue);

        result.R = Convert.ToByte(fRed * (float)PixelMax);
        result.G = Convert.ToByte(fGreen * (float)PixelMax);
        result.B = Convert.ToByte(fBlue * (float)PixelMax);

        return(result);
    }
コード例 #2
0
    void Update()
    {
        capture = device.GetCapture();

        Image depthImage          = capture.Depth.Reference();
        Image colorizedDepthImage = DepthPixelColorizer.ColorizeDepthImage(depthImage, StaticImageProperties.GetDepthModeRange(device.CurrentDepthMode));

        depthImageBytes = colorizedDepthImage.Memory.ToArray();

        Texture2D depthImageTex2D =
            new Texture2D(depthImageWidth, depthImageHeight, TextureFormat.BGRA32, false);

        depthImageTex2D.wrapMode   = TextureWrapMode.Clamp;
        depthImageTex2D.filterMode = FilterMode.Point;

        depthImageTex2D.LoadRawTextureData(depthImageBytes);
        depthImageTex2D.Apply();
        depthImagePlane.GetComponent <Renderer>().material.mainTexture = depthImageTex2D;
    }