目次

はじめに

Dlib FaceLandmark Detector という顔器官を検出するライブラリがあります。OpenCV のラッパーパッケージ無しに webcam からの画像の読み込み、顔検出ができます。(WebCamTextureExample)

サンプルの実行手順と私の場合は嵌りがあったのでここにメモとして残しておきます。

WebCamTextureExample 実行手順

  1. Dlib FaceLandmark Detector をプロジェクトにインポートします。
  2. Tools -> Dlib FaceLandmark Detector -> Set Plugin Import Settings をクリック
  3. Assets/DlibFaceLandmarkDetector/StreamingAssets を Assets にドラッグドロップします。
  4. Assets/DlibFaceLandmarkDetector 配下にある全ての .unity を Build 対象に追加します。
  5. 後は Play すればサンプルの実行ができます。

複数の webcam が接続されている場合の注意

複数 webcam (Facerig 等の仮想デバイス含む)が接続されており、かつ全ての webcam が ( WebCamTexture.devices [cameraIndex].isFrontFacing == shouldUseFrontCamera ) = false の場合、カメラインデックス 0 が常に選択される点に注意が必要です。

私の場合それが xsplit virtual streaming device になっていて実際に接続されている webcam の画像が出ませんでした。

サンプルでは isFrontFacing = false なカメラを利用可能と判定していますが Logicool HD Webcam C615 は isFrontFacing = true です。なので webcam が 1 台のみの場合はメンバの shouldUseFrontCamera = true にすると良いでしょう。

因みに複数台 webcam がある場合はカメラ変更がうまくいかないので 下記のように書き換えて使用する webcam を固定しました。

WebCamTextureExample.cs #118 付近

- if (WebCamTexture.devices [cameraIndex].isFrontFacing == shouldUseFrontCamera)
+ if(WebCamTexture.devices[cameraIndex].name == "Logicool HD Webcam C615")