We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there! I am very new at processing, but for an outcomming exhibition I would like to use processing and kinect. I have found some lines of code and changed them to meet my goals. But now I can't move forward and finish it! I would like to restart my sketch every 3 minutes (reseting everytime all lines drawn) without any keypressed or mouse event. Is this possible? Help me pleaseeeee! Here the code that I've made and changed so far:
PImage img;
import SimpleOpenNI.*;
SimpleOpenNI kinect;
boolean sketchFullScreen() {
return true;
}
int closestValue;
int closestX;
int closestY;
float lastX;
float lastY;
//decalre global vriables for the
//previous x and y co-ordinates
int previousX;
int previousY;
void setup()
{
kinect = new SimpleOpenNI(this);
kinect.enableDepth();
background(0);
size(displayWidth, displayHeight);
img = loadImage("bolaXL640.jpg");
image(img, 350, 150);
}
void draw()
{
closestValue = 4000;
kinect.update();
int[] depthValues = kinect.depthMap();
translate (350, 150);
for(int y = 0; y < 480; y++){
for(int x = 0; x < 640; x++){
// reverse x by moving in from the right side of image
int reversedX = 640-x-1;
// use reversedx to calculate
//the array index
int i = reversedX + y * 640;
int currentDepthValue = depthValues[i];
//only look for the closest values within a range
//620 or 2 feet is the minimum
//1525 or 5 feet is the maximum
if(currentDepthValue > 610 && currentDepthValue < 1525
&& currentDepthValue < closestValue){
closestValue = currentDepthValue;
closestX = x;
closestY = y;
}
}
}
//linear interpolation i.e smooth transition between last point and new
// closest point
float interpolatedX = lerp(lastX, closestX, 0.2f);
float interpolatedY = lerp(lastY, closestY, 0.2f);
//line colour
stroke(0);
strokeWeight(1);
//draw line from previous point to new one
line(lastX, lastY, interpolatedX, interpolatedY);
lastX = interpolatedX;
lastY = interpolatedY;
}
Answers
here---
Thanks! it works just fine!! But, sorry my ignorance, now I have another problem...when the background goes to black how can I put my background image where it was on setup (center) ? I'm trying like this but it doesn't load.
//...
if (hasFinished()) { println(WAIT_TIME/1000 + " seconds have past! At " + millis() + " millis."); startTime = millis(); background(0); loadImage("bolaXL640.jpg"); startTime=millis(); }
I have tried to copy the values of setup for my image -- image(img, 350, 150); -- but it simply moves to the right bottom instead of being centered, as it was. humpf! Don't know how to fix it!
//...
if (hasFinished()) { println(WAIT_TIME/1000 + " seconds have past! At " + millis() + " millis."); startTime = millis(); background(0); loadImage("bolaXL640.jpg"); image(img, 350, 150); startTime=millis(); }
first
imgBkg = loadImage("bolaXL640.jpg");
must always be in setup() never in draw()second just use
background(imgBkg);
;-)
Hello again :) I've tried as you said...but it isn't running :( I have got this message "Could not run the sketch (Target VM failed to initialize)." Here's the full code...can you tell me what i did wrong? Thanks! you're being an huge help!!! :)
final int WAIT_TIME = (int) (120.0 * 1000); // 120.0 seconds in millis
int startTime;
PImage imgBkg;
import SimpleOpenNI.*;
SimpleOpenNI kinect;
boolean sketchFullScreen() { return true; }
int closestValue;
int closestX;
int closestY;
float lastX;
float lastY;
int previousX;
int previousY;
void setup() { kinect = new SimpleOpenNI(this);
kinect.enableDepth();
background(0);
size(displayWidth, displayHeight);
imgBkg = loadImage("bolaXL640.jpg");
image(imgBkg, 350, 150);
startTime=millis();
}
void draw() { closestValue = 4000;
kinect.update();
int[] depthValues = kinect.depthMap();
translate (350, 150);
for(int y = 0; y < 480; y++){
for(int x = 0; x < 640; x++){
}
//linear interpolation i.e smooth transition between last point and new // closest point
float interpolatedX = lerp(lastX, closestX, 0.2f);
float interpolatedY = lerp(lastY, closestY, 0.2f);
//line colour
stroke(0);
strokeWeight(1);
//draw line from previous point to new one
line(lastX, lastY, interpolatedX, interpolatedY);
lastX = interpolatedX;
lastY = interpolatedY;
if (hasFinished()) {
background(imgBkg);
startTime=millis();
}
}
boolean hasFinished() {
return millis() - startTime >= WAIT_TIME; }
Sorry about the messy code... I am very new at this...the first one was probably corrected by the admin :) sorry! About the golden rule, not sure I understand...(as I said...very new at this and very poorly programming skills)
Should I do it like this? It's not possible to run the sketch either "Could not run the sketch (Target VM failed to initialize)" What am i missing?
`
`
the beginning of setup() should look like this
so move the line
size(displayWidth, displayHeight);
up.size() must occur only once.
Hello once more! :)
I moved
size(displayWidth, displayHeight);
up to setup only... but no improvements...it still breaks down after 120 seconds and the sketch doesn´t run. Thebackground(imgBkg);
gets underlined and this message appears :120 seconds have past! At 122864 millis. Could not run the sketch (Target VM failed to initialize).
Why? Is there another crucial error in the code? Until there the sketch runs fine!
I can't help you
I don't know the lib you use.
Remarks
lines 30 / 33 / 89 / 90 should be
background(imgBkg);
this could be before
setup()
:int[] depthValues;
do other processing sketches run at all - the simple examples?
do other kinect sketches with that lib run?
Find out whether it's because of the current sketch or a deeper issue please.
;-)
Hi there again! Thanks! Think I got it! I have resized the data image
imBkg
tosize (640,360)
it works just fine and resets after 120 seconds. But I can´t do a fullscreen withboolean sketchFullScreen()
. Any thoughts in what to use? Thanks!size(displayWidth, displayHeight);
?
All done and working!!!!thanks a lot!!!
you're welcome!
;-)