Saving Tango camera data as an image

一世执手 提交于 2019-12-13 03:54:28

问题


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?


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



来源:https://stackoverflow.com/questions/45360382/saving-tango-camera-data-as-an-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!