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?
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?
I’m using a Kinect v2. My operating system is MacOS Sierra version 10.12.6. The library I’m using is Open Kinect.
Im asuming you’re using the library I linked in the other post.
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:
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:
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.
I’ve tried using your advice, but I’m sitll stuck. Here’s my code:
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);
}
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.
What isn’t working? What error / bad output are you getting?