Qualcomm技术论坛
直播中

张杰

8年用户 255经验值
私信 关注
[经验]

高通AR的cloud研究


首先,你需要注册free Cloud Recognition developer账号,然后在Targe Manager创建一个Cloud DataBase
https://developer.vuforia.com/targetmanager

完成后,将会给你Access Keys,在你的AR程序中用那个Client Access Keys去请求数据库,
Server Access keys用来准备和管理你的云端targets的。

你可以往Cloud DataBase添加targets,使用Target Manager--选择Add Target 并且上传图片和相应的数据文件到数据库。

当你创建完成Cloud DataBase 并且targets设置完成,你就可以将Client Access keys填入到CloudRecoBehaviour这个组建的参数里了。

你可以从Qualcomm Augmented Reality/Prefabs folder中找到CloudRecognition 这个prefab,把他拽到hierarchy面板。

然后,加入一个CloudRecoEventHandler.cs到CloudRecognition这个物体上(下面会介绍)。这将能让你捕获图片扫描结果,结果将以TargetFinder.TargetSearchResult的结构返回给你。
public struct TargetSearchResult
    {
        // name of the target
        public string TargetName;
        // system-wide unique id of the target.
        public string UniqueTargetId;
        /// width of the target (in 3D scene units)
        public float TargetSize;
        // metadata associated with this target
        public string MetaData;
        //tracking rating for this target
        /**
         *  The tracking rating represents a 5-star rating describing the
         *  suitability of this target for tracking on a scale from 0 to 5. A low
         *  tracking rating may result in poor tracking or unstable augmentation.
         */
        public byte TrackingRating;
        // pointer to native search result
        public IntPtr TargetSearchResultPtr;
   
}
要显示返回的target,你需要用一个Image Target Template,它其实就是一个ImageTarget实例,在你的场景中你将他当成虚拟物体模板。你需要做的是把这个ImageTargets拖到CloudRecoEventHandler组件上的Image Target
Template field这个参数上。


另外,你要做自己的设计的话,也可以用下面这个精简版的SimpleCloudRecoEventHandler.cs. 你需要获得的数据可以在OnNewSearchResult()方法中调用。
using System;
using UnityEngine;

///
/// This MonoBehaviour implements the Cloud Reco Event handling for this sample.
/// It registers itself at the CloudRecoBehaviour and is notified of new search results.
///

public class SimpleCloudRecoEventHandler : MonoBehaviour, ICloudRecoEventHandler
{
    #region PRIVATE_MEMBER_VARIABLES

    // CloudRecoBehaviour reference to avoid lookups
    private CloudRecoBehaviour mCloudRecoBehaviour;
    // ImageTracker reference to avoid lookups
    private ImageTracker mImageTracker;

    #endregion // PRIVATE_MEMBER_VARIABLES



    #region EXPOSED_PUBLIC_VARIABLES

    ///
    /// can be set in the Unity inspector to reference a ImageTargetBehaviour that is used for augmentations of new cloud reco results.
    ///

    public ImageTargetBehaviour ImageTargetTemplate;

    #endregion



    #region ICloudRecoEventHandler_IMPLEMENTATION

    ///
    /// called when TargetFinder has been initialized successfully
    ///

    public void OnInitialized()
    {
        // get a reference to the Image Tracker, remember it
        mImageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
    }

    ///
    /// initialization errors
    ///

    public void OnInitError(TargetFinder.InitState initError)
    {
    }

    ///
    ///  update errors
    ///

    public void OnUpdateError(TargetFinder.UpdateState updateError)
    {
    }

    ///
    /// updates to the scanning state
    ///

    public void OnStateChanged(bool scanning)
    {
    }

    ///
    /// Handles new search results
    ///

    ///
    public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
    {
        // duplicate the referenced image target
        GameObject newImageTarget = Instantiate(ImageTargetTemplate.gameObject) as GameObject;

        // enable the new result with the same ImageTargetBehaviour:
        ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, newImageTarget);

        if (imageTargetBehaviour != null)
        {
            // stop the target finder
            mCloudRecoBehaviour.CloudRecoEnabled = false;
        }
    }

    #endregion // ICloudRecoEventHandler_IMPLEMENTATION



    #region UNTIY_MONOBEHAVIOUR_METHODS

    ///
    /// register for events at the CloudRecoBehaviour
    ///

    void Start()
    {
        // register this event handler at the cloud reco behaviour
        CloudRecoBehaviour cloudRecoBehaviour = GetComponent();
        if (cloudRecoBehaviour)
        {
            cloudRecoBehaviour.RegisterEventHandler(this);
        }

        // remember cloudRecoBehaviour for later
        mCloudRecoBehaviour = cloudRecoBehaviour;
    }

    #endregion // UNTIY_MONOBEHAVIOUR_METHODS

}
这个程序将会自动调用扫描功能,你可以控制扫描状态,通过设置
CloudRecoBehaviour.CloudRecoEnabled = true || false

你不需要用ContentManager物体。那是例子中用来从服务器返回JSON数据用的。

更多回帖

发帖
×
20
完善资料,
赚取积分