tilt and rotate slice from kinect
in
Contributed Library Questions
•
1 month ago
Hi!
Im using this tracking system for tracking closest point with a kinect.
I can change the top, bottom, left right edges by adjusting the numbers in the two for loops but how do i adjust the z?
I guess this create the array of depth, z
what I want to do is to rotate the slice so if i put the kinect in the ceiling I can modify the slice that the kinect takes so its not further away in the bottom and closer in the top. I want to be able to rotate it by adjusting the depth values.
so tilt/rotate the whole slice of the tracked image ...
heres the whole sketch. any thoughts? (i know its a bit of messy explanation ...)
Im using this tracking system for tracking closest point with a kinect.
I can change the top, bottom, left right edges by adjusting the numbers in the two for loops but how do i adjust the z?
I guess this create the array of depth, z
- depthImage = kinect.depthImage();
so tilt/rotate the whole slice of the tracked image ...
heres the whole sketch. any thoughts? (i know its a bit of messy explanation ...)
- import SimpleOpenNI.*;
- SimpleOpenNI kinect;
- Keys keyEvents;
- int close = 1310;
- int far = 1325;
- int closestX;
- int closestY;
- int x;
- int y;
- float xMapped;
- float yMapped;
- // slice on / off
- boolean slice = true;
- PImage depthImage;
- int currentDepthValue;
- float closestValue;
- float posX, posY, posZ; // current X, Y, Z
- int v_left = 140;
- int b_right = 550;
- int f_top = 20;
- int g_bot = 330;
- int skevaH = 0;
- void setup() {
- background(0);
- size(displayWidth, displayHeight);
- blendMode(BLEND);
- keyEvents = new Keys();
- kinect = new SimpleOpenNI(this);
- kinect.setMirror(true);
- kinect.enableDepth();
- }
- void draw() {
- // ---------- uppdaterar kinectbilden
- kinect.update();
- closestValue = 8000; // sätter closes value till 8000. det gör att alla som är mindre säkert kommer med.
- // get the depth array from the kinect
- int[] depthValues = kinect.depthMap();
- depthImage = kinect.depthImage();
- for (int x = v_left; x < b_right; x++) {
- for (int y = f_top; y < g_bot; y++) {
- int i = x + y * 640;
- currentDepthValue = depthValues[i];
- if (slice == true) {
- color color_ = color(100, 0, 200);
- if (currentDepthValue < close // om talet är mindre än värdet deklarerat i closestValue (i detta fall 610)
- || currentDepthValue > far) { // eller större än värdet deklarerat i farthestValue (i detta fall 1525)
- depthImage.pixels[i] = color_; // görs alla pixlarna om till 0 (dvs. svart)
- }
- }
- if (currentDepthValue > close && currentDepthValue < far && currentDepthValue < closestValue) {
- closestValue = currentDepthValue;
- closestX = x;
- closestY = y;
- xMapped = map(closestX, v_left, b_right, 0, displayWidth);
- yMapped = map(closestY, f_top, g_bot, 0, displayHeight);
- }
- }
- }
- if (slice == true) {
- image(kinect.depthImage(), 0, 0, width, height);
- }
- if (closestValue > far || closestValue < close) {
- noFill();
- noStroke();
- }
- else if (closestValue < far ) {
- fill(random(0, 255), random(0, 255), random(0, 255));
- stroke (255);
- }
- ellipse(xMapped, yMapped, 50, 50);
- }
- // DRAW END ------------------------------------
- class Keys {
- Keys() {
- }
- void tangent() {
- if (keyPressed) {
- if (key == 'w') {
- slice = true;
- }
- if (key == 'q') {
- slice = false;
- }
- // Beskär
- if (key == 'l') {
- v_left = skevaH + 10;
- }
- if (key == 'k') {
- v_left = v_left + 10;
- }
- if (key == 'i') {
- v_left = skevaH + 10;
- }
- if (key == 'o') {
- v_left = v_left + 10;
- }
- // ----------
- if (key == 'b') {
- v_left = v_left + 10;
- }
- if (key == 'n') {
- b_right = b_right - 10;
- }
- if (key == 'f') {
- f_top = f_top + 10;
- }
- if (key == 'h') {
- g_bot = g_bot - 10;
- }
- if (key == 'v') {
- v_left = v_left - 10;
- }
- if (key == 'm') {
- b_right = b_right + 10;
- }
- if (key == 'g') {
- f_top = f_top - 10;
- }
- if (key == 'j') {
- g_bot = g_bot + 10;
- }
- v_left = constrain(v_left, 0, 640);
- b_right = constrain(b_right, 0, 640);
- f_top = constrain(f_top, 0, 480);
- g_bot = constrain(g_bot, 0, 480);
- if (keyCode == UP) {
- close = close + 10;
- }
- if (keyCode == DOWN) {
- close = close - 10;
- }
- if (keyCode == LEFT) {
- far = far + 10;
- }
- if (keyCode == RIGHT) {
- far = far - 10;
- }
- println("left " + v_left);
- println("right " + b_right);
- println("top " + f_top);
- println("bottom " + g_bot);
- println("closest " + close);
- println("farthest " + far);
- if (key == 'd') {
- background(0, 0, 0);
- }
- }
- }
- }
1