hi to all!
i’m tryng to subtract the background ov a video stream
processing code
import processing.video.*;
Capture video;
PShader shader;
PGraphics pg;
void setup() {
size(1280, 720, P2D);
shader = loadShader("passImage.glsl");
pg = createGraphics(width, height, P2D);
shader.set("u_resolution", width/1., height/1.);
video = new Capture(this, width, height);
video.start();
}
void draw() {
println(frameRate);
if (video.available() == true) {
video.read();
}
pg.beginDraw();
pg.loadPixels();
video.loadPixels();
shader.set("textureCam", video);
shader.set("preTextureCam", pg);
shader(shader);
pg.pixels = video.pixels;
pg.updatePixels();
video.updatePixels();
pg.endDraw();
rect(0, 0, width, height);
}
glsl code
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
uniform sampler2D textureCam, preTextureCam;
uniform vec2 u_resolution;
vec3 background = vec3(0);
void main(){
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.xy = vec2(1)-st.xy;
vec2 st2 = gl_FragCoord.xy/u_resolution.xy;
st.x = 1-st.x;
vec3 color = texture2D(textureCam, st).rgb;
vec3 preColor = texture2D(preTextureCam, st2).rgb;
vec3 diff = abs(color-preColor);
gl_FragColor = vec4(diff, 1);
}
the code work a little bit strange, too much black frame
any suggestion?