Skip to content

Instantly share code, notes, and snippets.

@eldog
Last active February 6, 2017 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eldog/bf2ff7f0219d9eba0e86dc650b997aa3 to your computer and use it in GitHub Desktop.
Save eldog/bf2ff7f0219d9eba0e86dc650b997aa3 to your computer and use it in GitHub Desktop.
// Import Libraries - install these if necessary.
import processing.video.*;
import gab.opencv.*;
//create Capture
Capture liveCam;
//create PImages
PImage camCapture, foregroundMask, backgroundMask, screenshot;
float comparVal = 0.25;
OpenCV opencv;
int width = 640;
int height = 480;
void setup() {
//scene setup
fullScreen();
colorMode(HSB,1,1,1);
liveCam = new Capture(this,width,height);
camCapture = createImage(width,height,HSB);
screenshot = createImage(width,height,HSB);
foregroundMask = createImage(width,height,HSB);
backgroundMask = createImage(width,height,HSB);
// Create the opencv object in setup, not in the draw call.
opencv = new OpenCV(this, foregroundMask);
//live Camera start
liveCam.start();
}
void draw() {
if (liveCam.available()) {
liveCam.read();
}
//set camCapture PImage to be current Frame
camCapture.set(0,0,liveCam);
camCapture.loadPixels();
opencv.loadImage(screenshot);
// Don't do the processing in processing (Java), let opencv do the heavy lifting (save the CPU and the frames!).
opencv.diff(camCapture);
opencv.blur(6);
opencv.threshold(50);
opencv.erode();
opencv.erode();
opencv.erode();
opencv.dilate();
opencv.dilate();
opencv.dilate();
foregroundMask = opencv.getSnapshot();
camCapture.blend(foregroundMask, 0, 0, width, height, 0, 0, width, height, ADD);
image(camCapture,0,0);
}
void mouseClicked() {
screenshot.set(0,0,liveCam);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment