小编San*_*ada的帖子

无法将文件/图像设置为对象跟踪器的 RunTimeImageSource

我正在尝试在运行时动态创建图像目标。为此,我从 vuforia AR 相机捕获屏幕并将其保存在 Application.persistentDataPath 中。然后,我按照如何在 Unity 中创建和加载目标中提供的脚本创建数据集可跟踪行为。
我的捕获屏幕的代码:

            var datapath = Application.persistentDataPath;
            
            datapath = Path.Combine(datapath, "image.jpg");
        
            int width = Screen.width;
            int height = Screen.height;
            Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);

            // Read screen contents into the texture
            tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
            tex.Apply();
            byte[] bytes = tex.EncodeToJPG();

            File.WriteAllBytes(datapath, bytes);
Run Code Online (Sandbox Code Playgroud)

创建可跟踪行为的代码:


            var objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
            var runtimeImageSource = objectTracker.RuntimeImageSource;
            //Problem here
            bool result = runtimeImageSource.SetFile(VuforiaUnity.StorageType.STORAGE_ABSOLUTE, datapath, 0.15f, "Temp");
            // create a new dataset and …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine augmented-reality vuforia

5
推荐指数
1
解决办法
502
查看次数