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; }
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; }
/// <summary> /// Renders the received images from the zed camera /// </summary> /// <param name="msg">JSON msg containing the roboy pose.</param> private void RefreshZedImage(ImageMsg image) { //Get the image as an array from the message. byte[] image_temp = image.GetImage(); int j = 0; for (int i = 0; i < image_temp.Length; i += 3) { m_ColorArrayZed[j].b = image_temp[i] / (float)255; m_ColorArrayZed[j].g = image_temp[i + 1] / (float)255; m_ColorArrayZed[j].r = image_temp[i + 2] / (float)255; m_ColorArrayZed[j].a = 1f; j++; } // Load data into the texture. m_TexZed.SetPixels(m_ColorArrayZed); m_TexZed.Apply(); Graphics.Blit(m_TexZed, RT_Zed); }