Esempio n. 1
0
    public static void DisplayTexture(Texture2D texture, MatDisplaySettings properties)
    {
        MatDrawer uDispl = texDisplays[texDisplayCount++];

        uDispl.texture = texture;
        uDispl.Activate(properties);
    }
Esempio n. 2
0
    public static void DisplayMat(Mat mat, MatDisplaySettings properties)
    {
        if (!isValid)
        {
            return;
        }

        Mat uMat = PrepareMatData(mat);

        DisplayImageData(new IntPtr(uMat.dataAddr()), uMat.width(), uMat.height(), uMat.channels(), properties);
    }
Esempio n. 3
0
 public void Activate(MatDisplaySettings properties)
 {
     active          = true;
     this.properties = properties;
 }
Esempio n. 4
0
    public unsafe static void DisplayImageData(byte[] data, int width, int height, int channels, MatDisplaySettings properties)
    {
        int len = width * height * channels;

        if (channels == 1)
        {
            int cI = 0;
            for (int i = 0; i < len; i++)
            {
                byte val = data[i];
                convData[cI++] = val;
                convData[cI++] = val;
                convData[cI++] = val;
            }
            data     = convData;
            channels = 3;
        }

        fixed(byte *ptr = data)
        {
            DisplayImageData(new IntPtr(ptr), width, height, channels, properties);
        }
    }
Esempio n. 5
0
    public static unsafe void DisplayImageData(IntPtr ptr, int width, int height, int channels, MatDisplaySettings properties)
    {
        if (width * height <= 0)
        {
            throw new Exception("[MatDisplay] invalid extends: width=" + width + ", height=" + height);
        }
        if (!isValid)
        {
            return;
        }
        int len = width * height * channels;

        TextureFormat format = ChannelsToFormat(channels);

        MatDrawer uDispl = null;

        //Reuse displ
        foreach (MatDrawer displ in matDisplays)
        {
            if (!displ.active)
            {
                if (displ.texture != null && format == displ.texture.format && height == displ.texture.height && width == displ.texture.width)
                {
                    uDispl = displ;
                }
            }
        }


        if (uDispl == null)
        {
            //Find new display
            foreach (MatDrawer displ in matDisplays)
            {
                if (displ.texture == null)
                {
                    uDispl         = displ;
                    displ.texture  = new Texture2D(width, height, format, false);
                    displ.channels = channels;
                    break;
                }
            }
        }

        if (uDispl == null)
        {
            Debug.LogError("Too many mat displays");
            return;
        }

        //Update texture data
        uDispl.flipY = false;
        uDispl.texture.LoadRawTextureData(ptr, len);
        uDispl.texture.Apply();

        //Activate display for rendering
        uDispl.Activate(properties);
    }