We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm working on a greenscreen project right now and my task is to use a video with a greenscreen in the background. The green background should be replaced by an image. In the foreground, there is someone doing some random stuff (that doesn't matter). Only the green background is important. So first I tried some steps which are easier, they all worked pretty good, but now I'm trying to replace the green pixels from the greenscreen in the backgorund with black colored pixels, so that we have a black background. I used that code:
import processing.video.*; //importing the video library
Movie movie; //declaring movie
void setup() {
size(1280, 720);
movie = new Movie(this, "greenscreen_hand.mp4"); //loading movie and..
movie.loop(); //..looping the movie
}
void draw() {
loadPixels();
movie.loadPixels();
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
int stelle = i+(j*width); //iterating through the screen and setting the number of the index through the whole frame
float red = red(movie.pixels[stelle]); //RGB values of the pixel
float green = green(movie.pixels[stelle]);
float blue = blue(movie.pixels[stelle]);
color c = color(0, 0, 0); //black pixels
if (red>40 && red<80 && green>190 && blue>60 && blue<90) { //if pixel is kind of green
movie.set(i, j, c); //new pixel color
}
}
}
image(movie, 0, 0);
}
void movieEvent(Movie m) {
m.read();
}
void mousePressed() { //that actually doesn't matter, it's just for some information from some steps before
int stelle = mouseX+(mouseY*width);
float red = red(movie.pixels[stelle]);
float green = green(movie.pixels[stelle]);
float blue = blue(movie.pixels[stelle]);
println("R: " + red +" "+ "G: " + green +" "+ "B: " + blue);
}
Now I got a whole bunch of problems. Well, sometimes there is an ArrayIndexOutOfBoundsException: 0 (I don't know why actually :/) and sometimes it works and the video is starting, but the background is flickering (half-green and half-black) (maybe because pixels are loading too slow in every millisecond frame?)
Can someone help me? Or some suggestions about what I could change?
Answers
I changed the black background to a random image. I didn't change much, but the flickering effect is still the same, just with the pixels of the image.
Now my final question: Is the flickering background normal? I do think it is because Processing has to calculate every little pixel within every millisecond, so the screen is flickering, because it can't run fast enough to let the background look smooth.
Any ideas? ^^"
https://Processing.org/reference/rightshift.html
Check the reference for pixels[] as well as updatePixels (called in tandem with loadPixels). I believe using pixels[] is recommended over using set.
Also check in the forum for
chromakey
Kf