Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions addon_config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ linux64:
ADDON_INCLUDES += /usr/include/k4a
ADDON_LIBS += /usr/lib/libk4abt.so
ADDON_LIBS += /usr/lib/x86_64-linux-gnu/libk4a.so
ADDON_LIBS += /opt/libjpeg-turbo/lib64/libturbojpeg.a

# ADDON_LIBS += /opt/libjpeg-turbo/lib64/libturbojpeg.a
ADDON_LIBS += /usr/lib/x86_64-linux-gnu/libturbojpeg.so.0
ADDON_LDFLAGS += -lk4arecord

linux:

linuxarmv6l:
Expand Down
291 changes: 95 additions & 196 deletions example-bodies/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,37 @@ void ofApp::setup()

ofLogNotice(__FUNCTION__) << "Found " << ofxAzureKinect::Device::getInstalledCount() << " installed devices.";

auto deviceSettings = ofxAzureKinect::DeviceSettings();
deviceSettings.syncImages = false;
deviceSettings.depthMode = K4A_DEPTH_MODE_NFOV_UNBINNED;
deviceSettings.updateIr = false;
deviceSettings.updateColor = false;
//deviceSettings.colorResolution = K4A_COLOR_RESOLUTION_1080P;
deviceSettings.updateWorld = true;
deviceSettings.updateVbo = false;
// Load Body Tracking Settings
auto bodyTrackingSettings = ofxAzureKinect::BodyTrackingSettings();
//bodyTrackingSettings.processingMode = K4ABT_TRACKER_PROCESSING_MODE_CPU;
bodyTrackingSettings.updateBodies = true;
if (this->kinectDevice.open(deviceSettings, bodyTrackingSettings))

// Load a recording with Body Tracking Settings
if (!streaming)
{
this->kinectDevice.startCameras();
filename = ofToDataPath("output_2d_movements.mkv");
if (!kinectDevice.open(filename, bodyTrackingSettings))
{
exit();
}
}

// Load shader.
auto shaderSettings = ofShaderSettings();
shaderSettings.shaderFiles[GL_VERTEX_SHADER] = "shaders/render.vert";
shaderSettings.shaderFiles[GL_FRAGMENT_SHADER] = "shaders/render.frag";
shaderSettings.intDefines["BODY_INDEX_MAP_BACKGROUND"] = K4ABT_BODY_INDEX_MAP_BACKGROUND;
shaderSettings.bindDefaults = true;
if (this->shader.setup(shaderSettings))
else
{
ofLogNotice(__FUNCTION__) << "Success loading shader!";
auto deviceSettings = ofxAzureKinect::DeviceSettings();
deviceSettings.syncImages = false;
deviceSettings.depthMode = K4A_DEPTH_MODE_NFOV_UNBINNED;
deviceSettings.updateIr = false;
deviceSettings.updateColor = false;
//deviceSettings.colorResolution = K4A_COLOR_RESOLUTION_1080P;
deviceSettings.updateWorld = true;
deviceSettings.updateVbo = false;

if (!kinectDevice.open(deviceSettings, bodyTrackingSettings))
{
exit();
}
}

// Setup vbo.
std::vector<glm::vec3> verts(1);
this->pointsVbo.setVertexData(verts.data(), verts.size(), GL_STATIC_DRAW);
// Start Playback or Streaming
kinectDevice.startCameras();
}

//--------------------------------------------------------------
Expand All @@ -48,228 +49,126 @@ void ofApp::exit()
//--------------------------------------------------------------
void ofApp::update()
{

}

//--------------------------------------------------------------
void ofApp::draw()
{
ofBackground(0);

if (this->kinectDevice.isStreaming())
{
this->kinectDevice.getBodyIndexTex().draw(0, 0, 360, 360);
}
ofxAzureKinect::BodyTracker *tracker = kinectDevice.get_body_tracker();

this->camera.begin();
{
ofPushMatrix();
{
ofRotateXDeg(180);

ofEnableDepthTest();
tracker->draw_body_map();

constexpr int kMaxBodies = 6;
int bodyIDs[kMaxBodies];
int i = 0;
while (i < this->kinectDevice.getNumBodies())
{
bodyIDs[i] = this->kinectDevice.getBodyIDs()[i];
++i;
}
while (i < kMaxBodies)
{
bodyIDs[i] = 0;
++i;
}
camera.begin();

this->shader.begin();
{
this->shader.setUniformTexture("uDepthTex", this->kinectDevice.getDepthTex(), 1);
this->shader.setUniformTexture("uBodyIndexTex", this->kinectDevice.getBodyIndexTex(), 2);
this->shader.setUniformTexture("uWorldTex", this->kinectDevice.getDepthToWorldTex(), 3);
this->shader.setUniform2i("uFrameSize", this->kinectDevice.getDepthTex().getWidth(), this->kinectDevice.getDepthTex().getHeight());
this->shader.setUniform1iv("uBodyIDs", bodyIDs, kMaxBodies);
ofPushMatrix();
ofRotateXDeg(180);
tracker->draw_point_clouds(kinectDevice.getDepthTex(), kinectDevice.getDepthToWorldTex());
tracker->draw_skeletons();
ofPopMatrix();

int numPoints = this->kinectDevice.getDepthTex().getWidth() * this->kinectDevice.getDepthTex().getHeight();
this->pointsVbo.drawInstanced(GL_POINTS, 0, 1, numPoints);
}
this->shader.end();
camera.end();

ofDisableDepthTest();
stringstream ss;
ss << ofToString(ofGetFrameRate(), 2) + " FPS" << std::endl;
ss << "Joint Smoothing: " << kinectDevice.get_body_tracker()->get_joint_smoothing();
ofDrawBitmapStringHighlight(ss.str(), 10, 20);
}

auto& bodySkeletons = this->kinectDevice.getBodySkeletons();
for (auto& skeleton : bodySkeletons)
//--------------------------------------------------------------
void ofApp::keyPressed(int key)
{
// handle playback hotkeys
if (!streaming)
{
switch (key)
{
case ' ':
{
play = !play;
if (play)
{
// Draw joints.
for (int i = 0; i < K4ABT_JOINT_COUNT; ++i)
{
auto joint = skeleton.joints[i];
ofPushMatrix();
{
glm::mat4 transform = glm::translate(toGlm(joint.position)) * glm::toMat4(toGlm(joint.orientation));
ofMultMatrix(transform);

ofDrawAxis(50.0f);
}
ofPopMatrix();
}

// Draw connections.
this->skeletonMesh.setMode(OF_PRIMITIVE_LINES);
auto& vertices = this->skeletonMesh.getVertices();
vertices.resize(50);
int vdx = 0;

// Spine.
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_PELVIS].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_SPINE_NAVEL].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_SPINE_NAVEL].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_SPINE_CHEST].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_SPINE_CHEST].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_NECK].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_NECK].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_HEAD].position);

// Head.
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_HEAD].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_NOSE].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_NOSE].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_EYE_LEFT].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_EYE_LEFT].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_EAR_LEFT].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_NOSE].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_EYE_RIGHT].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_EYE_RIGHT].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_EAR_RIGHT].position);

// Left Leg.
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_PELVIS].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_HIP_LEFT].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_HIP_LEFT].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_KNEE_LEFT].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_KNEE_LEFT].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_ANKLE_LEFT].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_ANKLE_LEFT].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_FOOT_LEFT].position);

// Right leg.
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_PELVIS].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_HIP_RIGHT].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_HIP_RIGHT].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_KNEE_RIGHT].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_KNEE_RIGHT].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_ANKLE_RIGHT].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_ANKLE_RIGHT].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_FOOT_RIGHT].position);

// Left arm.
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_NECK].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_CLAVICLE_LEFT].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_CLAVICLE_LEFT].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_SHOULDER_LEFT].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_SHOULDER_LEFT].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_ELBOW_LEFT].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_ELBOW_LEFT].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_WRIST_LEFT].position);

// Right arm.
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_NECK].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_CLAVICLE_RIGHT].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_CLAVICLE_RIGHT].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_SHOULDER_RIGHT].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_SHOULDER_RIGHT].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_ELBOW_RIGHT].position);

vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_ELBOW_RIGHT].position);
vertices[vdx++] = toGlm(skeleton.joints[K4ABT_JOINT_WRIST_RIGHT].position);

this->skeletonMesh.draw();
kinectDevice.play = true;
}
else
{
kinectDevice.pause = false;
}
break;
}
case '+':
play_head = ofClamp(play_head + .01, 0, 1);
kinectDevice.seek = play_head;
break;
case '-':
play_head = ofClamp(play_head - .01, 0, 1);
kinectDevice.seek = play_head;
break;
}
ofPopMatrix();
}
this->camera.end();

std::ostringstream oss;
oss << ofToString(ofGetFrameRate(), 2) + " FPS" << std::endl;
oss << "Joint Smoothing: " << this->kinectDevice.jointSmoothing;
ofDrawBitmapStringHighlight(oss.str(), 10, 20);
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){

switch (key)
{
case 'f':
case 'F':
ofToggleFullscreen();
break;
default:
break;
}
}
}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){

void ofApp::keyReleased(int key)
{
}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){

void ofApp::mouseMoved(int x, int y)
{
}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button)
{
if (button == 1)
{
this->kinectDevice.jointSmoothing = ofMap(x, 0, ofGetWidth(), 0.0f, 1.0f, true);
this->kinectDevice.get_body_tracker()->set_joint_smoothing(ofMap(x, 0, ofGetWidth(), 0.0f, 1.0f, true));
}
}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){

void ofApp::mousePressed(int x, int y, int button)
{
}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){

void ofApp::mouseReleased(int x, int y, int button)
{
}

//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){

void ofApp::mouseEntered(int x, int y)
{
}

//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){

void ofApp::mouseExited(int x, int y)
{
}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){

void ofApp::windowResized(int w, int h)
{
}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){

void ofApp::gotMessage(ofMessage msg)
{
}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
void ofApp::dragEvent(ofDragInfo dragInfo)
{
}
13 changes: 8 additions & 5 deletions example-bodies/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include "ofxAzureKinect.h"

class ofApp
: public ofBaseApp
class ofApp
: public ofBaseApp
{
public:
void setup();
Expand All @@ -31,8 +31,11 @@ class ofApp

ofEasyCam camera;

ofVbo pointsVbo;
ofShader shader;
bool streaming = true;

// Playback Params
string filename;
bool play = false;
float play_head = 0;

ofVboMesh skeletonMesh;
};
Loading