【Vuforia】010-上传识别目标图与下载识别数据

1、选择目标图

选择了一个与模型寒冰相关的图片


AIXI.jpg

2、上传图片到官网的数据库

img.png

3、查看该图片目标的识别星级

img.png

4、下载数据到本地

img.png
img.png

浏览器会下载.unitypackge的包,包名与你创建的数据集名字一样,导入unity即可。

5.在unity中选择自己的数据

img.png

6.控制模型的生成

创建脚本AR,附加在imagTagert,移除自身的,继承接口 ITrackableEventHandler

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;


public class AR : MonoBehaviour, ITrackableEventHandler
{


    protected TrackableBehaviour mTrackableBehaviour;  //声明可识别行为脚本

    public GameObject AIXIPrefab;//模型预制

    private GameObject aixi; //生成的模型


    protected virtual void Start()
    {
        mTrackableBehaviour = GetComponent();
        if (mTrackableBehaviour)
            mTrackableBehaviour.RegisterTrackableEventHandler(this);
    }

    protected virtual void OnDestroy()
    {
        if (mTrackableBehaviour)
            mTrackableBehaviour.UnregisterTrackableEventHandler(this);
    }

 


    /// 
    ///  状态的改变
    /// 
    public void OnTrackableStateChanged(
        TrackableBehaviour.Status previousStatus,
        TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED ||
            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
        {
            Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
            OnTrackingFound();
        }
        else if (previousStatus == TrackableBehaviour.Status.TRACKED &&
                 newStatus == TrackableBehaviour.Status.NOT_FOUND)
        {
            Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
            OnTrackingLost();
        }
        else
        {
            OnTrackingLost();
        }
    }


    /// 
    /// 识别到物体
    /// 
    protected virtual void OnTrackingFound()
    {
        aixi = GameObject.Instantiate(AIXIPrefab);
        aixi.transform.position = this.transform.position;
        aixi.transform.SetParent(this.transform);

       
    }


    /// 
    /// 丢失物体
    /// 
    protected virtual void OnTrackingLost()
    {
        if (aixi != null)
        {
            Destroy(aixi);
        }
       

    }
}

主要接口方法:

OnTrackableStateChanged(TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus)

你可能感兴趣的:(【Vuforia】010-上传识别目标图与下载识别数据)