Joint position and orientation ofxKinectForWindows2

Hi, I am trying to iterate through the joint position and orientation for each user using ofxKinectForWindows2.

I think I am getting close but the structure of the code is over my head,

my cpp has

#include "ofApp.h"
using namespace ofxKinectForWindows2;
void ofApp::setup(){
    kinect,open();
    kinect.initDepthSource();
    kinect.initColorSource();
    kinect.initInfraredSource();
    kinect.initBodyIndexSource();
}
void ofApp::update(){
    this->kinect.update();
    std::vector<Data::Body> myBodies = this->kinect.getBodySource()->getBodies();
    if(myBodies.size()>0){
        for (int i=0; i<myBodies.size() ; i++){
            
            for(auto const &it : myBodies[i].joints){
                cout<<ofTostring(it.first + " " + ofToString(it.second.getOrientation().x())<<endl:
            }
        }
    }
}

It would be great to know how to get to this. Maybe @elliotwoods can answer?

Cheers

Fred

I am also looking to do this. For some reason, when nobody is in front of the kinect, the number of bodies I get from getBodies() is 6.

I’m facing the same problem, getBodies function seems to have a initialisation phase and during this one is tracking 6 skeletons.
Does someone have any idea why ?

I’ve just come back to this for a new project and found how to do it:

    ofVec3f normalize(0.5, 0.5, 0);
    ofVec3f scale3(640, 360, 0);

    auto bodies = kinect.getBodySource()->getBodies();
    const auto & bonesDictionary = ofxKinectForWindows2::Data::Body::getBonesAtlas();
    for(auto body : bodies) {
        if (body.tracked) {

            ofVec3f handLeftPos = ( body.joints[JointType_HandLeft].getPosition() + normalize) * scale3;
            handLeftPos.y = scale3.y - handLeftPos.y;
            ofSetColor(0, 0, 255);
            ofCircle(handLeftPos.x, handLeftPos.y, 20);

            ofVec3f handRightPos = ( body.joints[JointType_HandRight].getPosition() + normalize) * scale3;
            handRightPos.y = scale3.y - handRightPos.y;
            ofSetColor(0, 255, 0);
            ofCircle(handRightPos.x, handRightPos.y, 20);

            for(auto bone : bonesDictionary) {

                ofVec3f startPos = ( body.joints[bone.first].getPosition() + normalize) * scale3;
                startPos.y = scale3.y - startPos.y;
                
                ofSetColor(0);
                ofCircle(startPos.x, startPos.y, 10);

                ofVec3f endPos = ( body.joints[bone.second].getPosition() + normalize) * scale3;
                endPos.y = scale3.y - endPos.y;

                ofSetColor(255, 0, 0);
                ofCircle(endPos.x, endPos.y, 10);
            }
        }
    }
2 Likes