LoginSignup
0
0

HoloLens 2でVuforiaを使い物体の移動に追従させる

Posted at

はじめに

HoloLens2を用いた物体検出をマーカーで実装しようと思い始めた.
結局うまくいっていないが,調べたことなどを記しておく.

動作確認できていない

前提

環境

項目
OS Windows 11
Unity 2020.3.44f1, 2021.3f1
デバイス HoloLens 2
Visual Studio 2022
MRTK 2.8.3
Vufolia Vuforia Engine 10.19

手順

1. Vuforiaのセットアップ

  • Vuforia Developer Portalにログインし,Target Managerへ移動し「Add Database」する.
  • データの保存先を選択できるので今回はDeeviceを選択する.

image.png

  • Add Target から画像を追加.
  • 今回はいらすとやでゴーグルの画像をダウンロードした.
  • 画像の例だとpngだが,透過画像だとエラーを出されるのでペイントアプリでjpgに変換した.

image.png

  • Licence ManagerでGet Basicからライセンスを取得する.
  • 今回は「HoloLesMarkerTest」という名前で作成した.
  • 後で表示された文字列を使用する.

image.png

2. Unity

プロジェクトのセットアップ

  • プロジェクトを作成.

image.png

  • Vuforia Engine, MRTK からunitypackageをダウンロード
  • Assets / Immport Package / Custom Package... からインポートする

MRTK

  • MRTKの画面が出たらApplyを押す.
  • 画面はエディター上部のMixed Reality Toolkit / Utilities / Configure Unity Projectで出せる.
  • Build Settings でPlatformを以下のように設定する.
  • error CS8124: Tuple must contain at least two elements.が表示された場合は以下のように修正する.
public UnityEvent OnTargetFound = new();
public UnityEvent OnTargetLost = new();

public UnityEvent OnTargetFound = new UnityEvent();
public UnityEvent OnTargetLost = new UnityEvent();

image.png

Vuforia.

  • メニューからWindow / Vuforia Configration
  • 先ほど取得したライセンス文字列を入力する.

image.png

作りこみ

  • Mixed Reality Toolkit / Add to Scene And Configure..
  • Image Targetの作成

image.png

  • 以下のように設定.
項目
Type From Database
Database 作成したデータベース
ImageTarget 作成したターゲット
  • パッケージをインポート.
  • Target ManagerからDownload Databaseでダウンロードできる.

image.png

image.png

  • マーカー認識時に表示したいオブジェクトを作成し,Image Targetの子オブジェクトにする.

  • MixedRealityPlayspaceの子にあるMain Cameraに以下のコンポーネントを追加.

  • Vuforia BehaviourDefault Initialization Error Handler

  • PackageManagerから以下をインポート(Packages: Unity Registryにしないと表示されない).

  • Windows XR PluginXR Plugin Management

image.png

  • Edit / Project SettingsからXR Plug-in ManagementWindows Mixed Realityにチェック

image.png

  • Player Settings / Player / Publish Settings / CapbilitiesのWebCamにチェックを入れる

image.png

ビルド

  • Add Open Scenesでシーンを追加.
  • ビルドする.

エラー解決

ConsoleにMRTKのエラーが出ている場合

image.png

image.png
image.png

Refeence rewriter

  • 以下のエラーが発生
Reference Rewriter found some errors while running with command "--target=Temp\StagingArea\Data\Managed\Microsoft.MixedReality.Toolkit.Async.dll"
Reference rewriter: Error: method `System.Boolean UnityEngine.Texture2D::Reinitialize(System.Int32,System.Int32,UnityEngine.TextureFormat,System.Boolean)` doesn't exist in target framework. It is referenced from Vuforia.Unity.Engine.dll at System.Void Vuforia.Image::ResizeTexture(UnityEngine.Texture2D,System.Int32,System.Int32,UnityEngine.TextureFormat).

アプリ起動後に落ちる

試したこと

  • Open XRに切り替えたらビルドできた
  • 白い画面がずっと表示される
  • Windows Mixed Realityに戻す
  • Build時のアーキテクチャをARM64に変更
  • Visual StudioでARM64にしてビルド
  • また落ちるようになる
  • ログを見る
Windows Mixed Reality specific camera code has been moved into Windows Mixed Reality Camera Settings. Please ensure you have this added under your Camera System's Settings Providers, as this deprecated code path may be removed in a future update.
  • このサイトに行きつく.
  • ログにエラーがないが落ちる.
  • unityのversionを2021.3.33f1iに変えてみる.
  • Assetsをreimport allする.
  • プロジェクトの作り直し,バージョン変更など行ったが気づけば研究室に籠ること時刻は午前三時.
  • 萎えたので帰ります.

その他のエラー解決

おわりに

他の人のプロジェクトをクローンするのが早いのかもしれません.
それをやっても自分の環境では正常に動作しませんでした.
多分どこか間違えているのだろうけど頭が回らないので別日にリトライします.

動作確認プロジェクト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0