在 vuforia 7.5.20 中启用跟踪不适用于多个云目标图像

Enable tracking not working for more than one cloud target image in vuforia 7.5.20

更新

I've checked with the different version of unity, it is working with Unity 2018.2.6f1 Personal which is installed on another laptop. But I've Unity 2018.2.12f1 Personal which gives the error. Is it a unity error?


我正在使用 vuforia 的基本 免费计划 并使用 vuforia 进行云识别。云识别部分工作正常,可跟踪的处理程序也打印云识别的图像名称。但是当我尝试启用跟踪图像目标时,它只适用于第一张图像。在第一个之后,它给出了以下错误:

TargetSearchResult cloud-image-name could not be enabled for tracking. UnityEngine.Debug:LogError(Object) Vuforia.TargetFinder:EnableTracking(TargetSearchResult, GameObject) CloudRec:OnNewSearchResult(TargetSearchResult) (at Assets/Scripts/CloudRec.cs:66) Vuforia.ObjectRecoBehaviour:Update()

以上错误表明以下行是问题所在:

m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)m_ObjectTracker.TargetFinder.EnableTracking(targetSearchResult, ImageTargetTemplate.gameObject);

技术版本:

Vuforia 版本:7.5.20 | Unity 2018.2.12f1 个人版

完整代码在这里:

public class CloudRec : MonoBehaviour, ICloudRecoEventHandler
{

  private CloudRecoBehaviour mCloudRecoBehaviour;
  private bool mIsScanning = false;
  private string mTargetMetadata = "";
  public ImageTargetBehaviour ImageTargetTemplate;
  ObjectTracker m_ObjectTracker;
  TargetFinder m_TargetFinder;


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

  public void OnInitialized()
  {
      m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
      Debug.Log("Cloud Reco initialized");
  }
  public void OnInitError(TargetFinder.InitState initError)
  {
    Debug.Log("Cloud Reco init error " + initError.ToString());
  }
  public void OnUpdateError(TargetFinder.UpdateState updateError)
  {
      Debug.Log("Cloud Reco update error " + updateError.ToString());
  }

  public void OnStateChanged(bool scanning)
  {
      mIsScanning = scanning;
      if (scanning)
      {
        // clear all known trackables
          ObjectTracker tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
          tracker.TargetFinder.ClearTrackables(false);
      }
  }

  // Here we handle a cloud target recognition event
  public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
  {
      GameObject newImageTarget = Instantiate(ImageTargetTemplate.gameObject) as GameObject;
      GameObject augmentation = null;

      if (augmentation != null)
          augmentation.transform.SetParent(newImageTarget.transform);
      if (ImageTargetTemplate)
      {
          m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
          ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)m_ObjectTracker.TargetFinder.EnableTracking(targetSearchResult, ImageTargetTemplate.gameObject);


          //ImageTracker imageTracker = TrackerManager.Instance.GetTracker<ImageTracker>();
          //ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)imageTracker.TargetFinder.EnableTracking(targetSearchResult, newImageTarget);

      }
      if (mIsScanning)
      {
          mCloudRecoBehaviour.CloudRecoEnabled = true;
      }

  }

  // Update is called once per frame
  void Update()
  {

  }

  public void OnInitialized(TargetFinder targetFinder)
  {
      m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
      m_TargetFinder = targetFinder;
  }
}

经过将近一周的搜索,我找到了错误原因。当 运行 unity 发生错误但是当我构建到 AndroidiOS 它工作正常.所以停止对代码的怀疑,这让我跳出了框框。所以我决定用相同的 machine 在各种版本的 unity 和 vuforia 上进行测试。它无助于克服错误。最终,我用其他 machines 进行了测试,并找到了错误原因。这是因为硬件兼容性。

就我而言,我使用的是 mac pro-2009 mid,它不支持 ObjectTracking 但我使用相同的代码和相同的版本进行了测试MacBook Air 2017Mac Pro 2014 年中 的技术运行良好。所以我断定这是一个硬件兼容性问题!