Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question I want to see streaming camera footage in Unity HUD window.

Discussion in 'Robotics' started by Hasan-ATC, Feb 14, 2022.

  1. Hasan-ATC


    Feb 14, 2022
    void SendImage(Camera sensorCamera, string topicName)
    var oldRT =; = sensorCamera.targetTexture;

    // Copy the pixels from the GPU into a texture so we can work with them
    // For more efficiency you should reuse this texture, instead of creating and disposing them every time
    Texture2D camText = new Texture2D(sensorCamera.targetTexture.width, sensorCamera.targetTexture.height);
    camText.ReadPixels(new Rect(0, 0, sensorCamera.targetTexture.width, sensorCamera.targetTexture.height), 0, 0);
    camText.Apply(); = oldRT;

    // Encode the texture as an ImageMsg, and send to ROS
    ImageMsg imageMsg = camText.ToImageMsg();
    RosConnection.GetOrCreateInstance().Publish(topicName, message);

    When I added this code to the Message Extensions.cs file, I got the following errors:
    Do you have any solutions?

    I didn't come across any solution in the forum so I wrote it here.
    Last edited: Feb 14, 2022
  2. amanda-unity


    Unity Technologies

    May 29, 2020
    Hi @Hasan-ATC, responding to your comment on the Github issue here--for anyone wanting to chime in, feel free to respond in this thread!