LoginSignup
26
26

More than 5 years have passed since last update.

PythonでLeapMotionを使ってみる

Posted at

LeapMotionという小型のジェスチャ操作デバイスを買って、pythonで動かしてみました。
私の環境がubuntu12.04なので、それ用のSDKをdeveloperサイトから取得してきます。(ユーザ登録が必要です)
ダウンロードしたファイルを解凍すると中にLeapSDKというフォルダがあるのでその中のlibに入っている以下のファイルがpythonで動かすのに必要なファイルになります。

  • Leap.py
  • libLeap.so
  • LeapPython.so

3次元表示にはVPythonというモジュールを使いました。
以下が今回作成した簡易ビューアです。

finger_viz.py
#!/usr/bin/python
#coding:utf-8
from visual import *
import Leap

scene = display(title='Leap Motion Example',
                x = 0, y = 0, width = 600, height = 600,
                center = (5, 0, 0), background = (0, 1, 1),
                visible = True,
                scale = (0.005, 0.005, 0.005),
                autoscale = False)
balls = [sphere(radius=10, color=color.red, visible=False) for _ in range(10)]
controller = Leap.Controller()

while True:
    rate(100)
    f = controller.frame()
    for idx, ball in enumerate(balls):
        if idx < len(f.fingers):
            ball.visible = True
            ball.pos = (f.fingers[idx].tip_position.x,
                        f.fingers[idx].tip_position.y,
                        f.fingers[idx].tip_position.z)
        else:
            ball.visible = False

実際の表示画面はこんな感じです。
かなりシンプルで指先のみの表示になっています。
finger_viz.png
面白いデバイスなので、ゲーム、音楽とか3Dモデリングなどいろいろと使えそうな感じです。

26
26
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
26
26