# How do you expand a kinect's window to match the size of the canvas?

**URL:** <https://discourse.processing.org/t/how-do-you-expand-a-kinects-window-to-match-the-size-of-the-canvas/10168>\
**Category:** Libraries\
**Created:** [April 10, 2019, 7:44pm UTC](https://discourse.processing.org/t/how-do-you-expand-a-kinects-window-to-match-the-size-of-the-canvas/10168 "2019-04-10T19:44:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicoles](https://avatars.discourse-cdn.com/v4/letter/n/ee7513/32.png) [@nicoles](https://discourse.processing.org/u/nicoles)\
**Post date:** [April 10, 2019, 7:44pm UTC](https://discourse.processing.org/t/how-do-you-expand-a-kinects-window-to-match-the-size-of-the-canvas/10168/1 "2019-04-10T19:44:12Z")

</div>

I am playing with the Kinect and when I enlarge the size of the canvas, the Kinect window stays the same size and does not expand to match the size of the canvas. How can I enlarge it?

---

<div class="post-metadata">

**Author:** ![zenemig](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/zenemig/32/4418_2.png) [@zenemig](https://discourse.processing.org/u/zenemig)\
**Post date:** [April 12, 2019, 5:15pm UTC](https://discourse.processing.org/t/how-do-you-expand-a-kinects-window-to-match-the-size-of-the-canvas/10168/2 "2019-04-12T17:15:34Z")

</div>

Hi, first of all, we need to know some things that are not clear on this:

- What kinect are you using?
- What operative system are you using?
- What library are you using for the kinect connection?

---

<div class="post-metadata">

**Author:** ![nicoles](https://avatars.discourse-cdn.com/v4/letter/n/ee7513/32.png) [@nicoles](https://discourse.processing.org/u/nicoles)\
**Post date:** [April 12, 2019, 6:54pm UTC](https://discourse.processing.org/t/how-do-you-expand-a-kinects-window-to-match-the-size-of-the-canvas/10168/3 "2019-04-12T18:54:36Z")

</div>

I’m using a Kinect v2. My operating system is MacOS Sierra version 10.12.6. The library I’m using is Open Kinect.

---

<div class="post-metadata">

**Author:** ![zenemig](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/zenemig/32/4418_2.png) [@zenemig](https://discourse.processing.org/u/zenemig)\
**Post date:** [April 13, 2019, 1:58am UTC](https://discourse.processing.org/t/how-do-you-expand-a-kinects-window-to-match-the-size-of-the-canvas/10168/4 "2019-04-13T01:58:14Z")

</div>

Im asuming you’re using the library I linked in the [other post](https://discourse.processing.org/t/how-can-i-link-multiple-kinects-in-one-processing-sketch/10169/3).  
If that is the case, the image you are getting from the Kinect and the size of the canvas are not conected, so there’s no chance of getting the kinect image automatically adjust its size to the windows/canvas size.

If you have something like this in your code:

```auto
image(kinect2.getDepthImage(), 0, 0);

```

It means that you are placing the kinect image, in its original size at 0 of x and 0 of y. So the kinect did’t care about your canvas size.

But if you have something like this:

```auto
image(kinect2.getDepthImage(), 0, 0, width, height);

```

That mean you’re adjusting the image you get from the kinect to the size of your windows/canvas.

---

<div class="post-metadata">

**Author:** ![nicoles](https://avatars.discourse-cdn.com/v4/letter/n/ee7513/32.png) [@nicoles](https://discourse.processing.org/u/nicoles)\
**Post date:** [April 18, 2019, 7:28pm UTC](https://discourse.processing.org/t/how-do-you-expand-a-kinects-window-to-match-the-size-of-the-canvas/10168/5 "2019-04-18T19:28:18Z")

</div>

I’ve tried using your advice, but I’m sitll stuck. Here’s my code:

```auto
import org.openkinect.processing.*;

Kinect2 kinect2;
Drop[] drops = new Drop[500];
float minThresh = 480;
float maxThresh = 830;
PImage img;
int rx;
int ry;

void setup() {
  size(512, 424);
  kinect2 = new Kinect2(this);
  kinect2.initDepth();
  kinect2.initDevice();
   for (int i = 0; i < drops.length; i++) {
   drops[i] = new Drop();
  }
  
}

class Drop {
  float x;
  float y;
  float z;
  float len;
  float yspeed;

  Drop() {
    x = random(width);
    y = random(-500, -50);
    z = random(0, 20);
    len = map(z, 0, 20, 10, 20);
    yspeed = map(z, 0, 20, 1, 20);
  }

  void fall() {
    y = y + yspeed;
    float grav = map(z, 0, 20, 0, 0.2);
    yspeed = yspeed + grav;

    if (y > height) {
      y = random(-200, -100);
      yspeed = map(z, 0, 20, 4, 10);
    }
    else if (dist(rx,ry+100,x,y)< 100) {

      y = random(-200, -100);
      yspeed = map(z, 0, 20, 4, 10);
    }
    
  
  }

  void show() {
    float thick = map(z, 0, 20, 1, 3);
    strokeWeight(thick);
    stroke(137, 207, 240);
    line(x, y, x, y+len);
  }
}

void draw() {
   
  background(25,25,112);

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

  // Get the raw depth as array of integers
  int[] depth = kinect2.getRawDepth();
  
  //int record = 4500;
  int record = kinect2.depthHeight;
  rx = 0;
  ry = 0;

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

      if (d > minThresh && d < maxThresh && x > 100 && y > 50) {
       
        if (y < record) {
          record = y;
          rx = x;
          ry = y;
        }
        
        
      } else {
      }
    }
  }

  for (int i = 0; i < drops.length; i++) {
    drops[i].fall();
    drops[i].show();
 
  }
  noFill();
  noStroke(); 
  ellipse(rx, ry+100, 200, 200);

}

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 20, 2019, 5:36pm UTC](https://discourse.processing.org/t/how-do-you-expand-a-kinects-window-to-match-the-size-of-the-canvas/10168/6 "2019-04-20T17:36:29Z")

</div>

> [@zenemig](#):
>
> But if you have something like this:
> 
> ```auto
> image(kinect2.getDepthImage(), 0, 0, width, height);
> 
> ```
> 
> That mean you’re adjusting the image

This works well, but note however that this is extremely inefficient if the image isn’t constantly updating – assuming that you have lots of camera activity, a resize every frame might be the best that you can do – but whenever possible avoid 5-arg image as it can be really slow.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 20, 2019, 5:36pm UTC](https://discourse.processing.org/t/how-do-you-expand-a-kinects-window-to-match-the-size-of-the-canvas/10168/7 "2019-04-20T17:36:51Z")

</div>

> [@nicoles](#):
>
> but I’m sitll stuck

What isn’t working? What error / bad output are you getting?
