LoginSignup
10
9

More than 5 years have passed since last update.

HoloLensでOpenCV その1 ことはじめ #アセットアドカレ

Posted at

はじめに

この記事は Unity Assets Advent Calendar 2016 8日目の記事になります。

本日はHoloLensにも対応しているOpenCVをUnityで使えるアセットをご紹介します。
OpenCVについては過去記事のこちらをご参照ください。

Telepathy Jumperアプリを作る OpenCV for Unity #アセットアドカレ – develog.holo
http://2vr.jp/2015/12/05/unity-assets-telepathy-jumper_opencv-for-unity/

今回はその1と題して、OpenCV for Unityのセットアップから、HoloLensのアプリ開発では必須なHoloToolkit-Unityと同時に使うのに必要な手順を説明します。

環境

  • Unity 5.5.0f3

OpenCV for Unity 2.0.9

image

Integration Examples | OpenCV for Unity
https://enoxsoftware.com/opencvforunity/documentation/integration-examples/

HoloToolkit-Unityのインポート

についてはこちらの記事が最高です。

HoloToolkit-Unityを一発でダウンロード&インポートするエディタ拡張 - 気ままにI/O
http://kzonag.hatenablog.com/entry/2016/12/07/192228

OpenCV for Unityのインポート

OpenCV for UnityにはUWPに対応したソースがZIPで含まれているので、ストアからインポートするときはOpenCVForUnityUWP_Beta2.zipのみ選択してインポート。

image

次にOpenCVForUnityUWP_Beta2.zipの中にあるOpenCVForUnityUWP_Beta2.unitypackageをダブルクリックして全部インポート。
image

HoloToolkit-UnityとOpenCV for Unityを同時にインポートした時の問題を解消する

ここでめちゃくちゃエラーが出まくる
image

検索用
Assets/OpenCVForUnity/Samples/CamShiftSample/CamShiftSample.cs(143,9): error CS1502: The best overloaded method match for `OpenCVForUnity.RotatedRect.points(OpenCVForUnity.Point[])' has some invalid arguments
Assets/OpenCVForUnity/Samples/CamShiftSample/CamShiftSample.cs(143,17): error CS1503: Argument `#1' cannot convert `Point[]' expression to type `OpenCVForUnity.Point[]'
Assets/OpenCVForUnity/Samples/CamShiftSample/CamShiftSample.cs(189,45): error CS1729: The type `Point' does not contain a constructor that takes `2' arguments
Assets/OpenCVForUnity/Samples/CamShiftSample/CamShiftSample.cs(193,79): error CS1502: The best overloaded method match for `OpenCVForUnity.Rect.contains(OpenCVForUnity.Point)' has some invalid arguments
Assets/OpenCVForUnity/Samples/CamShiftSample/CamShiftSample.cs(202,39): error CS1540: Cannot access protected member `OpenCVForUnity.MatOfPoint.MatOfPoint(System.IntPtr)' via a qualifier of type `OpenCVForUnity.MatOfPoint'. The qualifier must be of type `OpenCVForUnitySample.CamShiftSample' or derived from it
Assets/OpenCVForUnity/Samples/CamShiftSample/CamShiftSample.cs(202,39): error CS0122: `OpenCVForUnity.MatOfPoint.MatOfPoint(System.IntPtr)' is inaccessible due to its protection level
Assets/OpenCVForUnity/Samples/CamShiftSample/CamShiftSample.cs(228,15): error CS1502: The best overloaded method match for `OpenCVForUnity.Imgproc.circle(OpenCVForUnity.Mat, OpenCVForUnity.Point, int, OpenCVForUnity.Scalar, int)' has some invalid arguments
Assets/OpenCVForUnity/Samples/CamShiftSample/CamShiftSample.cs(228,39): error CS1503: Argument `#2' cannot convert `Point' expression to type `OpenCVForUnity.Point'
Assets/OpenCVForUnity/Samples/CamShiftSample/CamShiftSample.cs(234,15): error CS1502: The best overloaded method match for `OpenCVForUnity.Imgproc.line(OpenCVForUnity.Mat, OpenCVForUnity.Point, OpenCVForUnity.Point, OpenCVForUnity.Scalar, int)' has some invalid arguments
中略
Assets/OpenCVForUnity/Samples/WebCamTextureToMatSample/WebCamTextureToMatSample.cs(94,114): error CS1503: Argument `#3' cannot convert `Point' expression to type `OpenCVForUnity.Point'

これはPointクラスHoloToolkit-ExamplesのGazeRulerのデモに含まれるコードと、OpenCV for Unityに含まれるコードで名前が被っているので起こるエラー。なので、GazeRulerをフォルダごと削除するか、namespace追加で解消しましょう。

OpenCV for Unityのセットアップ続き

学習ファイル類がAseets/OpenCVForUnity/StreamingAssetsに入っているのでAseets/StreamingAssetsに移動

次にPlayerSettingsからCapabilitiesWebCamをチェック。これでアプリからHoloLensのカメラにアクセスできるようになります。

image

これで下準備は完了。
それぞれのサンプルプロジェクトを開いて実機に転送して動かしてみましょう。
※Holographic Remoting PlayerだとPCのカメラを使うことになり、HoloLens実機のカメラでは動作してくれません。

10
9
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
10
9