高通AR 的cloud研究

原文地址:https://developer.vuforia.com/forum/unity-3-extension-technical-discussion/please-explain-step-step-how-use-vuforia-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;

/// <summary>
/// This MonoBehaviour implements the Cloud Reco Event handling for this sample.
/// It registers itself at the CloudRecoBehaviour and is notified of new search results.
/// </summary>
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

    /// <summary>
    /// can be set in the Unity inspector to reference a ImageTargetBehaviour that is used for augmentations of new cloud reco results.
    /// </summary>
    public ImageTargetBehaviour ImageTargetTemplate;

    #endregion



    #region ICloudRecoEventHandler_IMPLEMENTATION

    /// <summary>
    /// called when TargetFinder has been initialized successfully
    /// </summary>
    public void OnInitialized()
    {
        // get a reference to the Image Tracker, remember it
        mImageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
    }

    /// <summary>
    /// initialization errors
    /// </summary>
    public void OnInitError(TargetFinder.InitState initError)
    {
    }

    /// <summary>
    ///  update errors
    /// </summary>
    public void OnUpdateError(TargetFinder.UpdateState updateError)
    {
    }

    /// <summary>
    /// updates to the scanning state
    /// </summary>
    public void OnStateChanged(bool scanning)
    {
    }

    /// <summary>
    /// Handles new search results
    /// </summary>
    /// <param name="targetSearchResult"></param>
    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

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

        // remember cloudRecoBehaviour for later
        mCloudRecoBehaviour = cloudRecoBehaviour;
    }

    #endregion // UNTIY_MONOBEHAVIOUR_METHODS

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

你不需要用ContentManager物体。那是例子中用来从服务器返回JSON数据用的。
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值