Hey guys,
after watching some tutorials about the kinect I finally managed to get the depth image and transform that depth image into text/numbers. I have a textfile with a poem, just one for now, and I want that it picks random words to create something new. In my code I loaded the file, but instead of words it gives me numbers. Does anyone know what I do wrong?
import org.openkinect.freenect.*;
import org.openkinect.processing.*;
String[] lines;
String[] tokens;
String[] allwords;
PImage depthImg;
int minDepth = 400;
int maxDepth = 900;
int kinectWidth = 640;
int kinectHeight = 480;
//max depth 2048
int cont_length = displayWidth*displayHeight;
float angle;
float reScale;
Kinect kinect;
void setup() {
lines = loadStrings("rainbow.txt");
String allwords = join(lines, "\n");
tokens = splitTokens(allwords, ",; .?1234567890!");
println(tokens);
reScale = (float) width / kinectWidth;
size(1280, 800, P3D);
PFont f = createFont( "Franklin Gothic Medium", 24 );
textFont(f);
kinect = new Kinect(this);
kinect.initDepth();
angle = kinect.getTilt();
depthImg = new PImage(640, 480, ARGB);
depthImg.filter(BLUR, 1);
reScale = (float) width / kinectWidth;
}
void draw() {
background(0);
int[] rawDepth = kinect.getRawDepth();
float minThresh = map(mouseX, 0, width, 0, 4500);
float maxThresh = map(mouseY, 0, width, 0, 4500);
for (int x=0; x < kinect.width; x+=10) {
for (int y=0; y < kinect.height; y+=10) {
int offset = x + y * kinect.width;
int d = rawDepth[offset];
float b = brightness(depthImg.pixels[offset]);
float z = map(b, 0, 255, 250, -250);
if (d >= minDepth && d <= maxDepth) {
fill(0, 255, 0);
pushMatrix();
textSize(10);
translate(x, y, z);
text(int(random(tokens.length)), x, y );
popMatrix();
}
}
}
text(minThresh + " " + maxThresh, 10, 64);
translate(0, (height-kinectHeight*reScale)/2);
scale(reScale);
image(depthImg, 0, 0, displayWidth, displayHeight);
depthImg.updatePixels();
fill(0);
text("TILT: " + angle, 10, 20);
}
void mousePressed() {
saveFrame();
}
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
angle++;
} else if (keyCode == DOWN) {
angle--;
}
angle = constrain(angle, 0, 30);
kinect.setTilt(angle);
}
}