/**
* Synchronized Pixels Capture (1.0.0)
* GoToLoop (2021-Oct-05)
* Discourse.Processing.org/t/video-pixels-changing-while-i-process-them/32589/10
*/
import processing.video.Capture;
Capture cam;
PImage frame;
void setup() {
size(640, 480);
frame = get();
cam = new Capture(this, width, height, "pipeline: autovideosrc");
cam.start();
}
void draw() {
surface.setTitle("Frame: " + frameCount + " FPS: " + round(frameRate));
synchronized (frame) {
background(frame);
}
}
void captureEvent(final Capture c) {
c.read();
final color[] pix = frame.pixels;
final int len = pix.length;
c.loadPixels();
synchronized (frame) {
arrayCopy(c.pixels, pix);
for (int i = 0; i < len; pix[i++] ^= ~PImage.ALPHA_MASK);
frame.updatePixels();
}
}
1 Like