I'm a noob working on a Processing sketch that takes a webcam feed as input and applies optical flow and particle effects. The sketch is called OpticalFlow_CaptureFluid. It's from Thomas Diewald's PixelFlow library.
Basically, I want to modify the CaptureFluid sketch so that it takes a Syphon feed instead of a webcam feed.
I've looked at the Optical Flow sketch and the ReceiveFrames sketch for Syphon. I sort of understand what the different parts of each sketch are doing, but because I'm not much of a coder I have very little idea of how to combine them so that the optical flow sketch is receiving frames from syphon.
Here's the ReceiveFrames sketch:
import codeanticode.syphon.*;
PGraphics canvas;
SyphonClient client;
void settings() {
size(640, 480, P3D);
PJOGL.profile = 1;
}
public void setup() {
// Create syhpon client to receive frames
// from the first available running server:
client = new SyphonClient(this);
background(0);
}
public void draw() {
if (client.newFrame()) {
canvas = client.getGraphics(canvas);
image(canvas, 0, 0, width, height);
}
}
The Optical Flow sketch is huge, so I've only included what I think are the most relevant bits here. The entire sketch is linked above. (Would have posted down here as well but I'm a newbie and they won't let me post more than two links!)
OpticalFlow_CaptureFluid (excerpt)
import processing.opengl.PGraphics2D;
import processing.video.Capture;
// webcam capture
cam = new Capture(this, cam_w, cam_h, 30);
cam.start();
// render buffers
pg_cam_a = (PGraphics2D) createGraphics(cam_w, cam_h, P2D);
pg_cam_a.noSmooth();
pg_cam_a.beginDraw();
pg_cam_a.background(0);
pg_cam_a.endDraw();
pg_cam_b = (PGraphics2D) createGraphics(cam_w, cam_h, P2D);
pg_cam_b.noSmooth();
pg_fluid = (PGraphics2D) createGraphics(view_w, view_h, P2D);
pg_fluid.smooth(4);
public void draw() {
if( cam.available() ){
cam.read();
// render to offscreenbuffer
pg_cam_b.beginDraw();
pg_cam_b.background(0);
pg_cam_b.image(cam, 0, 0);
pg_cam_b.endDraw();
swapCamBuffer(); // "pg_cam_a" has the image now
if(APPLY_BILATERAL){
filter.bilateral.apply(pg_cam_a, pg_cam_b, 5, 0.10f, 4);
swapCamBuffer();
}
// update Optical Flow
opticalflow.update(pg_cam_a);
I know I need to add "import codeanticode.syphon.*;" to the CaptureFluid sketch, get rid of the webcam capture bits, and replace that with a new syphon client. And I guess all the pg_cam_a and pg_cam_b variables need to be renamed or somehow modified. Tbh I don't even really understand what they're doing.
Okay last thing: I found this post by this guy who is sending frames in and out of a sketch with Syphon. He says this only works in P3D mode, but this CaptureFluid sketch uses P2D. The ReceiveFrames sketch I posted above uses P3D (see size under void settings), but I changed it to P2D and it seemed to work just fine, so I'm not sure if that's actually an issue.
Thanks in advance!