1

I am trying to draw a rectangle around the body using its upper left corner and bottom right corner detected by Kinect.

The left most and the highest points are detected but I have difficulty finding the right most and the lowest point. The current right mark is jumping up and down and does not move in x-direction.

import org.openkinect.processing.*;

Kinect2 kinect2;

float minThresh = 420;
float maxThresh = 1500;
PImage img;

void setup() {
  size(512, 424);
  kinect2 = new Kinect2(this);
  kinect2.initDepth();
  kinect2.initDevice();
  img = createImage(kinect2.depthWidth, kinect2.depthHeight, RGB);
}


void draw() {
  background(0);
  img.loadPixels();
  PImage dImg = kinect2.getDepthImage();
  int[] depth = kinect2.getRawDepth();

  // left side
  int leftRecord = kinect2.depthWidth;
  int lx = 0;
  int ly = 0;
  
  // right side
  int rightRecord = 0;
  int rx =0;
  int ry = 0;

  for (int x = 0; x < kinect2.depthWidth; x++) {
    for (int y = 0; y < kinect2.depthHeight; y++) {
      int offset = x + y*kinect2.depthWidth;
      // Grabbing the raw depth
      int d = depth[offset];

      // Testing against threshold
      if (d > minThresh && d < maxThresh && x>50) {
        
        img.pixels[offset] = color(255, 0, 150);
        
        //finding the left most point
        if (x < leftRecord) {
          leftRecord = x;
          lx = x;
          ly = y;
        }
        
        // finding the right most point
        // THE BIT THAT DOES NOT WORK
        if( x > rightRecord && x < kinect2.depthWidth){
          rightRecord = x;
          rx = x;
          ry = y;
        }

      } else {
        img.pixels[offset] = dImg.pixels[offset];
      }
    }
  }
  img.updatePixels();
  image(img, 0, 0);

  fill(150, 0, 255);
  ellipse(lx,ly,30,30);
  ellipse(rx,ry,30,30);
}
gigi
  • 11
  • 1

0 Answers0