Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
kasperweiss
kasperweiss'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
Kinect - closest point tracking in 3D
[0 Replies]
22-Mar-2013 02:53 PM
Forum:
Integration and Hardware
Hi,
I try to draw lines in 3D by tracking closest point.
Here is a code which works in 2D.
https://github.com/atduskgreg/Making-Things-See-Examples/blob/master/ex09_advanced_drawing/ex09_advanced_drawing.pde
I would like to write a 3D version of this.
However, I could not achieve it in 3D. I added closestZ, lastZ, interpolatedZ values to this sketch, but it doesn't work. Where is the problem?
import processing.dxf.*;
import SimpleOpenNI.*;
SimpleOpenNI kinect;
int closestValue;
int closestX;
int closestY;
int closestZ;
float lastX;
float lastY;
float lastZ;
void setup()
{
size(640, 480, P3D);
kinect = new SimpleOpenNI(this);
kinect.enableDepth();
// start out with a black background
background(0);
beginRaw(DXF, "output.dxf");
}
void draw()
{
closestValue = 8000;
kinect.update();
int[] depthValues = kinect.depthMap();
for (int y = 0; y < 480; y++) {
for (int x = 0; x < 640; x++) {
// reverse x by moving in from
// the right side of the 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 closestValue within a range
// 610 (or 2 feet) is the minimum
// 1525 (or 5 feet) is the maximum
if (currentDepthValue > 610 && currentDepthValue < 1525
&& currentDepthValue < closestValue) {
closestValue = currentDepthValue;
closestZ = currentDepthValue;
closestX = x;
closestY = y;
}
}
}
// "linear interpolation", i.e.
// smooth transition between last point
// and new closest point
float interpolatedX = lerp(lastX, closestX, 0.3f);
float interpolatedY = lerp(lastY, closestY, 0.3f);
float interpolatedZ = lerp(lastZ, closestZ, 0.3f);
stroke(255, 0, 0);
// make a thicker line, which looks nicer
strokeWeight(3);
line(lastX, lastY, lastZ, interpolatedX, interpolatedY, interpolatedZ);
lastX = interpolatedX;
lastY = interpolatedY;
lastZ = interpolatedZ;
}
void keyPressed() {
if (key == 'r'|| key == 'R') {
endRaw();
exit();
}
}
«Prev
Next »
Moderate user : kasperweiss
Forum