kinect=003=skeleton tracking 3d

76
KINECT Skeleton Tracking 3D 03

Upload: gary-chang

Post on 28-Mar-2016

225 views

Category:

Documents


2 download

DESCRIPTION

Kinect Skeleton Tracking

TRANSCRIPT

Page 1: Kinect=003=skeleton tracking 3d

KINECTSkeleton Tracking

3D

03

Page 2: Kinect=003=skeleton tracking 3d

READY for 3D?

Page 3: Kinect=003=skeleton tracking 3d

Let’s Start with

Looking at the Example.

Page 4: Kinect=003=skeleton tracking 3d

Open this example to check

Page 5: Kinect=003=skeleton tracking 3d

Run the Code!

Page 6: Kinect=003=skeleton tracking 3d

Camera

You

You can pressed your keyboard

“up, down, right, left” to change

the angle.

Page 7: Kinect=003=skeleton tracking 3d

But I would like to use

“peasyCam” instead.

Page 8: Kinect=003=skeleton tracking 3d

Let’s try to clean up

the code, first.

Page 9: Kinect=003=skeleton tracking 3d

/* --------------------------------------------------------------------------

* SimpleOpenNI User3d Test

* --------------------------------------------------------------------------

* Processing Wrapper for the OpenNI/Kinect 2 library

* http://code.google.com/p/simple-openni

* --------------------------------------------------------------------------

* prog: Max Rheiner / Interaction Design / Zhdk / http://iad.zhdk.ch/

* date: 12/12/2012 (m/d/y)

* ----------------------------------------------------------------------------

*/

import SimpleOpenNI.*;

SimpleOpenNI context;

float zoomF =0.5f;

float rotX = radians(180); // by default rotate the hole scene 180deg around the x-

axis,

// the data from openni comes upside down

float rotY = radians(0);

boolean autoCalib=true;

PVector bodyCenter = new PVector();

PVector bodyDir = new PVector();

PVector com = new PVector();

PVector com2d = new PVector();

color[] userClr = new color[]{ color(255,0,0),

color(0,255,0),

color(0,0,255),

color(255,255,0),

color(255,0,255),

color(0,255,255)

};

Delete the description.

Delete the rotation part.

***before setup();

Page 10: Kinect=003=skeleton tracking 3d

import SimpleOpenNI.*;

SimpleOpenNI context;

PVector bodyCenter = new PVector();

PVector bodyDir = new PVector();

PVector com = new PVector();

PVector com2d = new PVector();

color[] userClr = new color[]{ color(255,0,0),

color(0,255,0),

color(0,0,255),

color(255,255,0),

color(255,0,255),

color(0,255,255)

};

Yes, it’s like this

***before setup();

Page 11: Kinect=003=skeleton tracking 3d

void setup(){size(1024,768,P3D);

context = new SimpleOpenNI(this);

if(context.isInit() == false)

{

println("Can't init SimpleOpenNI, maybe the camera is not connected!");

exit();

return;

}

// disable mirror

context.setMirror(false);

// enable depthMap generation

context.enableDepth();

// enable skeleton generation for all joints

context.enableUser();

stroke(255,255,255);

smooth();

perspective(radians(45),

float(width)/float(height),

10,150000);

}

For the setup();

Only need to delete these lines.

***setup();

Page 12: Kinect=003=skeleton tracking 3d

void setup(){size(1024,768,P3D);

context = new SimpleOpenNI(this);

if(context.isInit() == false)

{

println("Can't init SimpleOpenNI, maybe the camera is not connected!");

exit();

return;

}

// disable mirror

context.setMirror(false);

// enable depthMap generation

context.enableDepth();

// enable skeleton generation for all joints

context.enableUser();

stroke(255,255,255);

smooth();

}

Like this

***before setup();

Page 13: Kinect=003=skeleton tracking 3d

void draw(){// update the cam

context.update();

background(0,0,0);

// set the scene pos

translate(width/2, height/2, 0);

rotateX(rotX);

rotateY(rotY);

scale(zoomF);

int[] depthMap = context.depthMap();

int[] userMap = context.userMap();

int steps = 3; // to speed up the drawing, draw every third point

int index;

PVector realWorldPoint;

translate(0,0,-1000); // set the rotation center of the scene 1000 infront of the camera

// draw the pointcloud

beginShape(POINTS);

for(int y=0;y < context.depthHeight();y+=steps)

{

for(int x=0;x < context.depthWidth();x+=steps)

{

index = x + y * context.depthWidth();

if(depthMap[index] > 0)

{

// draw the projected point

realWorldPoint = context.depthMapRealWorld()[index];

if(userMap[index] == 0)

stroke(100);

else

stroke(userClr[ (userMap[index] - 1) % userClr.length ]);

point(realWorldPoint.x,realWorldPoint.y,realWorldPoint.z);

}

}

}

endShape();

// draw the skeleton if it's available

int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i]))

drawSkeleton(userList[i]);

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

fill(0,255,100);

text(Integer.toString(userList[i]),com.x,com.y,com.z);

}

}

// draw the kinect cam

context.drawCamFrustum();

}

Delete the default rotation parts.

No point cloud at this moment. ***draw();

Page 14: Kinect=003=skeleton tracking 3d

void draw(){// update the cam

context.update();

background(0,0,0);

// draw the skeleton if it's available

int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i])) {drawSkeleton(userList[i]);

}

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

//fill(0,255,100);

//text(Integer.toString(userList[i]),com.x,com.y,com.z);

}

}

// draw the kinect cam

context.drawCamFrustum();

}

Draw the skeleton.

Draw the Center of Mass.

Draw the Camara.

***draw();

Hide these 2 lines, VERY IMPORTANT!

Page 15: Kinect=003=skeleton tracking 3d

// draw the skeleton with the selected joints

void drawSkeleton(int userId){

strokeWeight(3);

// to get the 3d joint data

drawLimb(userId, SimpleOpenNI.SKEL_HEAD, SimpleOpenNI.SKEL_NECK);

drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_LEFT_SHOULDER);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_LEFT_ELBOW);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_ELBOW, SimpleOpenNI.SKEL_LEFT_HAND);

drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_RIGHT_SHOULDER);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_RIGHT_ELBOW);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW, SimpleOpenNI.SKEL_RIGHT_HAND);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_TORSO);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_TORSO);

drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_LEFT_HIP);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_HIP, SimpleOpenNI.SKEL_LEFT_KNEE);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_KNEE, SimpleOpenNI.SKEL_LEFT_FOOT);

drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_RIGHT_HIP);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP, SimpleOpenNI.SKEL_RIGHT_KNEE);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_KNEE, SimpleOpenNI.SKEL_RIGHT_FOOT);

// draw body direction

getBodyDirection(userId,bodyCenter,bodyDir);

bodyDir.mult(200); // 200mm length

bodyDir.add(bodyCenter);

stroke(255,200,200);

line(bodyCenter.x,bodyCenter.y,bodyCenter.z,

bodyDir.x ,bodyDir.y,bodyDir.z);

strokeWeight(1);

}

void drawLimb(int userId,int jointType1,int jointType2){

PVector jointPos1 = new PVector();

PVector jointPos2 = new PVector();

float confidence;

// draw the joint position

confidence = context.getJointPositionSkeleton(userId,jointType1,jointPos1);

confidence = context.getJointPositionSkeleton(userId,jointType2,jointPos2);

stroke(255,0,0,confidence * 200 + 55);

line(jointPos1.x,jointPos1.y,jointPos1.z,

jointPos2.x,jointPos2.y,jointPos2.z);

drawJointOrientation(userId,jointType1,jointPos1,50);

}

***function & event

void drawJointOrientation(int userId,int jointType,PVector pos,float length){

// draw the joint orientation

PMatrix3D orientation = new PMatrix3D();

float confidence = context.getJointOrientationSkeleton(userId,jointType,orientation);

if(confidence < 0.001f)

// nothing to draw, orientation data is useless

return;

pushMatrix();

translate(pos.x,pos.y,pos.z);

// set the local coordsys

applyMatrix(orientation);

// coordsys lines are 100mm long

// x - r

stroke(255,0,0,confidence * 200 + 55);

line(0,0,0,

length,0,0);

// y - g

stroke(0,255,0,confidence * 200 + 55);

line(0,0,0,

0,length,0);

// z - b

stroke(0,0,255,confidence * 200 + 55);

line(0,0,0,

0,0,length);

popMatrix();

}

// -----------------------------------------------------------------

// SimpleOpenNI user events

void onNewUser(SimpleOpenNI curContext,int userId)

{

println("onNewUser - userId: " + userId);

println("\tstart tracking skeleton");

context.startTrackingSkeleton(userId);

}

void onLostUser(SimpleOpenNI curContext,int userId)

{

println("onLostUser - userId: " + userId);

}

void onVisibleUser(SimpleOpenNI curContext,int userId)

{

//println("onVisibleUser - userId: " + userId);

}

We keep these.

Page 16: Kinect=003=skeleton tracking 3d

void keyPressed()

{

switch(key)

{

case ' ':

context.setMirror(!context.mirror());

break;

}

switch(keyCode)

{

case LEFT:

rotY += 0.1f;

break;

case RIGHT:

// zoom out

rotY -= 0.1f;

break;

case UP:

if(keyEvent.isShiftDown())

zoomF += 0.01f;

else

rotX += 0.1f;

break;

case DOWN:

if(keyEvent.isShiftDown())

{

zoomF -= 0.01f;

if(zoomF < 0.01)

zoomF = 0.01;

}

else

rotX -= 0.1f;

break;

}

}

void getBodyDirection(int userId,PVector centerPoint,PVector dir)

{

PVector jointL = new PVector();

PVector jointH = new PVector();

PVector jointR = new PVector();

float confidence;

// draw the joint position

confidence = context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_LEFT_SHOULDER,jointL);

confidence = context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_HEAD,jointH);

confidence = context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_RIGHT_SHOULDER,jointR);

// take the neck as the center point

confidence = context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_NECK,centerPoint);

/* // manually calc the centerPoint

PVector shoulderDist = PVector.sub(jointL,jointR);

centerPoint.set(PVector.mult(shoulderDist,.5));

centerPoint.add(jointR);

*/

PVector up = PVector.sub(jointH,centerPoint);

PVector left = PVector.sub(jointR,centerPoint);

dir.set(up.cross(left));

dir.normalize();

}

We delete this.

“Keypressed” function

***function & event

Page 17: Kinect=003=skeleton tracking 3d

Now we need to add the

peasyCam.

Page 18: Kinect=003=skeleton tracking 3d

import SimpleOpenNI.*;

import peasy.test.*;

import peasy.org.apache.commons.math.*;

import peasy.*;

import peasy.org.apache.commons.math.geometry.*;

import processing.opengl.*;

SimpleOpenNI context;

PeasyCam cam;

PVector bodyCenter = new PVector();

PVector bodyDir = new PVector();

PVector com = new PVector();

PVector com2d = new PVector();

color[] userClr = new color[]{ color(255,0,0),

color(0,255,0),

color(0,0,255),

color(255,255,0),

color(255,0,255),

color(0,255,255)

};

Yes, it’s like this

***before setup();

Page 19: Kinect=003=skeleton tracking 3d

void setup(){size(1024,768,P3D);

context = new SimpleOpenNI(this);

if(context.isInit() == false)

{

println("Can't init SimpleOpenNI, maybe the camera is not connected!");

exit();

return;

}

// disable mirror

context.setMirror(false);

// enable depthMap generation

context.enableDepth();

// enable skeleton generation for all joints

context.enableUser();

cam = new PeasyCam(this, 0, 0, 1000, 4000);

stroke(255,255,255);

smooth();

}

Set up a PeasyCam.

***setup();

Page 20: Kinect=003=skeleton tracking 3d

RUN IT!!!

Hey mom,

I am upside

down!

Page 21: Kinect=003=skeleton tracking 3d

void draw(){context.update();

background(0,0,0);

///////////////////////////////flip

pushMatrix();

scale(-1,1,1);

rotateZ(radians(180));

rotateY(radians(360));

// draw the skeleton if it's available

int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i]))

drawSkeleton(userList[i]);

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

//fill(0,255,100);

//text(Integer.toString(userList[i]),com.x,com.y,com.z);}

} ***draw();

// draw the kinect cam

context.drawCamFrustum();

popMatrix();

}

For some reason, you have to hide or delete

these 2 lines!!!!!!!!!!!!!!!!!!!!!!!!!!!

The way I fix it.

(Not guarantee that

it’s the best way)

Flip & change the Camera by rotation and scale

pair

Page 22: Kinect=003=skeleton tracking 3d

RUN IT!!!

Hey mom,

I am

BACK!

I would like to change

colors of my skeleton.

Page 23: Kinect=003=skeleton tracking 3d

void drawLimb(int userId,int jointType1,int jointType2)

{

PVector jointPos1 = new PVector();

PVector jointPos2 = new PVector();

float confidence;

// draw the joint position

confidence = context.getJointPositionSkeleton(userId,jointType1,jointPos1);

confidence = context.getJointPositionSkeleton(userId,jointType2,jointPos2);

stroke( 0, 255, 255, confidence * 200 + 55);

line(jointPos1.x,jointPos1.y,jointPos1.z,

jointPos2.x,jointPos2.y,jointPos2.z);

drawJointOrientation(userId,jointType1,jointPos1,50);

}

Change here for your skeleton colors.

***drawLimbs()

Page 24: Kinect=003=skeleton tracking 3d

void drawJointOrientation(int userId,int jointType,PVector pos,float length)

{// draw the joint orientation

PMatrix3D orientation = new PMatrix3D();

float confidence = context.getJointOrientationSkeleton(userId,jointType,orientation);

if(confidence < 0.001f)

// nothing to draw, orientation data is useless

return;

pushMatrix();

translate(pos.x,pos.y,pos.z);

// set the local coordsys

applyMatrix(orientation);

// coordsys lines are 100mm long

// x - r

stroke(255,0,0,confidence * 200 + 55);

line(0,0,0,

length,0,0);

// y - g

stroke(0,255,0,confidence * 200 + 55);

line(0,0,0,

0,length,0);

// z - b

stroke(0,0,255,confidence * 200 + 55);

line(0,0,0,

0,0,length);

strokeWeight(10);

stroke(0, 255, 255);

point(0, 0, 0);

popMatrix();

strokeWeight(4);

}

Go here, and add these lines for drawing the joints

***drawJointOrientation

This is the strokeWeight of the limbs.

Page 25: Kinect=003=skeleton tracking 3d

limbs

RUN IT!!!

joints

I would like to change

colors of my skeleton.

Let’s

make

HEAD

Page 26: Kinect=003=skeleton tracking 3d

// draw the skeleton with the selected joints

void drawSkeleton(int userId)

{strokeWeight(3);

// to get the 3d joint data

drawLimb(userId, SimpleOpenNI.SKEL_HEAD, SimpleOpenNI.SKEL_NECK);

drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_LEFT_SHOULDER);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_LEFT_ELBOW);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_ELBOW, SimpleOpenNI.SKEL_LEFT_HAND);

drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_RIGHT_SHOULDER);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_RIGHT_ELBOW);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW, SimpleOpenNI.SKEL_RIGHT_HAND);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_TORSO);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_TORSO);

drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_LEFT_HIP);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_HIP, SimpleOpenNI.SKEL_LEFT_KNEE);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_KNEE, SimpleOpenNI.SKEL_LEFT_FOOT);

drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_RIGHT_HIP);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP, SimpleOpenNI.SKEL_RIGHT_KNEE);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_KNEE, SimpleOpenNI.SKEL_RIGHT_FOOT);

// draw body direction

getBodyDirection(userId,bodyCenter,bodyDir);

bodyDir.mult(200); // 200mm length

bodyDir.add(bodyCenter);

stroke(255,200,200);

line(bodyCenter.x,bodyCenter.y,bodyCenter.z,

bodyDir.x ,bodyDir.y,bodyDir.z);

PVector joint_HEAD = new PVector();

context.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_HEAD, joint_HEAD);

strokeWeight(50);

stroke(255);

point(joint_HEAD.x, joint_HEAD.y, joint_HEAD.z);

strokeWeight(1);

}

***drawSkeleton

Get the head

Draw the head

Page 27: Kinect=003=skeleton tracking 3d

That’s

how I

like it

to be.

Need to get a Boundary.

Page 28: Kinect=003=skeleton tracking 3d

import SimpleOpenNI.*;

import peasy.test.*;

import peasy.org.apache.commons.math.*;

import peasy.*;

import peasy.org.apache.commons.math.geometry.*;

import processing.opengl.*;

SimpleOpenNI context;

PeasyCam cam;

int boundSize = 2400;

PVector bodyCenter = new PVector();

PVector bodyDir = new PVector();

PVector com = new PVector();

PVector com2d = new PVector();

color[] userClr = new color[]{ color(255,0,0),

color(0,255,0),

color(0,0,255),

color(255,255,0),

color(255,0,255),

color(0,255,255)

};

***before setup();

Add the boundSize for

defining the boundary size

Page 29: Kinect=003=skeleton tracking 3d

void draw(){context.update();

background(0,0,0);

pushMatrix();

translate(0, 0, boundSize/2);

stroke(255, 0, 255);

noFill();

box(boundSize);

popMatrix();

pushMatrix();

scale(-1,1,1);

rotateZ(radians(180));

rotateY(radians(360));

// draw the skeleton if it's available

int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i]))

drawSkeleton(userList[i]);

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

//fill(0,255,100);

//text(Integer.toString(userList[i]),com.x,com.y,com.z);

}

}

***draw();

// draw the kinect cam

context.drawCamFrustum();

}

Page 30: Kinect=003=skeleton tracking 3d

I looks like a Giant.

Page 31: Kinect=003=skeleton tracking 3d

But my issue is while you

zoom out, you will lose

something.

SCALE the Skeleton DOWN

Page 32: Kinect=003=skeleton tracking 3d

void draw(){context.update();

background(0,0,0);

pushMatrix();

translate(0, 0, boundSize/2);

stroke(255, 0, 255);

noFill();

box(boundSize);

popMatrix();

pushMatrix();

scale(-1,1,1);

scale(0.5);rotateZ(radians(180));

rotateY(radians(360));

int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i]))

drawSkeleton(userList[i]);

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

//fill(0,255,100);

//text(Integer.toString(userList[i]),com.x,com.y,com.z);

}

} ***draw();

// draw the kinect cam

context.drawCamFrustum();

popMatrix();

}

Page 33: Kinect=003=skeleton tracking 3d

Here you go!

Add a fake ground.

Page 34: Kinect=003=skeleton tracking 3d

void draw(){context.update();

background(0,0,0);

pushMatrix();

translate(0, 0, boundSize/2);

stroke(255, 0, 255);

noFill();

box(boundSize);

popMatrix();

pushMatrix();

translate(0, boundSize/4, boundSize/2);

rotateX(PI/2);

stroke(255, 0, 255);

noFill();

rectMode(CENTER);

rect(0,0,boundSize,boundSize);

popMatrix();

***draw();

pushMatrix();

scale(-1,1,1);

scale(0.5);

rotateZ(radians(180));

rotateY(radians(360));

int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i]))

drawSkeleton(userList[i]);

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

//fill(0,255,100);

//text(Integer.toString(userList[i]),com.x,com.y,com.z);

}

}

// draw the kinect cam

context.drawCamFrustum();

popMatrix();

}

Page 35: Kinect=003=skeleton tracking 3d
Page 36: Kinect=003=skeleton tracking 3d

Save this file as

“Skeleton3D”

Page 37: Kinect=003=skeleton tracking 3d

https://vimeo.com/52096931

Let’s play some

CHINESE

RIBBON

DANCE!

Page 38: Kinect=003=skeleton tracking 3d

Hope you still remember

ArrayList();

Page 39: Kinect=003=skeleton tracking 3d

import SimpleOpenNI.*;

import peasy.test.*;

import peasy.org.apache.commons.math.*;

import peasy.*;

import peasy.org.apache.commons.math.geometry.*;

import processing.opengl.*;

SimpleOpenNI context;

PeasyCam cam;

int boundSize = 2400;

ArrayList traceR;

PVector bodyCenter = new PVector();

PVector bodyDir = new PVector();

PVector com = new PVector();

PVector com2d = new PVector();

color[] userClr = new color[]{ color(255,0,0),

color(0,255,0),

color(0,0,255),

color(255,255,0),

color(255,0,255),

color(0,255,255)

};

***before setup();

Page 40: Kinect=003=skeleton tracking 3d

void setup(){size(1024,768,P3D);

context = new SimpleOpenNI(this);

if(context.isInit() == false)

{

println("Can't init SimpleOpenNI, maybe the camera is not connected!");

exit();

return;

}

// disable mirror

context.setMirror(false);

// enable depthMap generation

context.enableDepth();

// enable skeleton generation for all joints

context.enableUser();

cam = new PeasyCam(this, 0, 0, 1000, 4000);

traceR = new ArrayList();

stroke(255,255,255);

smooth();

}

***setup();

Page 41: Kinect=003=skeleton tracking 3d

// draw the skeleton with the selected joints

void drawSkeleton(int userId){strokeWeight(3);

// to get the 3d joint data

drawLimb(userId, SimpleOpenNI.SKEL_HEAD, SimpleOpenNI.SKEL_NECK);

drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_LEFT_SHOULDER);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_LEFT_ELBOW);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_ELBOW, SimpleOpenNI.SKEL_LEFT_HAND);

drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_RIGHT_SHOULDER);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_RIGHT_ELBOW);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW, SimpleOpenNI.SKEL_RIGHT_HAND);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_TORSO);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_TORSO);

drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_LEFT_HIP);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_HIP, SimpleOpenNI.SKEL_LEFT_KNEE);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_KNEE, SimpleOpenNI.SKEL_LEFT_FOOT);

drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_RIGHT_HIP);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP, SimpleOpenNI.SKEL_RIGHT_KNEE);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_KNEE, SimpleOpenNI.SKEL_RIGHT_FOOT);

// draw body direction

getBodyDirection(userId,bodyCenter,bodyDir);

bodyDir.mult(200); // 200mm length

bodyDir.add(bodyCenter);

stroke(255,200,200);

line(bodyCenter.x,bodyCenter.y,bodyCenter.z,

bodyDir.x ,bodyDir.y,bodyDir.z);

PVector joint_HEAD = new PVector();

context.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_HEAD, joint_HEAD);

strokeWeight(50);

stroke(255);

point(joint_HEAD.x, joint_HEAD.y, joint_HEAD.z);

PVector Rhand = new PVector();

context.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, Rhand);

traceR.add(Rhand);

strokeWeight(1);

}

***drawSkeleton

Get your right hand

Put it in the “traceR” bag!

Page 42: Kinect=003=skeleton tracking 3d

void draw(){context.update();

background(0,0,0);

pushMatrix();

translate(0, 0, boundSize/2);

stroke(255, 0, 255);

noFill();

box(boundSize);

popMatrix();

pushMatrix();

translate(0, boundSize/4, boundSize/2);

rotateX(PI/2);

stroke(255, 0, 255);

noFill();

rectMode(CENTER);

rect(0,0,boundSize,boundSize);

popMatrix();

pushMatrix();scale(-1,1,1);

scale(0.5);

rotateZ(radians(180));

rotateY(radians(360));

int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i])){

drawSkeleton(userList[i]);

for(int t =0; t<traceR.size(); t++){

strokeWeight(50);

stroke(255,100);

PVector rTrace = (PVector)traceR.get(t);

pushMatrix();

translate(rTrace.x,rTrace.y,rTrace.z);

point(0,0,0);

popMatrix();

}

}

***draw();

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

//fill(0,255,100);

//text(Integer.toString(userList[i]),com.x,com.y,com.z);

}

}

// draw the kinect cam

context.drawCamFrustum();

popMatrix();

}

Page 43: Kinect=003=skeleton tracking 3d

I can make

CLOUD!!!

Page 44: Kinect=003=skeleton tracking 3d

void draw(){context.update();

background(0,0,0);

pushMatrix();

translate(0, 0, boundSize/2);

stroke(255, 0, 255);

noFill();

box(boundSize);

popMatrix();

pushMatrix();

translate(0, boundSize/4, boundSize/2);

rotateX(PI/2);

stroke(255, 0, 255);

noFill();

rectMode(CENTER);

rect(0,0,boundSize,boundSize);

popMatrix();

pushMatrix();

scale(-1,1,1);

scale(0.5);

rotateZ(radians(180));

rotateY(radians(360));

int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i])){

drawSkeleton(userList[i]);

for(int t =0; t<traceR.size(); t++){

strokeWeight(50);

//stroke(255,100);

PVector rTrace = (PVector)traceR.get(t);

float rCR = map(rTrace.x,200,2000,50,255);

float rCG = map(rTrace.y,200,2000,50,255);

float rCB = map(rTrace.z,200,2000,50,255);

stroke(rCR, rCG, rCB);

pushMatrix();

translate(rTrace.x,rTrace.y,rTrace.z);

point(0,0,0);

popMatrix();

if(t > 200){

traceR.remove(t-200);

}

}

}***draw();

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

//fill(0,255,100);

//text(Integer.toString(userList[i]),com.x,com.y,com.z);

}

}

// draw the kinect cam

context.drawCamFrustum();

popMatrix();

}

Mapping colors

If the trace number is over 200, it will start

delete from the first trace

Page 45: Kinect=003=skeleton tracking 3d

THIS IS

RIBBON

Page 46: Kinect=003=skeleton tracking 3d

Now it’s your turn to

Give me the LEFT hand

Page 47: Kinect=003=skeleton tracking 3d

import SimpleOpenNI.*;

import peasy.test.*;

import peasy.org.apache.commons.math.*;

import peasy.*;

import peasy.org.apache.commons.math.geometry.*;

import processing.opengl.*;

SimpleOpenNI context;

PeasyCam cam;

int boundSize = 2400;

ArrayList traceR;

ArrayList traceL;

PVector bodyCenter = new PVector();

PVector bodyDir = new PVector();

PVector com = new PVector();

PVector com2d = new PVector();

color[] userClr = new color[]{ color(255,0,0),

color(0,255,0),

color(0,0,255),

color(255,255,0),

color(255,0,255),

color(0,255,255)

};

***before setup();

Page 48: Kinect=003=skeleton tracking 3d

void setup(){size(1024,768,P3D);

context = new SimpleOpenNI(this);

if(context.isInit() == false)

{

println("Can't init SimpleOpenNI, maybe the camera is not connected!");

exit();

return;

}

// disable mirror

context.setMirror(false);

// enable depthMap generation

context.enableDepth();

// enable skeleton generation for all joints

context.enableUser();

cam = new PeasyCam(this, 0, 0, 1000, 4000);

traceR = new ArrayList();

traceL = new ArrayList();

stroke(255,255,255);

smooth();

}

***setup();

Page 49: Kinect=003=skeleton tracking 3d

// draw the skeleton with the selected joints

void drawSkeleton(int userId){strokeWeight(3);

// to get the 3d joint data

drawLimb(userId, SimpleOpenNI.SKEL_HEAD, SimpleOpenNI.SKEL_NECK);

drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_LEFT_SHOULDER);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_LEFT_ELBOW);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_ELBOW, SimpleOpenNI.SKEL_LEFT_HAND);

drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_RIGHT_SHOULDER);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_RIGHT_ELBOW);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW, SimpleOpenNI.SKEL_RIGHT_HAND);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_TORSO);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_TORSO);

drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_LEFT_HIP);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_HIP, SimpleOpenNI.SKEL_LEFT_KNEE);

drawLimb(userId, SimpleOpenNI.SKEL_LEFT_KNEE, SimpleOpenNI.SKEL_LEFT_FOOT);

drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_RIGHT_HIP);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP, SimpleOpenNI.SKEL_RIGHT_KNEE);

drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_KNEE, SimpleOpenNI.SKEL_RIGHT_FOOT);

// draw body direction

getBodyDirection(userId,bodyCenter,bodyDir);

bodyDir.mult(200); // 200mm length

bodyDir.add(bodyCenter);

stroke(255,200,200);

line(bodyCenter.x,bodyCenter.y,bodyCenter.z,

bodyDir.x ,bodyDir.y,bodyDir.z);

PVector joint_HEAD = new PVector();

context.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_HEAD, joint_HEAD);

strokeWeight(50);

stroke(255);

point(joint_HEAD.x, joint_HEAD.y, joint_HEAD.z);

PVector Rhand = new PVector();

context.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, Rhand);

traceR.add(Rhand);

PVector Lhand = new PVector();

context.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, Lhand);

traceL.add(Lhand);

strokeWeight(1);

}

***drawSkeleton

Page 50: Kinect=003=skeleton tracking 3d

void draw(){context.update();

background(0,0,0);

pushMatrix();

translate(0, 0, boundSize/2);

stroke(255, 0, 255);

noFill();

box(boundSize);

popMatrix();

pushMatrix();

translate(0, boundSize/4, boundSize/2);

rotateX(PI/2);

stroke(255, 0, 255);

noFill();

rectMode(CENTER);

rect(0,0,boundSize,boundSize);

popMatrix();

pushMatrix();scale(-1,1,1);

scale(0.5);

rotateZ(radians(180));

rotateY(radians(360)); int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i])){

drawSkeleton(userList[i]);

for(int t =0; t<traceR.size(); t++){

strokeWeight(50);

PVector rTrace = (PVector)traceR.get(t);

float rCR = map(rTrace.x,200,2000,50,255);

float rCG = map(rTrace.y,200,2000,50,255);

float rCB = map(rTrace.z,200,2000,50,255);

stroke(rCR, rCG, rCB);

pushMatrix();

translate(rTrace.x,rTrace.y,rTrace.z);

point(0,0,0);

popMatrix();

if(t > 200){

traceR.remove(t-200);

}

}

***draw();

for(int t =0; t<traceL.size(); t++){

strokeWeight(50);

PVector lTrace = (PVector)traceL.get(t);

float lCR = map(lTrace.x,200,2000,50,255);

float lCG = map(lTrace.y,200,2000,50,255);

float lCB = map(lTrace.z,200,2000,50,255);

stroke(lCR, lCG, lCB);

pushMatrix();

translate(lTrace.x,lTrace.y,lTrace.z);

point(0,0,0);

popMatrix();

if(t > 200){

traceL.remove(t-200);

}

}

}

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

//fill(0,255,100);

//text(Integer.toString(userList[i]),com.x,com.y,com.z);

}

}

// draw the kinect cam

context.drawCamFrustum();

popMatrix();

}

Page 51: Kinect=003=skeleton tracking 3d

ROCK

THE

RIBBON!

Page 52: Kinect=003=skeleton tracking 3d

Let’s add a

Button & Slider

Page 53: Kinect=003=skeleton tracking 3d

import controlP5.*;

import SimpleOpenNI.*;

import peasy.test.*;

import peasy.org.apache.commons.math.*;

import peasy.*;

import peasy.org.apache.commons.math.geometry.*;

import processing.opengl.*;

SimpleOpenNI context;

PeasyCam cam;

ControlP5 controlP5;

PMatrix3D currCameraMatrix;

PGraphics3D g3;

int boundSize = 2400;

ArrayList traceR;

ArrayList traceL;

PVector bodyCenter = new PVector();

PVector bodyDir = new PVector();

PVector com = new PVector();

PVector com2d = new PVector();

color[] userClr = new color[]{ color(255,0,0),

color(0,255,0),

color(0,0,255),

color(255,255,0),

color(255,0,255),

color(0,255,255)

};

***before setup();

Page 54: Kinect=003=skeleton tracking 3d

void setup(){size(1024,768,P3D);

context = new SimpleOpenNI(this);

g3 = (PGraphics3D)g;

if(context.isInit() == false)

{

println("Can't init SimpleOpenNI, maybe the camera is not connected!");

exit();

return;

}

// disable mirror

context.setMirror(false);

// enable depthMap generation

context.enableDepth();

// enable skeleton generation for all joints

context.enableUser();

cam = new PeasyCam(this, 0, 0, 1000, 4000);

traceR = new ArrayList();

traceL = new ArrayList();

initGUI();

controlP5.setAutoDraw(false);

stroke(255,255,255);

smooth();

}***setup();

We don’t have this yet.

Let’s first finish the rest of it and make one

Page 55: Kinect=003=skeleton tracking 3d

void draw(){if (controlP5.window(this).isMouseOver()) {

cam.setActive(false);

} else {

cam.setActive(true);

}

context.update();

background(0,0,0);

pushMatrix();

translate(0, 0, boundSize/2);

stroke(255, 0, 255);

noFill();

box(boundSize);

popMatrix();

pushMatrix();

translate(0, boundSize/4, boundSize/2);

rotateX(PI/2);

stroke(255, 0, 255);

noFill();

rectMode(CENTER);

rect(0,0,boundSize,boundSize);

popMatrix();

pushMatrix();scale(-1,1,1);

scale(0.5);

rotateZ(radians(180));

rotateY(radians(360));

int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i])){

drawSkeleton(userList[i]);

for(int t =0; t<traceR.size(); t++){

strokeWeight(50);

PVector rTrace = (PVector)traceR.get(t);

float rCR = map(rTrace.x,200,2000,50,255);

float rCG = map(rTrace.y,200,2000,50,255);

float rCB = map(rTrace.z,200,2000,50,255);

stroke(rCR, rCG, rCB);

pushMatrix();

translate(rTrace.x,rTrace.y,rTrace.z);

point(0,0,0);

popMatrix();

if(t > 200){

traceR.remove(t-200);

}

} ***draw();

for(int t =0; t<traceL.size(); t++){

strokeWeight(50);

PVector lTrace = (PVector)traceL.get(t);

float lCR = map(lTrace.x,200,2000,50,255);

float lCG = map(lTrace.y,200,2000,50,255);

float lCB = map(lTrace.z,200,2000,50,255);

stroke(lCR, lCG, lCB);

pushMatrix();

translate(lTrace.x,lTrace.y,lTrace.z);

point(0,0,0);

popMatrix();

if(t > 200){

traceL.remove(t-200);

}

}

}

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

//fill(0,255,100);

//text(Integer.toString(userList[i]),com.x,com.y,com.z);

}

}

// draw the kinect cam

context.drawCamFrustum();

popMatrix();

gui();

}We don’t have this yet as well

Page 56: Kinect=003=skeleton tracking 3d

void gui() {currCameraMatrix = new PMatrix3D(g3.camera);

camera();

controlP5.draw();

g3.camera = currCameraMatrix;

}

void drawSkeleton(int userId)

{

strokeWeight(5);

if(userId%5==1){

scale(1, -1, 1);//turn upside down

}

else{

scale(1, 1, 1);

}

………………………

………………

…………………

………………….

……..

}

void drawLimb(int userId, int jointType1, int jointType2)

{

……………………….

………….

……………………….

}

…………….

………………………

……..

.

…………………..

………

………………..

…….

***gui();

Put it somewhere after void draw();

I don’t want to list them all.

Page 57: Kinect=003=skeleton tracking 3d

Add A New Tag

“GUI”

Page 58: Kinect=003=skeleton tracking 3d

These are what we need to add.

A button for show/hide Ribbons.

A slider for setting up the tailSize.

Page 59: Kinect=003=skeleton tracking 3d

void initGUI(){

controlP5 = new ControlP5(this);

controlP5.addToggle("showTail",showTail,10,30,20,20).setLabel("show Tail");

controlP5.addSlider("tailSize",50,500,10,10,100,10).setLabel("tail size");

}

***initGui();

Now we need to get back to our main code,

declare and put these variables in the code

Page 60: Kinect=003=skeleton tracking 3d

import controlP5.*;

import SimpleOpenNI.*;

import peasy.test.*;

import peasy.org.apache.commons.math.*;

import peasy.*;

import peasy.org.apache.commons.math.geometry.*;

import processing.opengl.*;

SimpleOpenNI context;

PeasyCam cam;

ControlP5 controlP5;

PMatrix3D currCameraMatrix;

PGraphics3D g3;

int boundSize = 2400;

int tailSize = 100;

boolean showTail = true;

ArrayList traceR;

ArrayList traceL;

PVector bodyCenter = new PVector();

PVector bodyDir = new PVector();

PVector com = new PVector();

PVector com2d = new PVector();

color[] userClr = new color[]{ color(255,0,0),

color(0,255,0),

color(0,0,255),

color(255,255,0),

color(255,0,255),

color(0,255,255)

}; ***before setup();

Page 61: Kinect=003=skeleton tracking 3d

void draw(){if (controlP5.window(this).isMouseOver()) {

cam.setActive(false);

} else {

cam.setActive(true);

}

context.update();

background(0,0,0);

pushMatrix();

translate(0, 0, boundSize/2);

stroke(255, 0, 255);

noFill();

box(boundSize);

popMatrix();

pushMatrix();

translate(0, boundSize/4, boundSize/2);

rotateX(PI/2);

stroke(255, 0, 255);

noFill();

rectMode(CENTER);

rect(0,0,boundSize,boundSize);

popMatrix();

pushMatrix();

scale(-1,1,1);

scale(0.5);

rotateZ(radians(180));

rotateY(radians(360));

int int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i])){

drawSkeleton(userList[i]);

for(int t =0; t<traceR.size(); t++){

strokeWeight(50);

PVector rTrace = (PVector)traceR.get(t);

float rCR = map(rTrace.x,200,2000,50,255);

float rCG = map(rTrace.y,200,2000,50,255);

float rCB = map(rTrace.z,200,2000,50,255);

stroke(rCR, rCG, rCB);

pushMatrix();

translate(rTrace.x,rTrace.y,rTrace.z);

if(showTail){

point(0,0,0);

}popMatrix();

if(t > tailSize){

traceR.remove(t- tailSize);

}}

***draw();

for(int t =0; t<traceL.size(); t++){

strokeWeight(50);

PVector lTrace = (PVector)traceL.get(t);

float lCR = map(lTrace.x,200,2000,50,255);

float lCG = map(lTrace.y,200,2000,50,255);

float lCB = map(lTrace.z,200,2000,50,255);

stroke(lCR, lCG, lCB);

pushMatrix();

translate(lTrace.x,lTrace.y,lTrace.z);

if(showTail){

point(0,0,0);

}popMatrix();

if(t > tailSize){

traceL.remove(t-tailSize);

}}

}

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

//fill(0,255,100);

//text(Integer.toString(userList[i]),com.x,com.y,com.z);

}

}

// draw the kinect cam

context.drawCamFrustum();

popMatrix();

gui();

}

Page 62: Kinect=003=skeleton tracking 3d

You

Have

Controllers

Page 63: Kinect=003=skeleton tracking 3d

Finally, We can

get rid off

RIBBONS

Page 64: Kinect=003=skeleton tracking 3d

Open your “Skeleton3D”(which only has your skeleton tracking.)

We would like to make some Attraction.

Page 65: Kinect=003=skeleton tracking 3d

import SimpleOpenNI.*;

import peasy.test.*;

import peasy.org.apache.commons.math.*;

import peasy.*;

import peasy.org.apache.commons.math.geometry.*;

import processing.opengl.*;

SimpleOpenNI context;

PeasyCam cam;

int boundSize = 2400;

ArrayList grids;

PVector bodyCenter = new PVector();

PVector bodyDir = new PVector();

PVector com = new PVector();

PVector com2d = new PVector();

color[] userClr = new color[]{ color(255,0,0),

color(0,255,0),

color(0,0,255),

color(255,255,0),

color(255,0,255),

color(0,255,255)

};

***before setup();

First, I would like to show

the Grid points without

attraction effect.

Make an ArrayList embedded all the grids’ coordination.

Page 66: Kinect=003=skeleton tracking 3d

void setup(){size(1024,768,P3D);

context = new SimpleOpenNI(this);

if(context.isInit() == false)

{

println("Can't init SimpleOpenNI, maybe the camera is not connected!");

exit();

return;

}

// disable mirror

context.setMirror(false);

// enable depthMap generation

context.enableDepth();

// enable skeleton generation for all joints

context.enableUser();

cam = new PeasyCam(this, 0, 0, 1000, 4000);

grids = new ArrayList();

for(int i=-2400; i<=2400; i+=400){

for(int j=0; j<=4800; j+=400){

PVector loc = new PVector(i,0,j);

grids.add(loc);

}

}

stroke(255,255,255);

smooth();

}

***setup();

Declare the Grids ArrayList.

Put the grids data inside.

Page 67: Kinect=003=skeleton tracking 3d

void draw(){context.update();

background(0,0,0);

pushMatrix();

translate(0, 0, boundSize/2);

stroke(255, 0, 255);

noFill();

box(boundSize);

popMatrix();

pushMatrix();

translate(0, boundSize/4, boundSize/2);

rotateX(PI/2);

stroke(255, 0, 255);

noFill();

rectMode(CENTER);

rect(0,0,boundSize,boundSize);

popMatrix();

pushMatrix();

scale(-1,1,1);

scale(0.5);

rotateZ(radians(180));

rotateY(radians(360));

int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i])){

drawSkeleton(userList[i]);

for(int d=0; d<grids.size(); d++){

PVector nLoc = (PVector)grids.get(d);

stroke(255);

strokeWeight(10);

point(nLoc.x,nLoc.y,nLoc.z);

}

}

***draw();

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

//fill(0,255,100);

//text(Integer.toString(userList[i]),com.x,com.y,com.z);

}

}

// draw the kinect cam

context.drawCamFrustum();

popMatrix();

}

Display the grids data we put from setup();

Page 68: Kinect=003=skeleton tracking 3d

But the grids and

user don’t interact

with each others

So we need the

“Attraction”

Page 69: Kinect=003=skeleton tracking 3d

void draw(){context.update();

background(0,0,0);

pushMatrix();

translate(0, 0, boundSize/2);

stroke(255, 0, 255);

noFill();

box(boundSize);

popMatrix();

pushMatrix();

translate(0, boundSize/4, boundSize/2);

rotateX(PI/2);

stroke(255, 0, 255);

noFill();

rectMode(CENTER);

rect(0,0,boundSize,boundSize);

popMatrix();

pushMatrix();

scale(-1,1,1);

scale(0.5);

rotateZ(radians(180));

rotateY(radians(360));

int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i])){

drawSkeleton(userList[i]);

PVector joint_HEAD = new PVector();

context.getJointPositionSkeleton(userList[i], SimpleOpenNI.SKEL_HEAD, joint_HEAD);

PVector att = new PVector(joint_HEAD.x,joint_HEAD.y,joint_HEAD.z);

for(int d=0; d<grids.size(); d++){

PVector nLoc = (PVector)grids.get(d);

stroke(255,255,0);

strokeWeight(10);

point(nLoc.x,nLoc.y,nLoc.z);

}

} ***draw();

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

//fill(0,255,100);

//text(Integer.toString(userList[i]),com.x,com.y,com.z);

}

}

// draw the kinect cam

context.drawCamFrustum();

popMatrix();

}

Get the head coordination as a Attraction point

Page 70: Kinect=003=skeleton tracking 3d

void draw(){context.update();

background(0,0,0);

pushMatrix();

translate(0, 0, boundSize/2);

stroke(255, 0, 255);

noFill();

box(boundSize);

popMatrix();

pushMatrix();

translate(0, boundSize/4, boundSize/2);

rotateX(PI/2);

stroke(255, 0, 255);

noFill();

rectMode(CENTER);

rect(0,0,boundSize,boundSize);

popMatrix();

pushMatrix();

scale(-1,1,1);

scale(0.5);

rotateZ(radians(180));

rotateY(radians(360));

int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i])){

drawSkeleton(userList[i]);

PVector joint_HEAD = new PVector();

context.getJointPositionSkeleton(userList[i], SimpleOpenNI.SKEL_HEAD, joint_HEAD);

PVector att = new PVector(joint_HEAD.x,joint_HEAD.y,joint_HEAD.z);

for(int d=0; d<grids.size(); d++){

PVector nLoc = (PVector)grids.get(d);

stroke(255,255,0);

strokeWeight(10);

float distance = PVector.dist(nLoc,att);

point(nLoc.x,sq((distance)/100)-boundSize/2,nLoc.z);}

}

***draw();

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

//fill(0,255,100);

//text(Integer.toString(userList[i]),com.x,com.y,com.z);

}

}

// draw the kinect cam

context.drawCamFrustum();

popMatrix();

}

Calculate the distance and apply them.

and apply them.

Page 71: Kinect=003=skeleton tracking 3d
Page 72: Kinect=003=skeleton tracking 3d

void draw(){context.update();

background(0,0,0);

pushMatrix();

translate(0, 0, boundSize/2);

stroke(255, 0, 255);

noFill();

box(boundSize);

popMatrix();

pushMatrix();

translate(0, boundSize/4, boundSize/2);

rotateX(PI/2);

stroke(255, 0, 255);

noFill();

rectMode(CENTER);

rect(0,0,boundSize,boundSize);

popMatrix();

pushMatrix();

scale(-1,1,1);

scale(0.5);

rotateZ(radians(180));

rotateY(radians(360));

int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i])){

drawSkeleton(userList[i]);

PVector joint_HEAD = new PVector();

context.getJointPositionSkeleton(userList[i], SimpleOpenNI.SKEL_HEAD, joint_HEAD);

PVector att = new PVector(joint_HEAD.x,joint_HEAD.y,joint_HEAD.z);

for(int d=0; d<grids.size(); d++){

PVector nLoc = (PVector)grids.get(d);

strokeWeight(10);

float distance = PVector.dist(nLoc,att);

stroke(255,0,map(distance,0,6000,50,255));

point(nLoc.x,sq((distance)/100)-boundSize/2,nLoc.z);}

}***draw();

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

//fill(0,255,100);

//text(Integer.toString(userList[i]),com.x,com.y,com.z);

}

}

// draw the kinect cam

context.drawCamFrustum();

popMatrix();

}

Of course you can map some colors

Page 73: Kinect=003=skeleton tracking 3d
Page 74: Kinect=003=skeleton tracking 3d

void draw(){context.update();

background(0,0,0);

pushMatrix();

translate(0, 0, boundSize/2);

stroke(255, 0, 255);

noFill();

box(boundSize);

popMatrix();

pushMatrix();

translate(0, boundSize/4, boundSize/2);

rotateX(PI/2);

stroke(255, 0, 255);

noFill();

rectMode(CENTER);

rect(0,0,boundSize,boundSize);

popMatrix();

pushMatrix();

scale(-1,1,1);

scale(0.5);

rotateZ(radians(180));

rotateY(radians(360));

int[] userList = context.getUsers();

for(int i=0;i<userList.length;i++)

{

if(context.isTrackingSkeleton(userList[i])){

drawSkeleton(userList[i]);

PVector joint_HEAD = new PVector();

context.getJointPositionSkeleton(userList[i], SimpleOpenNI.SKEL_HEAD, joint_HEAD);

PVector att = new PVector(joint_HEAD.x,joint_HEAD.y,joint_HEAD.z);

for(int d=0; d<grids.size(); d++){PVector nLoc = (PVector)grids.get(d);

strokeWeight(10);

float distance = PVector.dist(nLoc,att);

stroke(255,0,map(distance,0,6000,50,255));

point(nLoc.x,sq((distance)/100)-boundSize/2,nLoc.z);

pushMatrix();

translate(0, -boundSize/2, 0);

translate(nLoc.x,nLoc.y,nLoc.z);

rotateX(PI/2);

stroke(0,255,0);

ellipse(0,0,map(distance,0,600,0,40),map(distance,0,600,0,40));

popMatrix();

}

}***draw();

// draw the center of mass

if(context.getCoM(userList[i],com))

{

stroke(100,255,0);

strokeWeight(1);

beginShape(LINES);

vertex(com.x - 15,com.y,com.z);

vertex(com.x + 15,com.y,com.z);

vertex(com.x,com.y - 15,com.z);

vertex(com.x,com.y + 15,com.z);

vertex(com.x,com.y,com.z - 15);

vertex(com.x,com.y,com.z + 15);

endShape();

//fill(0,255,100);

//text(Integer.toString(userList[i]),com.x,com.y,com.z);

}

}

// draw the kinect cam

context.drawCamFrustum();

popMatrix();

}

Of course some other patterns.

Page 75: Kinect=003=skeleton tracking 3d
Page 76: Kinect=003=skeleton tracking 3d

It’s your turn to

PLAY