LoginSignup
2
4

More than 3 years have passed since last update.

MediaPipe の Hand Tracking を mac で動かす

Last updated at Posted at 2019-12-15

すでにやっている人がたくさんいるけど、復習ということで。

環境

MacBookPro + catalina 10.15.2 + Xcode 11.3 (11C29)

準備

先に brew のインストールが必要。bazel のインストールで jdk8 を要求されるかもしれない(下のコマンドには含む)。 bazel を普通に brew install bazel すると 1.2.1 とかインストールされるけど、bazel のバージョンが 1.1.0 以降だとダメぽいので、公式の通りにする。これ後で何か弊害でそう。

$ git clone https://github.com/google/mediapipe.git
$ brew cask install homebrew/cask-versions/adoptopenjdk8
$ brew install https://raw.githubusercontent.com/bazelbuild/homebrew-tap/f8a0fa981bcb1784a0d0823e14867b844e94fb3d/Formula/bazel.rb
$ brew link bazel
$ brew install opencv@3

xcode 関係で何かエラーが出たら、以下をためしてみる (自己責任で!)。

$ sudo xcodebuild -license accept
$ sudo xcode-select -r
$ sudo xcode-select -p

Hellp World のビルド

$ export GLOG_logtostderr=1
$ bazel run --define MEDIAPIPE_DISABLE_GPU=1     mediapipe/examples/desktop/hello_world:hello_world

Hello World が 10 回表示されたら OK。

Hand Tracking のビルトと実行

https://github.com/google/mediapipe/blob/master/mediapipe/examples/desktop/README.md
上記 URL には次のコマンドでビルドできると書かれているけど、うちの環境では six module がないといわれて途中で止まった。

$ bazel build -c opt mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu --define MEDIAPIPE_DISABLE_GPU=1

six を pip3 でインストールしたらいけた。

$ pip3 install six

ビルドを通ったら下記で実行できる。

GLOG_logtostderr=1 bazel-bin/mediapipe/examples/desktop/hand_tracking/hand_tracking_cpu     --calculator_graph_config_file=mediapipe/graphs/hand_tracking/hand_tracking_desktop_live.pbtxt

5fps くらいは出てる気がする。

Multiple Hand Tracking を試す

あっさり動いた。

$ bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 \
          mediapipe/examples/desktop/multi_hand_tracking:multi_hand_tracking_cpu
$ GLOG_logtostderr=1 bazel-bin/mediapipe/examples/desktop/multi_hand_tracking/multi_hand_tracking_cpu \
--calculator_graph_config_file=mediapipe/graphs/hand_tracking/multi_hand_tracking_desktop_live.pbtxt

landmark データの検証

手と指の位置のデータ (landmark) を取得して、表示させてみたのが次の図。手ひとつについて21点の landmark を認識して、それぞれ0番から20番まで手の各ポイントに割り当てられているようだ。番号は固定で、手の各位置と対応している。x,y,z の座標データが含まれているが、z は常に 0 になっている、つまり、奥行は取れていない。

pos.png

データもシンプルで使い勝手もいいので、いろいろできそうな気がしてきた。すごいよね google の人たち。

2
4
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
2
4