Created
December 19, 2018 10:08
-
-
Save genekogan/98e52ae47a11eacaa0c8788e432dd0cf to your computer and use it in GitHub Desktop.
quick Processing (2.* only) sketch to send Kinect skeleton joints to Wekinator (needs SimpleOpenNI + oscP5)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -------------------------------------------------------------------------- | |
* SimpleOpenNI User 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.*; | |
import oscP5.*; | |
import netP5.*; | |
OscP5 oscP5; | |
NetAddress myRemoteLocation; | |
SimpleOpenNI context; | |
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) | |
}; | |
PVector com = new PVector(); | |
PVector com2d = new PVector(); | |
ArrayList<Integer> jointNames; | |
void setup() | |
{ | |
size(640,480); | |
context = new SimpleOpenNI(this); | |
if(context.isInit() == false) | |
{ | |
println("Can't init SimpleOpenNI, maybe the camera is not connected!"); | |
exit(); | |
return; | |
} | |
// enable depthMap generation | |
context.enableDepth(); | |
// enable skeleton generation for all joints | |
context.enableUser(); | |
background(200,0,0); | |
stroke(0,0,255); | |
strokeWeight(3); | |
smooth(); | |
oscP5 = new OscP5(this,9239); | |
myRemoteLocation = new NetAddress("127.0.0.1",6448); | |
jointNames = new ArrayList<Integer>(); | |
jointNames.add(SimpleOpenNI.SKEL_HEAD); | |
jointNames.add(SimpleOpenNI.SKEL_NECK); | |
jointNames.add(SimpleOpenNI.SKEL_LEFT_SHOULDER); | |
jointNames.add(SimpleOpenNI.SKEL_LEFT_ELBOW); | |
jointNames.add(SimpleOpenNI.SKEL_LEFT_HAND); | |
jointNames.add(SimpleOpenNI.SKEL_RIGHT_SHOULDER); | |
jointNames.add(SimpleOpenNI.SKEL_RIGHT_ELBOW); | |
jointNames.add(SimpleOpenNI.SKEL_RIGHT_HAND); | |
jointNames.add(SimpleOpenNI.SKEL_LEFT_HIP); | |
jointNames.add(SimpleOpenNI.SKEL_LEFT_KNEE); | |
jointNames.add(SimpleOpenNI.SKEL_LEFT_FOOT); | |
jointNames.add(SimpleOpenNI.SKEL_RIGHT_HIP); | |
jointNames.add(SimpleOpenNI.SKEL_RIGHT_KNEE); | |
jointNames.add(SimpleOpenNI.SKEL_RIGHT_FOOT); | |
} | |
void draw() | |
{ | |
// update the cam | |
context.update(); | |
// draw depthImageMap | |
//image(context.depthImage(),0,0); | |
image(context.userImage(),0,0); | |
// draw the skeleton if it's available | |
int[] userList = context.getUsers(); | |
if (userList.length > 0) { | |
if(context.isTrackingSkeleton(userList[0])) | |
{ | |
sendJoints(userList[0]); | |
} | |
} | |
for(int i=0;i<userList.length;i++) | |
{ | |
if(context.isTrackingSkeleton(userList[i])) | |
{ | |
stroke(userClr[ (userList[i] - 1) % userClr.length ] ); | |
drawSkeleton(userList[i]); | |
} | |
// draw the center of mass | |
if(context.getCoM(userList[i],com)) | |
{ | |
context.convertRealWorldToProjective(com,com2d); | |
stroke(100,255,0); | |
strokeWeight(1); | |
beginShape(LINES); | |
vertex(com2d.x,com2d.y - 5); | |
vertex(com2d.x,com2d.y + 5); | |
vertex(com2d.x - 5,com2d.y); | |
vertex(com2d.x + 5,com2d.y); | |
endShape(); | |
fill(0,255,100); | |
text(Integer.toString(userList[i]),com2d.x,com2d.y); | |
} | |
} | |
} | |
void sendJoints(int userId) { | |
OscMessage msg = new OscMessage("/wek/inputs"); | |
PVector torso = new PVector(); | |
context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_TORSO,torso); | |
for (int j=0; j<jointNames.size(); j++) { | |
PVector jointPos = new PVector(); | |
context.getJointPositionSkeleton(userId, jointNames.get(j), jointPos); | |
msg.add(jointPos.x-torso.x); | |
msg.add(jointPos.y-torso.y); | |
msg.add(jointPos.z-torso.z); | |
} | |
oscP5.send(msg, myRemoteLocation); | |
} | |
// draw the skeleton with the selected joints | |
void drawSkeleton(int userId) | |
{ | |
// to get the 3d joint data | |
/* | |
PVector jointPos = new PVector(); | |
context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_NECK,jointPos); | |
println(jointPos); | |
*/ | |
context.drawLimb(userId, SimpleOpenNI.SKEL_HEAD, SimpleOpenNI.SKEL_NECK); | |
context.drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_LEFT_SHOULDER); | |
context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_LEFT_ELBOW); | |
context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_ELBOW, SimpleOpenNI.SKEL_LEFT_HAND); | |
context.drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_RIGHT_SHOULDER); | |
context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_RIGHT_ELBOW); | |
context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW, SimpleOpenNI.SKEL_RIGHT_HAND); | |
context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_TORSO); | |
context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_TORSO); | |
context.drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_LEFT_HIP); | |
context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_HIP, SimpleOpenNI.SKEL_LEFT_KNEE); | |
context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_KNEE, SimpleOpenNI.SKEL_LEFT_FOOT); | |
context.drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_RIGHT_HIP); | |
context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP, SimpleOpenNI.SKEL_RIGHT_KNEE); | |
context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_KNEE, SimpleOpenNI.SKEL_RIGHT_FOOT); | |
} | |
// ----------------------------------------------------------------- | |
// SimpleOpenNI events | |
void onNewUser(SimpleOpenNI curContext, int userId) | |
{ | |
println("onNewUser - userId: " + userId); | |
println("\tstart tracking skeleton"); | |
curContext.startTrackingSkeleton(userId); | |
} | |
void onLostUser(SimpleOpenNI curContext, int userId) | |
{ | |
println("onLostUser - userId: " + userId); | |
} | |
void onVisibleUser(SimpleOpenNI curContext, int userId) | |
{ | |
//println("onVisibleUser - userId: " + userId); | |
} | |
void keyPressed() | |
{ | |
switch(key) | |
{ | |
case ' ': | |
context.setMirror(!context.mirror()); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment