thorey
thorey

Reputation: 63

Saving Tango camera data as an image

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?

Upvotes: 0

Views: 495

Answers (1)

midnightcoffee
midnightcoffee

Reputation: 85

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).

Upvotes: 1

Related Questions