## Proj 1: Simple Project

149607569
Posts: 1
Joined: Fri Apr 01, 2016 2:34 pm

### Re: Proj 1: Simple Project

Description
Here I would like to know Kinect to capture information from the human hand and the feedback data and it will print a 3D motion graphics. My idea comes from the fancy basketball. It's just a simple game.

References
Making.Things.See(2012.01).Greg.Borenstein
Screenshots
code

Code: Select all

``````/* MAT 265 Project 1: Simple Project
* SimpleOpenNI Hands3d Test/Kinect 2 library
* Date : 2016/04/12
* This demos shows how to use the gesture/hand generator.
* It's not the most reliable yet, a two hands example will follow
* ----------------------------------------------------------------------------
*/

import java.util.Map;
import java.util.Iterator;
import shapes3d.utils.*;
import shapes3d.animation.*;
import shapes3d.*;
import SimpleOpenNI.*;

Ellipsoid Ball;
SimpleOpenNI context;
int handVecListSize = 20;
Map<Integer,ArrayList<PVector>>  handPathList = new HashMap<Integer,ArrayList<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)
};
void setup()
{
size(640,480,OPENGL);

// Create the besketball
Ball = new Ellipsoid(this, 16, 16);
Ball.setTexture("Ball.jpg");
Ball.moveTo(new PVector(0, 0, 0));
Ball.strokeWeight(1.0f);
Ball.stroke(color(255, 255, 0));
Ball.moveTo(20, 40, -80);
Ball.tag = "Ball";
Ball.drawMode(Shape3D.TEXTURE);

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();

// disable mirror
context.setMirror(true);

// enable hands + gesture generation
//context.enableGesture();
context.enableHand();
context.startGesture(SimpleOpenNI.GESTURE_WAVE);

// set how smooth the hand capturing should be
//context.setSmoothingHands(.5);
}

void draw()
{
// update the cam
context.update();

image(context.depthImage(),0,0);

// draw the tracked hands
if(handPathList.size() > 0)
{
Iterator itr = handPathList.entrySet().iterator();
while(itr.hasNext())
{
Map.Entry mapEntry = (Map.Entry)itr.next();
int handId =  (Integer)mapEntry.getKey();
ArrayList<PVector> vecList = (ArrayList<PVector>)mapEntry.getValue();
PVector p;
PVector p2d = new PVector();

stroke(userClr[ (handId - 1) % userClr.length ]);
noFill();
strokeWeight(10);
Iterator itrVec = vecList.iterator();
beginShape();
//background(255);
p = (PVector) itrVec.next();

context.convertRealWorldToProjective(p,p2d);
Ball.moveTo(p2d.x,p2d.y-(150-p2d.z/25), -80);
Ball.draw();
endShape();

stroke(userClr[ (handId - 1) % userClr.length ]);
strokeWeight(4);
p = vecList.get(0);
context.convertRealWorldToProjective(p,p2d);
point(p2d.x,p2d.y);
}
}
}

// hand events
void onNewHand(SimpleOpenNI curContext,int handId,PVector pos)
{
println("onNewHand - handId: " + handId + ", pos: " + pos);
ArrayList<PVector> vecList = new ArrayList<PVector>();
handPathList.put(handId,vecList);
}
void onTrackedHand(SimpleOpenNI curContext,int handId,PVector pos)
{
println("onTrackedHand - handId: " + handId + ", pos: " + pos );
ArrayList<PVector> vecList = handPathList.get(handId);
if(vecList != null)
{
if(vecList.size() >= handVecListSize)
vecList.remove(vecList.size());
}
}

void onLostHand(SimpleOpenNI curContext,int handId)
{
println("onLostHand - handId: " + handId);
handPathList.remove(handId);
}
// gesture events
void onCompletedGesture(SimpleOpenNI curContext,int gestureType, PVector pos)
{
println("onCompletedGesture - gestureType: " + gestureType + ", pos: " + pos);

int handId = context.startTrackingHand(pos);
println("hand stracked: " + handId);
}

``````
Attachments
I am Dan W