2016年6月23日木曜日

MATLAB and LeapMotion



A very convenient motion tracker for hand, LeapMotion.
手のトラッキングに便利なリーププモーションを紹介。


Now, you can buy it only 6200 yen by Amazon. If you get 3D position data from LeapMotion using MATLAB, download Matleap.
ホント安いですね。Kinectもですが…量産とは恐ろしい。 MATLABで位置情報を取得したい時には,以下からmatleapをダウンロードします。

Download https://github.com/jeffsp/matleap

You can easily understand the initial settings by reading Read me file, and have to install Leapmotion SDK first. Matleap contains sample m file to get position data.
Read me読めば,最初のセッティングについてとりあえずわかります。簡単です。 LeapMotionに関しては,SDKをダウンロードして下さいね。 サンプルコードも付いてくるので,あんまり困ることはないです。


LeapMotion ifself always get position data as long as it capture a hand. MATLAB fetches the data from matleap_frame function.
LeapMotion自体はマウスのように,手がある限りずっとデータを取得しています。そこから,MATLABがmatleap_frame関数でデータをとってきます。

matleap_frame.m : read position data from LeapMotion


f = matleap_frame;
% an example of data contents
% f =
%             id: 354491
%      timestamp: 2.1655e+10
%     pointables: [1x5 struct]
%          hands: [1x1 struct]

Position data of fingertips are  f.pointables.position.
指先の一データはf.pointables.positionです。以下のような感じで取り出します。

point_num = length(f.pointables);
if (~isempty(point_num))&&(point_num>0)
    for i=1:point_num
        nowpos(i,:) = f.pointables(i).position;
    end
end

As default, matleap cannot get data other than fingertips, but it seems that you can get other data by changing codes by yourself.
デフォルトでは指先の位置データしか取得できませんが,コード書き換えればその他も可能なようです。
https://community.leapmotion.com/t/matleap-only-has-pointable-information/470/4