Vuforia SDK中如何获取每一帧图片数据(byte[])
1、最近在Unity3d使用Vuforia进行AR开发,做Android开发的时候,在Android中对相机中的每一帧进行处理的时候,可以使用Camera的回调函数,public void onPreviewFrame(byte[] data, Camera camera)来实现获取每一帧图像的数据,以byte数组的方式进行图形图像的处理,现在在Unity3d中,使用Vuforia的SDK进行开发,第一件事就是想到如何获取每一帧的数据,然后进行处理,在对Vuforia有个简单的了解后,查阅了一些资料,得到了Vuforia中每一帧数据的接口,现在分享给大家。废话不说了,上代码:
public class getByte : MonoBehaviour {
private Texture2D text;
private byte[] buff = null; //得到每一帧数据的byte数组
private float width; //每一帧图像的宽度
private float height; //每一帧图像的高度
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Vuforia.VuforiaRenderer.Instance != null){
if(Vuforia.VuforiaRenderer.Instance.VideoBackgroundTexture != null){
text = (Texture2D)Vuforia.VuforiaRenderer.Instance.VideoBackgroundTexture;
buff = text.GetRawTextureData();
width = text.width;
height = text.height;
Debug.Log("---length :" + buff.Length + " w :"+ width +" h :"+height);
}
}
}
}
3、以上就是Vuforia的SDK中打开相机后得到每一帧数据的方法,希望对大家有帮助。