Unity 中的 ARCore 扩展图像跟踪/锚定 API [英] ARCore Extended ImageTracking / Anchoring API in Unity

查看:61
本文介绍了Unity 中的 ARCore 扩展图像跟踪/锚定 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Unity SDK 包附带的 ARCore AugmentedImage 示例应用程序在示例 AugmentedImageDatabase 中包含的示例图像周围放置了一个图片框.如果找到它们,它将在场景中的多个图像周围放置一个相框,并且只有在跟踪完全丢失时才会销毁相框.

The ARCore AugmentedImage example application that comes with the Unity SDK package places a picture frame around the sample images included in the sample AugmentedImageDatabase. It will place a picture frame around multiple images in the scene if they are found, and only destroy the picture frames once tracking is lost entirely.

假设您只想在最近识别的图像周围显示一个相框 - 并从前一个图像中删除该相框?检查给定图像的 TrackingState 无济于事,因为默认情况下跟踪已扩展而无法关闭,而且锚点 API 也不提供任何有用的信息.

Suppose you wanted to only display a picture frame around the image most recently recognized - and remove the frame from the previous image? Checking the TrackingState of a given image doesn't help since the tracking is extended by default without any way to turn off, and the anchor API doesn't offer any information that would help either.

一旦包含可跟踪图像的列表超过 1,我就会通过销毁旧会话(并创建一个新会话)来使其工作,但这会导致应用在恢复之前暂时冻结一秒钟.

I have it working by destroying the old session (and creating a new one) once the list that holds the Trackable images exceeds 1, but that leads to the app temporarily freezing up for a second before resuming.

有没有更好的方法来做这件事的建议?

Are there suggestions on a better way to do this?

推荐答案

好吧,考虑到对此 github 的回复,这不是一个确切的解决方案 issue 来自 Google 开发人员,但它解决了问题.正如我在评论中所说,TrackableQueryFilter.Updated 为您提供当前帧中更新的图像(不仅在状态方面,而且在位置等方面).因此,当我将 m_TempAugmentedImages.Count 记录 318 帧,而我的图像在我的手机视图中并被跟踪时,我的图像更新了 18 次.

Okay this is not an exact solution considering the reply to this github issue from Google developers but it solves the issue. As i said in my comments TrackableQueryFilter.Updated gives you images that are updated(not just in terms of status but position etc.) in the current frame. Therefore, when i log the m_TempAugmentedImages.Count for 318 frames while my image is in the view of my phone and being tracked, my image is updated 18 times.

由于无法知道图像何时更新并且它不经常发生,所以我想检查图像是否在 3 秒内没有更新,我可以销毁图像.为此,我将 public float TimePassed 添加到我的 AugmentedImageVisualizer 脚本中.然后在我的 AugmentedImageController 脚本中,我添加了这些行来检查会话中每个图像的 TimePassed,如下所示:

Since there is no way of knowing when image is updated and it is not happening frequently, i thought of checking if image is not updated for 3 seconds i can destroy the image. In order to do so, i added public float TimePassed to my AugmentedImageVisualizer script. Then in my AugmentedImageController script i added these lines to check TimePassed of every image that is in the Session like this:

        foreach (var visualizer in m_Visualizers.Values)
        {
            // if image is Updated TimePassed is assigned to zero for that image
            if (m_TempAugmentedImages.Count != 0 && visualizer.Image == m_TempAugmentedImages[0])
            {

                    visualizer.TimePassed = 0;

            }
            else
            {
                visualizer.TimePassed += Time.deltaTime;
            }

            if (visualizer.TimePassed > 3.0f)
            {
                Debug.Log("Destroy is called");
                m_Visualizers.Remove(visualizer.Image.DatabaseIndex);
                GameObject.Destroy(visualizer.gameObject);
            }              
        }

我构建了它,这样您就可以返回到之前跟踪的图像,如果您不满意大约 3 秒,您也可以降低它.祝你好运

I built it and this way you can go back to images which are tracked before and if you are not happy about 3 seconds you can lower it as well. Good luck

这篇关于Unity 中的 ARCore 扩展图像跟踪/锚定 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆