# KinectV2 - Getting a rectangle boundary of the body

I am trying to draw a rectangle around the body detected by Kinect.
Left most and highest points are detected but have difficulty finding the right most and lowest point.

``````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);
PImage dImg = kinect2.getDepthImage();
int[] depth = kinect2.getRawDepth();

// highest
int highest = kinect2.depthHeight;
int hx = 0;
int hy = 0;
// 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++) {
// Mirroring the image
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 highest point
if (y < highest) {
highest = y;
hx = x;
hy = y;
}

//finding the left most point
if (x < leftRecord) {
leftRecord = x;
lx = x;
ly = y;
}

// finding the right most point
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);
}`````````