Depth Values of Z Axis per Pixel

edited March 2017 in Kinect

Hello Guys,

im quite fresh in the processing world and no native speaker so please be gentle :)

but direct to the Point:

Im would like to know is there any possibilty to get an defined Z axis output of every pixel ? with the code below (copied from shiffman) i can get an matrix out of the kinect so is there any possibility to map every single pixel and send it to an arduino ?

        import org.openkinect.freenect2.*;
        import org.openkinect.processing.*; //<>//

        Kinect2 kinect2;

        void setup() {
          size(32, 16, P2D);
          kinect2 = new Kinect2(this);
          kinect2.initVideo();
          kinect2.initDepth();
        }


        void draw() {
          background(0);

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

    for (int x = 0; x < img.width; x++); {
    for (int y = 0; y < img.height; x++);{
    int index = x +y * img.widht;
    float b = brightness (img.pixels[index]);
    float z = map(b, 0, 255, 250, -250);
    fill(255-b);
    pushMatrix();
    translate( x, y, z);
    rect( 0, 0,skip/2,skip/2);
    popMatrix();
        }
      }
    }

Answers

  • widht

    Spelling.

    Line 21 is incrementing the wrong thing. y++

    (I would have the y loop outermost, BTW)

    img.pixels is the depth map. This appears to be in the range 0-255. Line 24 is remapping it.

  • Thanks for the correction I just wrote it quick down in text edit but your answer doesn't dsolve my problemm, I want the depth value of every single pixel so 512 values. Do you know a solution for this.

  • println(img.width, img.height);

    what does that say?

  • I dont understand thr question

    The Function is prints these values

    And in the code its for looping through the pixels.

  • when you add that to your code and run it, what does it say?

  • edited February 2017

    thank you for your help koogs,really thank you very much

    but i cant run the code right now, im in the office.

    ill try it out later, last time i had some trouble with 21 now 23

          int index = x + y * img.width;
    

    TAB 0,LN 22LN START OFF: 386,LN STOP OFF: 387,PROB: The variable "x" does not exist The variable "x" does not exist kinect1 23

  • Answer ✓
    for (int x = 0; x < img.width; x++); {
    for (int y = 0; y < img.height; y++); {
    

    remove the final ; on each of these lines.

  • all errors are solved code is running nice and smoth, if i println(img.width, img.height);

    i get only the values 525,424 so the width and height.

    i need to map the pixels and get the println on the depth values any idea how to achieve that ?

  • here is the working code:

    Does somebody know how to get the values from specific pixels ?

    import KinectPV2.*;
    import org.openkinect.freenect.*;
    import org.openkinect.freenect2.*;
    import org.openkinect.processing.*;
    import org.openkinect.tests.*;
    
    
    Kinect2 kinect2;
    
    void setup() {
      size(512, 424, P3D);
      kinect2 = new Kinect2(this);
      kinect2.initVideo();
      kinect2.initDepth();
      kinect2.initDevice();
    }
    
    
    void draw() {
      background(0);
    
      PImage img = kinect2.getDepthImage();
      //image(img, 0, 0);
      int  skip = 17;
      for (int x = 0; x < img.width; x+=skip) { //=skip
        for (int y = 0; y < img.height; y+=skip){ //=skip
          int index = x + y * img.width; // formel ist x+y+ width ergibt tiefen wert
          float b = brightness (img.pixels[index]);
          float z = map(b, 0, 255, 250, -250);
         fill(255-b);
         pushMatrix();
         translate( x, y, z);
         rect( 0, 0, skip/2, skip/2);
         popMatrix();
        }
     }
    }
    
  • img.pixels[index]

    this is your depth, per pixel. it's in the range 0 to 255.

  • i know i can achieve a "floating" value when i add println (x , y , z); so it loops truogh any "pixel" and gives me the Z value but is there a possibilty to get X and y straight so the only floating value is Z ?

  • is there a possibilty to get X and y straight so the only floating value is Z ?

    i have no idea what you're asking here.

    draw a picture? put up a screenshot of the result of the above code?

  • edited March 2017

    so i added println (x , y , z); to my code. now this addition prints me the following values in :

    493 34 -48.039215
    493 51 -69.60785
    493 68 -99.01962
    493 85 -122.54904
    493 102 -169.60785
    493 119 -214.70587
    493 136 250.0
    493 153 250.0
    493 170 250.0
    493 187 250.0
    493 204 250.0
    493 221 250.0
    493 238 250.0
    493 255 250.0
    493 272 250.0
    493 289 250.0
    493 306 250.0
    493 323 32.352936
    

    Now its looping through x,y,z and i only would like to loop through z so i get an fixed value for x,y that it doenst look like this below it should look like

    x     y     z
    493 34 -48.039215
    493 34 -50.039215
    493 34 -20.039215
    
    493 51 -09.60785
    493 51 -19.60785
    493 51 -99.60785
    
  • i only would like to loop through z

    but there is only one value of z for each x,y position. it's not a 3d space, it's a 2d surface.

    where are you getting those z values?

  • yes its only one Z value for each coordinate and i want to know exactly, this should be the only value that changes so i can send the Z values to my Arduino. i would like to know at any time which z Value X0 Y17 got or X500 Y35

    what i image: i got a myPort.write (x =0 , y =0, z); so that x and y is fix and only z changes continously but that doesnt work... thats all i want

  • Yes, time is the other variable. Z at any position will change with time.

    The code you have posted doesn't match the description in your last post. Please post the new code.

Sign In or Register to comment.