Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
f9655339
f9655339's Profile
1
Posts
0
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
About kinect and processing
[0 Replies]
02-May-2012 01:12 PM
Forum:
Integration and Hardware
Hi guys.. I am a new to processing here. Recently I found two sketch one is to track hand motion and the other is a mouse pressed drawing sketch.
Does someone know how to combine these two to draw instead of using mouse but using hand capture with kinect?
Thanks u!
Hand 3d:
/* --------------------------------------------------------------------------
* SimpleOpenNI Hands3d Test
* --------------------------------------------------------------------------
* Processing Wrapper for the OpenNI/Kinect library
*
http://code.google.com/p/simple-openni
* --------------------------------------------------------------------------
* prog: Max Rheiner / Interaction Design / zhdk /
http://iad.zhdk.ch/
* date: 02/27/2011 (m/d/y)
* ----------------------------------------------------------------------------
* This demos shows how to use the gesture/hand generator.
* It's not the most reliable yet, a two hands example will follow
* ----------------------------------------------------------------------------
*/
import SimpleOpenNI.*;
//import processing.opengl.*;
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 handsTrackFlag = false;
PVector handVec = new PVector();
ArrayList handVecList = new ArrayList();
int handVecListSize = 100;
String lastGesture = "";
///////////////// other
import processing.opengl.*;
//import oscP5.*;
//import netP5.*;
//OscP5 oscP5;
//NetAddress myRemoteLocation;
boolean miden, smoothFade;
boolean xar=true;
// Sound Input Variables
float amp1, freq1, amp2, freq2, ampout, freqout;
float ElegxosAmp;
SketchLine line0, line1, line2;
float x1, y1, x2, y2;
PImage cur;
int stoixeia = 30, lineAlpha = 50;
// Color Variables
int colorL=255,strokeL, strokeValue = 20, strokeBackground = 5;
int paintCount = 0, alphaSform;
int r0,g0,b0,r1,g1,b1;
// Physics Variables
float[] x = new float[stoixeia];
float[] y = new float[stoixeia];
float[] epitaxinsiX = new float[stoixeia];
float[] epitaxinsiY = new float[stoixeia];
float[] elastikotita = new float[stoixeia];
float[] aposbesi = new float[stoixeia];
float[] deltaX = new float[stoixeia];
float[] deltaY = new float[stoixeia];
float fxMouse, fyMouse;
/////////////////////
void setup()
{
size(1024,768,P3D); // strange, get drawing error in the cameraFrustum if i use P3D, in opengl there is no problem
//size(1024,768,OPENGL);
context = new SimpleOpenNI(this);
// disable mirror
context.setMirror(false);
////////////////////////////
frameRate(240);
//oscP5 = new OscP5(this,46100); //listening
//myRemoteLocation = new NetAddress("127.0.0.1",57120); // speak to
line0 = new SketchLine(30);
line1 = new SketchLine(stoixeia);
line2 = new SketchLine(stoixeia + 1);
line0.calcType( 0.2, 0.65 );// 0.2, 0.65 writeLine
line1.calcType( 0.1, 0.65 );// 0.2, 0.65 writeLine
line2.calcType( 0.3, 0.65 );// 0.2, 0.65 writeLine
background(0);
noFill();
smooth();
// noCursor();
//cur = loadImage("cursor10black.png");
//cur.resize(8, 8);
//cursor(cur, mouseX, mouseY);
for (int i=0; i<stoixeia; i++){
elastikotita[i] = 0.2*(.07*(i+1));// 0.05 kai 0.005
aposbesi[i] = 0.55-(0.02*i);
}
/////////////////////////////
// enable depthMap generation
if(context.enableDepth() == false)
{
println("Can't open the depthMap, maybe the camera is not connected!");
exit();
return;
}
// enable hands + gesture generation
context.enableGesture();
context.enableHands();
// add focus gestures / here i do have some problems on the mac, i only recognize raiseHand ? Maybe cpu performance ?
context.addGesture("Wave");
context.addGesture("Click");
context.addGesture("RaiseHand");
// set how smooth the hand capturing should be
//context.setSmoothingHands(.5);
perspective(radians(45),
float(width)/float(height),
10.0f,150000.0f);
}
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);
// draw the 3d point depth map
int[] depthMap = context.depthMap();
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
stroke(200);
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];
point(realWorldPoint.x,realWorldPoint.y,realWorldPoint.z);
}
}
}
myLine();
noFill();
if (mousePressed == true) {
line0.calcPoints(mouseX, mouseY);
line0.render(255,0,0, lineAlpha);
line1.calcPoints(mouseX, mouseY);
line1.render(255,255,0, lineAlpha);
line2.calcPoints(mouseX, mouseY);
line2.render(255,255,255, lineAlpha);
} else {
line0.calcPoints(mouseX, mouseY);
line0.render(255,0,0, 0);
line1.calcPoints(mouseX, mouseY);
line1.render(255,255,0, 0);
line2.calcPoints(mouseX, mouseY);
line2.render(255,255,255, 0);
}
if (smoothFade) {
fill(0,12);
rect(-10,-10,width,height);
}
}
void myLine(){
if (mousePressed == true) {
if(miden == true) {
for (int i=0; i<stoixeia; i++){
x[i] = mouseX;// move worm
y[i] = mouseY;
miden = false;
}
//cursor(cur, 0,0);
}
strokeL = strokeValue;
}
noFill();
drawline();
}
void drawline(){
fxMouse = mouseX;
fyMouse = mouseY;
// beginShape();
for (int i=0; i<5; i++){
if (i==0){
deltaX[i] = (fxMouse - x[i]);
deltaY[i] = (fyMouse - y[i]);
if (mousePressed && xar) {
//OscMessage amp = new OscMessage("amp");
//ElegxosAmp = map(abs(deltaX[i])+abs(deltaY[i]), 0, 340, 0, 0.2 );
// amp.add(ElegxosAmp);
// oscP5.send(amp, myRemoteLocation);
}
}
else {
deltaX[i] = (x[i-1]-x[i]);
deltaY[i] = (y[i-1]-y[i]);
}
deltaX[i] *= elastikotita[i]; // create elastikotita effect
deltaY[i] *= elastikotita[i];
epitaxinsiX[i] += deltaX[i];
epitaxinsiY[i] += deltaY[i];
x[i] += epitaxinsiX[i];// move it
y[i] += epitaxinsiY[i];
vertex(x[i],y[i]);
epitaxinsiX[i] *= aposbesi[i]; // slow down elastikotita
epitaxinsiY[i] *= aposbesi[i];
}
endShape();
}
void mouseReleased() {
if(xar) {
// OscMessage silence = new OscMessage("amp");
// silence.add(0);
// oscP5.send(silence, myRemoteLocation);
}
line0.calcPointsStart(mouseX, mouseY);
}
void mousePressed() {
line0.calcPointsStart(mouseX, mouseY);
line1.calcPointsStart(mouseX, mouseY);
line2.calcPointsStart(mouseX, mouseY);
}
void mouseDragged() {
}
void keyPressed(){
if (key == 'z') {
//cursor(cur, 0, 0);
}
if (key == 'b') {
background(0);
}
if (key == 's') {
smoothFade = !smoothFade;
}
}
//////////////////////
/*
// 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);
// draw the 3d point depth map
int[] depthMap = context.depthMap();
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
stroke(200);
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];
point(realWorldPoint.x,realWorldPoint.y,realWorldPoint.z);
}
}
}
// draw the tracked hand
if(handsTrackFlag)
{
pushStyle();
stroke(255,0,0,200);
noFill();
Iterator itr = handVecList.iterator();
beginShape();
while( itr.hasNext() )
{
PVector p = (PVector) itr.next();
vertex(p.x,p.y,p.z);
}
endShape();
stroke(255,0,0);
strokeWeight(4);
point(handVec.x,handVec.y,handVec.z);
popStyle();
}
// draw the kinect cam
context.drawCamFrustum();
}
// -----------------------------------------------------------------
// hand events
void onCreateHands(int handId,PVector pos,float time)
{
println("onCreateHands - handId: " + handId + ", pos: " + pos + ", time:" + time);
handsTrackFlag = true;
handVec = pos;
handVecList.clear();
handVecList.add(pos);
}
void onUpdateHands(int handId,PVector pos,float time)
{
//println("onUpdateHandsCb - handId: " + handId + ", pos: " + pos + ", time:" + time);
handVec = pos;
handVecList.add(0,pos);
if(handVecList.size() >= handVecListSize)
{ // remove the last point
handVecList.remove(handVecList.size()-1);
}
}
void onDestroyHands(int handId,float time)
{
println("onDestroyHandsCb - handId: " + handId + ", time:" + time);
handsTrackFlag = false;
context.addGesture(lastGesture);
}
// -----------------------------------------------------------------
// gesture events
void onRecognizeGesture(String strGesture, PVector idPosition, PVector endPosition)
{
println("onRecognizeGesture - strGesture: " + strGesture + ", idPosition: " + idPosition + ", endPosition:" + endPosition);
lastGesture = strGesture;
context.removeGesture(strGesture);
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;
}
switch(keyCode)
{
case LEFT:
rotY += 0.1f;
break;
case RIGHT:
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;
}
}
*/
/////////////////////////
class SketchLine {
int stoixeia = 1000, colorR, colorG, colorB, lineAlpha = 25;
float elast, aposv;
float[] x = new float[stoixeia];
float[] y = new float[stoixeia];
float[] epitaxinsiX = new float[stoixeia];
float[] epitaxinsiY = new float[stoixeia];
float[] elastikotita = new float[stoixeia];
float[] aposvesi = new float[stoixeia];
float[] deltaX = new float[stoixeia];
float[] deltaY = new float[stoixeia];
float pointX, pointY;
SketchLine(int stoixeiaVar) {
stoixeia = stoixeiaVar;
}
void calcType(float elastikotitaVar, float aposvesiVar) {
elast = elastikotitaVar;
aposv = aposvesiVar;
for (int i=0; i < stoixeia; i++){
elastikotita[i] = elast*(.07*(i+1));// 0.05 kai 0.005
aposvesi[i] = aposv-(0.02*i);
}
}
void calcPoints(float pointXVar, float pointYVar) {
pointX = pointXVar;
pointY = pointYVar;
for (int i=0; i<stoixeia; i++){
if (i==0){
deltaX[i] = (pointX - x[i]);
deltaY[i] = (pointY - y[i]);
// if (mousePressed) {
// OscMessage amp = new OscMessage("amp");
// ElegxosAmp = map(abs(deltaX[i])+abs(deltaY[i]),0,340,0,1.6 );
// amp.add(ElegxosAmp);
// oscP5.send(amp, myRemoteLocation);
// }
}
else {
deltaX[i] = (x[i-1]-x[i]);
deltaY[i] = (y[i-1]-y[i]);
}
deltaX[i] *= elastikotita[i]; // create elastikotita effect
deltaY[i] *= elastikotita[i];
epitaxinsiX[i] += deltaX[i];
epitaxinsiY[i] += deltaY[i];
x[i] += epitaxinsiX[i];// move it
y[i] += epitaxinsiY[i];
epitaxinsiX[i] *= aposvesi[i]; // slow down elastikotita
epitaxinsiY[i] *= aposvesi[i];
}
}
void calcPointsStart(float pointXVar, float pointYVar) {
pointX = pointXVar;
pointY = pointYVar;
for (int i=0; i<stoixeia; i++){
x[i] = mouseX;
y[i] = mouseY;
}
}
void render(int colorRVar, int colorGVar, int colorBVar, int lineAlphaVar) {
colorR = colorRVar;
colorG = colorGVar;
colorB = colorBVar;
lineAlpha = lineAlphaVar;
noFill();
stroke(colorR, colorG, colorB, lineAlpha);
beginShape();
for (int i = 0; i < stoixeia; i++) {
curveVertex(x[i], y[i]);
}
endShape();
}
}
/////////////
Sketch file:
/**
sKeTch is audiovisual application
Aris Bezas Sat, 16 July 2011, 17:31
SC-CODE
=======
s.boot;
(
SynthDef("Xaraktiki",
{ arg amp = 0.5, pan = 0, out = 0;
var source;
var panned_source;
source = HPF.ar(BrownNoise.ar(amp, 0), MouseX.kr(1000,8000));
panned_source = Pan2.ar(source, MouseX.kr(-0.9, 0.9));
Out.ar( out, panned_source);
}
).send(s);
)
// OSC router
p = NetAddr("127.0.0.1", 12000); // send to Processing
z = Synth("Xaraktiki");
OSCresponder(nil, "amp", { | time, resp, message |
z.set("amp", message[1]);
}).add;
*/
import processing.opengl.*;
//import oscP5.*;
//import netP5.*;
//OscP5 oscP5;
//NetAddress myRemoteLocation;
boolean miden, smoothFade;
boolean xar=true;
// Sound Input Variables
float amp1, freq1, amp2, freq2, ampout, freqout;
float ElegxosAmp;
SketchLine line0, line1, line2;
float x1, y1, x2, y2;
PImage cur;
int stoixeia = 30, lineAlpha = 50;
// Color Variables
int colorL=255,strokeL, strokeValue = 20, strokeBackground = 5;
int paintCount = 0, alphaSform;
int r0,g0,b0,r1,g1,b1;
// Physics Variables
float[] x = new float[stoixeia];
float[] y = new float[stoixeia];
float[] epitaxinsiX = new float[stoixeia];
float[] epitaxinsiY = new float[stoixeia];
float[] elastikotita = new float[stoixeia];
float[] aposbesi = new float[stoixeia];
float[] deltaX = new float[stoixeia];
float[] deltaY = new float[stoixeia];
float fxMouse, fyMouse;
void setup() {
frameRate(240);
size(900,450);
//oscP5 = new OscP5(this,46100); //listening
//myRemoteLocation = new NetAddress("127.0.0.1",57120); // speak to
line0 = new SketchLine(30);
line1 = new SketchLine(stoixeia);
line2 = new SketchLine(stoixeia + 1);
line0.calcType( 0.2, 0.65 );// 0.2, 0.65 writeLine
line1.calcType( 0.1, 0.65 );// 0.2, 0.65 writeLine
line2.calcType( 0.3, 0.65 );// 0.2, 0.65 writeLine
background(0);
noFill();
smooth();
// noCursor();
//cur = loadImage("cursor10black.png");
//cur.resize(8, 8);
//cursor(cur, mouseX, mouseY);
for (int i=0; i<stoixeia; i++){
elastikotita[i] = 0.2*(.07*(i+1));// 0.05 kai 0.005
aposbesi[i] = 0.55-(0.02*i);
}
}
void draw() {
myLine();
noFill();
if (mousePressed == true) {
line0.calcPoints(mouseX, mouseY);
line0.render(255,0,0, lineAlpha);
line1.calcPoints(mouseX, mouseY);
line1.render(255,255,0, lineAlpha);
line2.calcPoints(mouseX, mouseY);
line2.render(255,255,255, lineAlpha);
} else {
line0.calcPoints(mouseX, mouseY);
line0.render(255,0,0, 0);
line1.calcPoints(mouseX, mouseY);
line1.render(255,255,0, 0);
line2.calcPoints(mouseX, mouseY);
line2.render(255,255,255, 0);
}
if (smoothFade) {
fill(0,12);
rect(-10,-10,width,height);
}
}
void myLine(){
if (mousePressed == true) {
if(miden == true) {
for (int i=0; i<stoixeia; i++){
x[i] = mouseX;// move worm
y[i] = mouseY;
miden = false;
}
//cursor(cur, 0,0);
}
strokeL = strokeValue;
}
noFill();
drawline();
}
void drawline(){
fxMouse = mouseX;
fyMouse = mouseY;
// beginShape();
for (int i=0; i<5; i++){
if (i==0){
deltaX[i] = (fxMouse - x[i]);
deltaY[i] = (fyMouse - y[i]);
if (mousePressed && xar) {
//OscMessage amp = new OscMessage("amp");
//ElegxosAmp = map(abs(deltaX[i])+abs(deltaY[i]), 0, 340, 0, 0.2 );
// amp.add(ElegxosAmp);
// oscP5.send(amp, myRemoteLocation);
}
}
else {
deltaX[i] = (x[i-1]-x[i]);
deltaY[i] = (y[i-1]-y[i]);
}
deltaX[i] *= elastikotita[i]; // create elastikotita effect
deltaY[i] *= elastikotita[i];
epitaxinsiX[i] += deltaX[i];
epitaxinsiY[i] += deltaY[i];
x[i] += epitaxinsiX[i];// move it
y[i] += epitaxinsiY[i];
vertex(x[i],y[i]);
epitaxinsiX[i] *= aposbesi[i]; // slow down elastikotita
epitaxinsiY[i] *= aposbesi[i];
}
endShape();
}
void mouseReleased() {
if(xar) {
// OscMessage silence = new OscMessage("amp");
// silence.add(0);
// oscP5.send(silence, myRemoteLocation);
}
line0.calcPointsStart(mouseX, mouseY);
}
void mousePressed() {
line0.calcPointsStart(mouseX, mouseY);
line1.calcPointsStart(mouseX, mouseY);
line2.calcPointsStart(mouseX, mouseY);
}
void mouseDragged() {
}
void keyPressed(){
if (key == 'z') {
//cursor(cur, 0, 0);
}
if (key == 'b') {
background(0);
}
if (key == 's') {
smoothFade = !smoothFade;
}
}
// ========== SKETCH CLASS ===================
/*
091027 Igoumeninja Aris Bezas
class: sKeTch
variables: stoixeia, elastikotita, aposvesi, red, green, blue, alpha
methods: calcType, calcPoints, render
*/
class SketchLine {
int stoixeia = 1000, colorR, colorG, colorB, lineAlpha = 25;
float elast, aposv;
float[] x = new float[stoixeia];
float[] y = new float[stoixeia];
float[] epitaxinsiX = new float[stoixeia];
float[] epitaxinsiY = new float[stoixeia];
float[] elastikotita = new float[stoixeia];
float[] aposvesi = new float[stoixeia];
float[] deltaX = new float[stoixeia];
float[] deltaY = new float[stoixeia];
float pointX, pointY;
SketchLine(int stoixeiaVar) {
stoixeia = stoixeiaVar;
}
void calcType(float elastikotitaVar, float aposvesiVar) {
elast = elastikotitaVar;
aposv = aposvesiVar;
for (int i=0; i < stoixeia; i++){
elastikotita[i] = elast*(.07*(i+1));// 0.05 kai 0.005
aposvesi[i] = aposv-(0.02*i);
}
}
void calcPoints(float pointXVar, float pointYVar) {
pointX = pointXVar;
pointY = pointYVar;
for (int i=0; i<stoixeia; i++){
if (i==0){
deltaX[i] = (pointX - x[i]);
deltaY[i] = (pointY - y[i]);
// if (mousePressed) {
// OscMessage amp = new OscMessage("amp");
// ElegxosAmp = map(abs(deltaX[i])+abs(deltaY[i]),0,340,0,1.6 );
// amp.add(ElegxosAmp);
// oscP5.send(amp, myRemoteLocation);
// }
}
else {
deltaX[i] = (x[i-1]-x[i]);
deltaY[i] = (y[i-1]-y[i]);
}
deltaX[i] *= elastikotita[i]; // create elastikotita effect
deltaY[i] *= elastikotita[i];
epitaxinsiX[i] += deltaX[i];
epitaxinsiY[i] += deltaY[i];
x[i] += epitaxinsiX[i];// move it
y[i] += epitaxinsiY[i];
epitaxinsiX[i] *= aposvesi[i]; // slow down elastikotita
epitaxinsiY[i] *= aposvesi[i];
}
}
void calcPointsStart(float pointXVar, float pointYVar) {
pointX = pointXVar;
pointY = pointYVar;
for (int i=0; i<stoixeia; i++){
x[i] = mouseX;
y[i] = mouseY;
}
}
void render(int colorRVar, int colorGVar, int colorBVar, int lineAlphaVar) {
colorR = colorRVar;
colorG = colorGVar;
colorB = colorBVar;
lineAlpha = lineAlphaVar;
noFill();
stroke(colorR, colorG, colorB, lineAlpha);
beginShape();
for (int i = 0; i < stoixeia; i++) {
curveVertex(x[i], y[i]);
}
endShape();
}
}
«Prev
Next »
Moderate user : f9655339
Forum