////kinect and Processing///drawing wireframe///
in
Integration and Hardware
•
4 months ago
hi,
I just want to know if somebody can help me merge these two codes:
//////kinect hand drawing core /////
import SimpleOpenNI.*;
SimpleOpenNI kinect;
ArrayList<PVector> handPositions;
PVector currentHand;
PVector previousHand;
void setup() {
size (1280, 800);
cursor(CROSS);
background(255);
kinect = new SimpleOpenNI (this);
kinect.setMirror(true);
//enable depthMap generation
kinect.enableDepth();
//enable hands + gesture generation
kinect.enableGesture();
kinect.enableHands();
kinect.addGesture("RaiseHand");
handPositions = new ArrayList();
stroke(255,0,0,100);
strokeWeight(2.5);
}
void draw(){
kinect.update();
// image(kinect.depthImage(), 0, 0);
for (int i = 1; i < handPositions.size(); i++) {
currentHand = handPositions.get(i);
previousHand = handPositions.get(i-1);
line(previousHand.x, previousHand.y, currentHand.x, currentHand.y);
}
}
//hand events
void onCreateHands(int handId, PVector position, float time) {
kinect.convertRealWorldToProjective(position, position);
handPositions.add(position);
}
void onUpdateHands(int handId, PVector position, float time) {
kinect.convertRealWorldToProjective (position, position);
handPositions.add(position);
}
void onDestroyHands(int handId, float time) {
handPositions.clear();
kinect.addGesture("RaiseHand");
}
//gesture events
void onRecognizeGesture(String strGesture,
PVector idPosition,
PVector endPosition)
{
kinect.startTrackingHands(endPosition);
kinect.removeGesture("RaiseHand");
}
////mouse wireframe drawing code////
ArrayList hist = new ArrayList();
float joinDist = 130;
void setup() {
size(1056,706);
background(255);
}
void draw() {
}
void mouseMoved() {
stroke(0);
PVector d = new PVector(mouseX, mouseY, 0);
hist.add(0,d);
for (int p = 0; p < hist.size(); p++) {
PVector v = (PVector) hist.get(p);
float joinChance = p/hist.size() +
d.dist(v)/joinDist;
if (joinChance < random(0.4))
line(d.x, d.y, v.x, v.y);
}
}
void keyPressed() {
if (key == ' ') {
background(255);
hist.clear();
}
}
Thank you!! I still have difficulty to merge codes, still beginner!!
1