Monster Hand Tracker

 

Worked on tracking monster with Heather Valez. The code for the ‘mon mon monsters’ was adapted to work with kinect. Original code here.

 

 

 

 

 
import SimpleOpenNI.*;
SimpleOpenNI context; boolean handsTrackFlag = false; PVector handVec = new PVector();

Monster [][]monsters;
int row = 10;
int col = 18;

PFont f;
boolean debugging = false;
PVector myPositionScreenCoords = new PVector(); //storage device

 

void setup() {

// size(640, 480); // strange, get drawing error in the cameraFrustum if i use P3D, in opengl there is no problem
//size(1024,768,OPENGL);

size(800,450);
frameRate(15);

f = createFont(“Helvetica”, 8);
textFont(f);
monsters = new Monster[row][col];

smooth();

for (int i = 0; i < row ; i++)
{
for (int j = 0; j < col ; j++)
{
monsters[i][j] = new Monster(new PVector( (j + 0.5) * width / col , (i + 1) * height / row, 0));
}
}

context = new SimpleOpenNI(this);
context.setMirror(false);
context.enableDepth();
//unfortunately have to track guestures to get hands
context.enableGesture();
context.enableHands();
context.addGesture(“RaiseHand”);
fill(255, 0, 0);
}
void draw() {
// update the cam
context.update();
//paint the image
image(context.depthImage(), 0, 0, width, height);
if (handsTrackFlag)
//callback – functions that notifies of an event.. like keypress, serial
//skeletal action works as a call back
{

//convert the weird kinect coordinates to screen coordinates.
context.convertRealWorldToProjective(handVec, myPositionScreenCoords);
ellipse(myPositionScreenCoords.x, myPositionScreenCoords.y, 20, 20);

// Monster Stuff

background(240,240,220);
for (int i = 0; i < row ; i++)
{
for (int j = 0; j < col ; j++)
{
Monster mon = monsters[i][j];
mon.handMoved();
mon.look(i,j);
mon.update();
mon.show();
}
}
}
}

// —————————————————————– // hand events
void onCreateHands(int handId, PVector pos, float time) {
println(“onCreateHands – handId: ” + handId + “, pos: ” + pos + “, time:” + time);
handsTrackFlag = true;
handVec = pos;
}
void onUpdateHands(int handId, PVector pos, float time) {
//println(“onUpdateHandsCb – handId: ” + handId + “, pos: ” + pos + “, time:” + time);
//store the location of the hand in a vector object
handVec = pos;
}
void onDestroyHands(int handId, float time) {
println(“onDestroyHandsCb – handId: ” + handId + “, time:” + time);
handsTrackFlag = false;
//go back to looking for the guesture that gave you hand.
context.addGesture(“RaiseHand”);
}
// —————————————————————– // gesture events
void onRecognizeGesture(String strGesture, PVector idPosition, PVector endPosition) {
println(“onRecognizeGesture – strGesture: ” + strGesture + “, idPosition: ” + idPosition + “, endPosition:” + endPosition);
//stop looking for the gesture
context.removeGesture(strGesture);
//use the location of this guesture tell you where to start tracking the hand
context.startTrackingHands(endPosition);
}
void onProgressGesture(String strGesture, PVector position, float progress) {
//println(“onProgressGesture – strGesture: ” + strGesture + “, position: ” + position + “, progress:” + progress);
}
// —————————————————————– // Keyboard event
void keyPressed() {
switch(key)
{
case ‘ ‘:
context.setMirror(!context.mirror());
break;
}
}

Comments are closed.