Kinect with grid

edited December 2016 in Kinect

Im new with processing, im trying to make a fade background and as the user move the movement will stay on the grid.

So i have made a grid, where i move the can see my body movement on the grid.

1) how do i make the movement stay in grid after i move.

2) how do i make ... example = player 1 = red, player 2 = green.

3)background color fade random rgb.

import processing.serial.*;
import KinectPV2.*;


Serial myPort;
KinectPV2 kinect;

boolean foundUsers = false;

int matrixSizeWidth = 14;
int matrixSizeHeight = 18;

void setup() {
  size(1024, 424);
  frameRate(200);

  //String portName = "COM5";
 // myPort = new Serial(this, portName, 115200);

  kinect = new KinectPV2(this);

  //kinect.enableDepthImg(true);
  kinect.enableBodyTrackImg(true);

  kinect.init();

  delay(6000);
}

void draw() {
  clear();
  background(255);

  PImage kinectImg = kinect.getBodyTrackImage();

  image(kinectImg, 512, 0);

  int [] rawData = kinect.getRawBodyTrack();

  foundUsers = false;
  //iterate through 1/5th of the data
  for(int i = 0; i < rawData.length; i+=5){
    if(rawData[i] != 255){
     //found something
     foundUsers = true;
     break;
    }
  }
 // print(rawData);

  int totalPixels = 0;

  //if (foundUsers)
  //{
   // myPort.clear();

    int row = 0;

    //color toColor = -(int)random(255*255*255);
    color thatColor = -(int)random(255*255*255);

    for (int y = 10; y < 414; y += matrixSizeHeight){
      int col = 0;

      for (int x = 10; x < 500; x += matrixSizeWidth) {
        color c = kinectImg.pixels[x + y*kinectImg.width];

        // print(c);

        if(c < -1)
        {
        //c = toColor;
        }
        else{
        c = thatColor;
        }

        print(c);

        fill(c);
        stroke(0);
        strokeWeight(1);
        rect(x, y, matrixSizeWidth, matrixSizeHeight);

        //if (totalPixels < 105)
        //{
          if (c != -1)
          {
            //print(1);
           // myPort.write("H");
            totalPixels++;
            //myPort.write(totalPixels);
          }
          else
          {
            //print(0);
           // myPort.write("L");
          }
        //}


        col++;
      }

      row++;
    }


   // myPort.write("C");

  fill(0);
  textSize(14);
  text(kinect.getNumOfUsers(), 10, 30);
  text("Found User: "+foundUsers, 10, 50);
  text(frameRate, 10, 70);
  text("Total Pixels: " + totalPixels, 10, 90);
}

Answers

  • Format your code above. Edit your post, select your code and hit ctrl+o. Ensure one empty line above and below your code block.

    Kf

  • Sorry bout that, shall make the changes

  • Im stuck here now.

    Please describe your problem. You need to be specific, as most ppl will not be able to reproduce your problem because they will lack a kinetic unit.

    Kf

  • Update : i have a fading background behind my grid, how can i make the grid transparent but still see user moving?

    //Colour tween animation
    //Set starting colour values 
    int r = 255;
    int g = 0;
    int b = 0;
    int alphaVal, alphaDelta;
    
    import processing.serial.*;
    import KinectPV2.*;
    
    
    Serial myPort;
    KinectPV2 kinect;
    
    boolean foundUsers = false;
    
    int matrixSizeWidth = 14;
    int matrixSizeHeight = 18;
    
    void setup() {
    
     alphaVal = 255; // initial value
     alphaDelta = 1; // rate of change
    
      size(1024, 424);
      frameRate(20);
    
      //String portName = "COM5";
     // myPort = new Serial(this, portName, 115200);
    
      kinect = new KinectPV2(this);
    
      //kinect.enableDepthImg(true);
      kinect.enableBodyTrackImg(true);
    
      kinect.init();
    
      delay(6000);
    }
    
    void draw() {
      clear();
      Colors();
    
      PImage kinectImg = kinect.getBodyTrackImage();
    
      image(kinectImg, 512, 0);
    
      int [] rawData = kinect.getRawBodyTrack();
    
      foundUsers = false;
      //iterate through 1/5th of the data
      for(int i = 0; i < rawData.length; i+=5){
        if(rawData[i] != 255){
         //found something
         foundUsers = true;
         break;
        }
      }
     // print(rawData);
    
      int totalPixels = 0;
    
      //if (foundUsers)
      //{
       // myPort.clear();
    
        int row = 0;
    
        color toColor = -(int)random(255*255*255);
    
        for (int y = 10; y < 414; y += matrixSizeHeight){
          int col = 0;
    
          for (int x = 10; x < 500; x += matrixSizeWidth) {
            color c = kinectImg.pixels[x + y*kinectImg.width];
    
            // print(c);
    
            if(c < -1)
            {
             c = 0;
            }
            else{
            c = color(0,0,alphaVal);
            }
    
            fill(c);
            stroke(0);
            strokeWeight(0);
            rect(x, y, matrixSizeWidth, matrixSizeHeight);
    
            //if (totalPixels < 105)
            //{
              if (c != -1)
              {
                //print(1);
               // myPort.write("H");
                totalPixels++;
                //myPort.write(totalPixels);
              }
              else
              {
                //print(0);
               // myPort.write("L");
              }
            //}
    
    
            col++;
          }
    
          row++;
        }
    
    
    
       // myPort.write("C");
    
      fill(0);
      textSize(14);
      text(kinect.getNumOfUsers(), 10, 30);
      text("Found User: "+foundUsers, 10, 50);
      text(frameRate, 10, 70);
      text("Total Pixels: " + totalPixels, 10, 90);
    }
    
    void Colors() 
    {
      background(r, g, b);
      //Red to yellow
      if(g < 255 && b == 0)
      {
         g = g + 1;
      }
    
      //Yellow to green
      if (g == 255 && b == 0) 
      {
        if(r >= 0)
        {
          r = r - 1;
        }
      }
    
      //Green to cyan
      if (r == 0 && g == 255) 
      {
        if(b < 255)
        {
          b = b + 1;
        }
      }
      //cyan to blue
      if (b == 255 && r == 0)
      {
        if(g > 0)
        {
           g = g - 1;
        }
      }
      //Purple to magenta
      if (b == 255 && g == 0) 
      {
        if(r < 255)
        {
          r = r + 1;
        }
      }
    
      //magenta to red
      if(r == 255 && g == 0)
      {
        if(b > 0)
        {
          b = b - 1;
        }
      }
    }
    
Sign In or Register to comment.