We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone, I am doing a project about person extraction and background subtraction. I am going to export a video of the foreground people. Learnt from Daniel Shiffman, now I could get the pixels of foreground but I don't know how to export these pixels as a video. Or I don't need to export it immediately, but I need to do the further processing about these pixels as a video format. Is there anyone could help me? Thanks a lot in advance. Sorry for my English if there is any mistake.
Here is the code:
import processing.video.*;
Capture video;
PImage backgroundImage;
float threshold = 30;
void setup() {
size(320, 240);
video = new Capture(this, width, height);
video.start();
backgroundImage = createImage(video.width, video.height, RGB);
}
void captureEvent(Capture video) {
video.read();
}
void draw() {
loadPixels();
video.loadPixels();
backgroundImage.loadPixels();
image(video, 0, 0);
for (int x = 0; x < video.width; x++) {
for (int y = 0; y < video.height; y++) {
int loc = x + y * video.width;
color fgColor = video.pixels[loc];
color bgColor = backgroundImage.pixels[loc];
float r1 = red(fgColor); float g1 = green(fgColor); float b1 = blue(fgColor);
float r2 = red(bgColor); float g2 = green(bgColor); float b2 = blue(bgColor);
float diff = dist(r1, g1, b1, r2, g2, b2);
if (diff > threshold) {
pixels[loc] = fgColor;
} else {
pixels[loc] = color(0, 0, 0);
}
}}
updatePixels();
}
void mousePressed() {
backgroundImage.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
backgroundImage.updatePixels();
}