Exemplo n.º 1
0
    public new static void CallBack(ROSBridgeMsg msg)
    {
        ImageMsg image = (ImageMsg)msg;

        byte[]    color_data = image.GetImage();
        int       height     = (int)image.GetHeight();
        int       width      = (int)image.GetWidth();
        int       step       = (int)image.GetRowStep();
        Texture2D tex        = new Texture2D(width, height, TextureFormat.RGB24, false);

        Color[] colors = new Color[width * height];
        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                byte  B = color_data[j * step + i * 3];
                byte  G = color_data[j * step + i * 3 + 1];
                byte  R = color_data[j * step + i * 3 + 2];
                Color c = new Color((float)R / 255.0f, (float)G / 255.0f, (float)B / 255.0f);
                colors[j * width + i] = c;
                //tex.SetPixel(i, height - j, c);
            }
        }
        tex.SetPixels(colors);
        tex.Apply();
        GameObject cam_image = GameObject.Find("CameraImage");

        cam_image.GetComponent <RawImage>().texture = tex;
    }
Exemplo n.º 2
0
    public new static void CallBack(ROSBridgeMsg msg)
    {
        ImageMsg image = (ImageMsg)msg;

        int curr = num;

        num++;
        if (verbose)
        {
            Debug.Log("Start processing " + curr);
        }

        uint width  = image.GetWidth();
        uint height = image.GetHeight();

        byte[] raw_data = image.GetImage();

        RawImage texObj = GameObject.Find(objectName).GetComponent <RawImage>();

        Texture2D tex = GameObject.Find(objectName).GetComponent <RawImage>().texture as Texture2D;

        if (tex == null)
        {
            tex            = new Texture2D((int)width / 2, (int)height / 2, TextureFormat.RGBA32, false);
            texObj.texture = tex;
        }

        NativeArray <Color32> image_data = tex.GetRawTextureData <Color32>();

        if (image_data == null || image_data.Length * 4 != raw_data.Length)
        {
            tex            = new Texture2D((int)width / 2, (int)height / 2, TextureFormat.RGBA32, false);
            texObj.texture = tex;
            image_data     = tex.GetRawTextureData <Color32>();
        }

        for (int ind = 0, o_ind = raw_data.Length - 4; ind < image_data.Length; ind += 1, o_ind -= 4)
        {
            image_data[ind] = new Color32(raw_data[o_ind + 3], (byte)((raw_data[o_ind + 1] + raw_data[o_ind + 2]) / 2), raw_data[o_ind], 255);
        }

        //tex.LoadRawTextureData(image_data);
        tex.Apply();

        if (verbose)
        {
            Debug.Log("Finish processing " + curr);
        }

        //File.WriteAllBytes(Application.dataPath + "/Captures/" + curr + ".png", tex.EncodeToPNG());
    }
    public void SetFrame(ImageMsg data, string videoPlayer)
    {
        Debug.Log(videoPlayer);
        if (videoPlayer == "")
        {
            return;
        }
        Texture2D tex = new Texture2D((int)data.GetWidth(), (int)data.GetHeight(), TextureFormat.RGB24, false);

        GameObject.Find(videoPlayer).GetComponent <RawImage>().enabled        = true;
        GameObject.Find(videoPlayer).GetComponent <RectTransform>().sizeDelta = new Vector2((int)data.GetWidth(), (int)data.GetHeight());
        tex.LoadRawTextureData(data.GetImage());
        tex.Apply();
        GameObject.Find(videoPlayer).GetComponent <RawImage>().texture = tex;
    }