0

I'd like to save the camera data from the Tango camera as an image file. I'm not sure where to start, the closest question I could find is this: Getting Tango's camera stream data

Other questions+answers look like they are out of date.

Is this applicable to me? Or can I just get the texture from ITangoCameraTexture and save that as a image file?

Also is there a way to set the frame rate of the Tango camera?

thorey
  • 63
  • 7

1 Answers1

1

Your script should inherit ITangoVideoOverlay and implement OnTangoImageAvailableEventHandler where the image is stored under TangoUnityImageData imageBuffer as a byte array (imageBuffer.data). The image is in YUV format so you will have to convert it to RGB or some another format.

private void SaveImage(byte[] byteArray, string datetime)
{
    ...
    TextureFormat format = TextureFormat.RGBA32;
    Texture2D x = new Texture2D(1920, 1080, format, false);
    Color32[] argbArray = ColorHelper.YUV_NV21_TO_RGB(byteArray, 1920, 1080);
    x.SetPixels32(argbArray);
    File.WriteAllBytes(PATH + datetime + "_image.jpg", x.EncodeToJPG());
    ...
}

Of course, size shouldn't be hard coded but this is just work in progress (imageBuffer has values for width and height).

  • Am I doing this right? The textbox text never changes and I want to make sure I'm actually getting the data. `public class GetCameraFrame : MonoBehaviour, ITangoVideoOverlay { public byte[] data; public UnityEngine.UI.Text textbox; public void OnTangoImageAvailableEventHandler(Tango.TangoEnums.TangoCameraId cameraId, Tango.TangoUnityImageData imageBuffer) { data = imageBuffer.data; textbox.text = data.ToString (); } }` – thorey Aug 01 '17 at 18:44
  • I figured it out, forgot to register to the tango application in Start() – thorey Aug 01 '17 at 19:36
  • Where is this function defined ColorHelper.YUV_NV21_TO_RGB ? – Michael T Dec 12 '17 at 08:47
  • If I remember correctly, I used this one: https://stackoverflow.com/questions/12469730/confusion-on-yuv-nv21-conversion-to-rgb – midnightcoffee Dec 12 '17 at 11:44