Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

Make the animation to move with kinect

edited March 2017 in Kinect

Hello,

I am very new in Processing. I am using Processing 3.3. So I found this formula and I want to move the animation by tracking my movements from a Kinect instead of a mouse. I am using the new Kinect on a Mac. I can get information from kinect2 but I can't find a way to connect my movements with the animation. Can pls someone help me?

void setup () {
size (500,500);
noFill();
stroke(255);
strokeWeight(2);
}

void draw() {
background(0);

translate(width /2, height/2);

beginShape();

// add some vertices

for (float theta = 0; theta <= 2 * PI; theta += 0.01) {

float rad = r(theta,
mouseX / 100.0, // a
mouseY / 100.0, // b
70, // m
1, // n1
2, // n2
2 // n3
);
float x = rad * cos (theta) * 50;
float y = rad * sin (theta) * 50;
vertex (x, y);

}

endShape();

}

float r(float theta, float a, float b, float m, float n1, float n2, float n3) {
return pow(pow (abs(cos(m * theta / 4.0)/a), n2 ) +
pow (abs(sin(m * theta / 4.0) /b), n3), -1.0 / n1) ;

}

• void setup () {
size (500,500);
noFill();
stroke(255);
strokeWeight(2);
}

void draw() {
background(0);

translate(width /2, height/2);

beginShape();

// add some vertices

for (float theta = 0; theta <= 2 * PI; theta += 0.01) {

float rad = r(theta,
mouseX / 100.0, // a
mouseY / 100.0, // b
70, // m
1, // n1
2, // n2
2 // n3
);
float x = rad * cos (theta) * 50;
float y = rad * sin (theta) * 50;
vertex (x, y);

}

endShape();

}

float r(float theta, float a, float b, float m, float n1, float n2, float n3) {
return pow(pow (abs(cos(m * theta / 4.0)/a), n2 ) +
pow (abs(sin(m * theta / 4.0) /b), n3), -1.0 / n1) ;

}

• Please edit your post, select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code

Kf

• thanks. It looks better now :)

• How do you want to connect this code with kinetic?

Also, check previous comments related to kinetic here: https://forum.processing.org/two/search?Search=kinetic

Kf

• Hello, Thanks for your reply. I would like to make this animation to react with a performer's (body) on stage. Instead of using the mouse I would like to use the kinect. I insalled the open kinect library by shimman import org.openkinect.processing.*;

Here is the code I am using:

import org.openkinect.processing.*;

// Kinect Library object
Kinect2 kinect2;
PImage img;

void setup () {
size (500,500);
kinect2 = new Kinect2(this);
kinect2.initDepth();
kinect2.initDevice();
noFill();
stroke(255);
strokeWeight(2);
}

void draw() {
background(0);

PImage img = kinect2.getDepthImage();
image (img, 0, 0);

translate(width /2, height/2);

beginShape();

// add some vertices

for (float theta = 0; theta <= 2 * PI; theta += 0.01) {

float rad = r(theta,
mouseX / 100.0, // a
mouseY / 100.0, // b
70, // m
1, // n1
2, // n2
2 // n3
);
float x = rad * cos (theta) * 50;
float y = rad * sin (theta) * 50;
vertex (x, y);

}

endShape();

}

float r(float theta, float a, float b, float m, float n1, float n2, float n3) {
return pow(pow (abs(cos(m * theta / 4.0)/a), n2 ) +
pow (abs(sin(m * theta / 4.0) /b), n3), -1.0 / n1) ;

}

• Check this previous post as it could give you an idea of how to use the depth data: https://forum.processing.org/two/discussion/21412/kinect-projection-masking-array-out-of-bounds-error#latest

Kf

• This is untested code below. What I do is I grab the depth value right at the center of the depth data (yes, only one pixel) and i used that to replace the effect of mouseX from your code.

Also search for other examples using https://forum.processing.org/two/search?Search=depthMap

Lastly, check Shiffman's videos on Kinetic: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZMlWHdcy8hAGDy6IaoxUKf

Kf

import org.openkinect.processing.*;

// Kinect Library object
Kinect2 kinect2;
PImage img;

//distance in cm depth, adapt to room
int distance = 1500;
int distance2 = 3000;

void setup () {
size (500, 500);
kinect2 = new Kinect2(this);
kinect2.initDepth();
kinect2.initDevice();
noFill();
stroke(255);
strokeWeight(2);
}

void draw() {
background(0);

PImage img = kinect2.getDepthImage();
image (img, 0, 0);

kinect.update();
int[] depthValues = kinect.depthMap(); //array, distances

translate(width /2, height/2);
beginShape();

int centerOfScreen= depthMapWidth/2.0+(depthMapWidth/2.0*depthMapWidth);
int currentDepthValue = depthValues[centerOfScreen];
float mappedVal=map(currentDepthValue,distance,distance2,0,width/100.0);

// add some vertices
for (float theta = 0; theta <= 2 * PI; theta += 0.01) {

float rad = r(theta,
mappedVal, // a
mouseY / 100.0, // b
70, // m
1, // n1
2, // n2
2 // n3
);
float x = rad * cos (theta) * 50;
float y = rad * sin (theta) * 50;
vertex (x, y);
}

endShape();
}

float r(float theta, float a, float b, float m, float n1, float n2, float n3) {
return pow(pow (abs(cos(m * theta / 4.0)/a), n2 ) +
pow (abs(sin(m * theta / 4.0) /b), n3), -1.0 / n1) ;
}

• Hello, Thank you very much for your help. I really really appreciate that. As you notice I am not that familiar with processing and this might be very easy to do if you are familiar with the code.

I am getting two errors on lines 27 and 28. Probably I need to change to kinect2. However, when I change to kinect2 I 've got another error on line 27 (the function update() does not exist ). when I change kinect.depthMap to kinect2.depthMap it says 'The Sunction'depthMap() does not exist.

I am writing kinect2 because I am using the new kinect. I will check as well the links you send me.

Thank you so much !!!

• I will check the provided documentation and any previous post using kinetic2. You are right, lines 27 and 28 should be kinetic2. I copy this from a previous post and they could some bugs.

Kf