Hello,
i have a sketch where i’m trying to set a certain color of an image to zero transparency color(0,0).
It works in the first part of the sketch but for some reason doesn’t work in the second part.
See image for reference.
Here’s the whole code:
import org.openkinect.processing.*;
// Kinect Library object
Kinect2 kinect2;
float minThresh = 1000;
float maxThresh = 2700;
PImage img, img1, img3;
int counter;
boolean img3Draw = false;
PImage hintergrund;
int timer = 0;
boolean firstClick = true;
void setup() {
frameRate(30);
background(0);
hintergrund = loadImage("hintergrund3.png");
size(1920, 1080);
kinect2 = new Kinect2(this);
kinect2.initDepth();
kinect2.initDevice();
img = createImage(kinect2.depthWidth, kinect2.depthHeight, ARGB);
img3 = createImage(kinect2.depthWidth, kinect2.depthHeight, ARGB);
}
void draw() {
image(hintergrund, 0, 0);
img.loadPixels();
int[] depth = kinect2.getRawDepth();
float totalPixels = 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) {
img.set(x, y, color(map(depth[offset], 4500, 500, 0, 255)));
totalPixels++;
} else {
img.pixels[offset] = color(0,0);
}
}
}
counter++;
if (counter == 5) {
pushStyle();
tint(255, 3);
image(img, 100, 500);
popStyle();
counter = 0;
}
timer++;
if (timer == 100) {
}
println(img3Draw);
if (img3Draw == true) {
image(img3, 400, 100, kinect2.depthWidth, kinect2.depthHeight);
}
}
void mouseClicked() {
img3 = get(100, 500, 512, 424);
img3.loadPixels();
for (int x=0; x< img3.pixels.length; x++) {
if (img3.pixels[x] == color(0)) {
img3.pixels[x] = color(0, 0);
}
}
img3.updatePixels();
img3Draw = true;
}
I can set the pixels to a different color like this:
for (int x=0; x< img3.pixels.length; x++) {
if (img3.pixels[x] == color(0)) {
img3.pixels[x] = color(0, 255, 0);
}
}
But when i try to set them to transparent with color(0,0); the black pixels seem to stay black.
Thank you in advance!