Quantcast
Channel: Kinect - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 530

Skeletal data to grid data

$
0
0

Sorry if this has been asked before, but I couldn't find anything. I'm quite new to both Kinect and programming, so it would be great if someone can help me out here.

In my processing sketch I have created a grid of 4*4 tiles, each having an assigned value of "0". I want to change this value to "1" if a human (or limb) is detected in that part of the grid.

This would mean if a head is spotted in the leftupper corner, tile #1 would get a value of "1". If a foot is also spotted in the rightlower corner, tile#16 would get a value of "1'. This results in a string of "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1". This data is send to Arduino through serial commucation (I'm planning to use it to create silhouettes in LEDS).

I'm currently using the KinectPV2 library. I think I have to use the rawData of this library, where each value that is NOT 255 tells me that a limb is found there (I assume rawData gives me the 'coordinates' of where the limb is found, but I cant test that, see my question further below. If I'm wrong please correct me!).

To check this, I write this: int [] rawData = kinect.getRawBodyTrack();

  for (int i = 0; i < rawData.length; i++){
    if (rawData[i] != 255){
      humanPresent = true;
      println(rawData[i]);
    }
  }

However, the problem seems to be that rawData is so extremely big (217088 values at minimum), that I can't run a loop like that without crashing Processing. This brings me to my question: how could I check rawData in an efficient way, or, what would be a better way to change grid tile values based on the position of limbs?

Thanks!

Full code: import processing.serial.*; import KinectPV2.*;

KinectPV2 kinect;

//Grid
Table table;
int cols = 4; //grid Width (amount of valves)
int rows = 2 ;//gridHeight, amount of "pixels" we want in the grid, vertically
int gridTiles; //amount of tiles
int tileValue[];

//Enddata
String allGridValues = "";

//Serial
Serial myPort;

//Misc
boolean humanPresent = false;


void setup(){
  size(1200, 800);
  kinect = new KinectPV2(this);
  kinect.enableBodyTrackImg(true); //enables tracking bodies
  kinect.enableColorImg(true); //enables visualising the full video in color for testing purposes
  kinect.enableDepthImg(true); //enables black white image for testing purposes
  kinect.init();

  gridTiles = (rows*cols);
  setTable();

  //Serial comm
  //printArray(Serial.list()); //list available ports
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);

}


void draw(){
  clear(); //clears background
  background(255); //sets background to full white

  image(kinect.getColorImage(), 0, 0, width, height); //Full Color
  //image(kinect.getDepthImage(), 0, 0, width, height); //Black White

  //PImage kinectImg = kinect.getBodyTrackImage();
  //image(kinectImg, 512, 0);
  int [] rawData = kinect.getRawBodyTrack();

  for (int i = 0; i < rawData.length; i++){
    if (rawData[i] != 255){
      humanPresent = true;
      println(rawData[i]);
      //break
    }
  }
}

void setTable(){
  table = new Table();
  table.addColumn("tile");
  table.addColumn("value");

  tileValue = new int[gridTiles];

  for (int i = 0; i < gridTiles; i++){
    tileValue[i] = 0;
    TableRow newRow = table.addRow();
    newRow.setInt("tile", i);
  }
}

Viewing all articles
Browse latest Browse all 530

Trending Articles