0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ofxKinectForWindows2 を使ってBoneで遊ぶ

Last updated at Posted at 2018-07-18

今更Kinect使い始めたのでBoneやJointの情報を使ってなんかやりたい時のメモ。

ofxKinectForWindows2のインポートの方法はこちらの記事を参考にしました。
https://qiita.com/YuYuYuYoYoYo/items/b97feda35a62eba8ec7a

##単体のJointの情報を使って何かしたい時
JointType_〇〇という定数をjointsのindexに渡してあげて取得する。

###ofApp.cpp

void ofApp::update(){
    auto bodies = kinect.getBodySource()->getBodies();
    for (auto body : bodies) {
        if (!body.tracked) continue;
        ofVec3f neckRotation = body.joints[JointType_Neck].getOrientation().getEuler(); //首の回転取得
    }
}

##複数のJointの情報を使って何かしたい時
全身のJointを使って複雑な処理をしたい場合はswitchで処理してやると比較的楽かも。以下は例。
###ofApp.cpp

void ofApp::update(){
    auto bodies = kinect.getBodySource()->getBodies();
    for (auto body : bodies) {
        if (!body.tracked) continue;
        ofVec3f handRightPos //右手の位置;
        ofVec3f handLeftPos; //左手の位置;
        ofVec3f shoulderRightPos; //右肩の位置;
        ofVec3f shoulderLeftPos; //左肩の位置;
        for (auto joint : body.joints) {
            TrackingState state = joint.second.getTrackingState();
            if (state == TrackingState_NotTracked) continue;
            switch (joint.second.getType()) {
                case JointType_HandRight:
                    handRightPos = joint.second.getPosition();
                    break;
                case JointType_HandLeft:
                    handLeftPos = joint.second.getPosition();
                    break;
                case JointType_ShoulderRight:
                    shoulderRightPos = joint.second.getPosition();
                    break;
                case JointType_ShoulderLeft:
                    shoulderLeftPos = joint.second.getPosition();
                    break;
                //省略~~
            }
        }
    }
}

あとはそれぞれのJoint間の相対位置などからポーズ認識するだけ。
ちなみにJointの定数のリストはvvvvのDocumentationのものが分かりやすかったので貼っておきます。
https://vvvv.org/documentation/kinect

Kinect for Azure楽しみっすね

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?