Skip to content

Instantly share code, notes, and snippets.

@newshorts
Last active August 29, 2015 14:05
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 newshorts/e0caa9961c8e61f2a007 to your computer and use it in GitHub Desktop.
Save newshorts/e0caa9961c8e61f2a007 to your computer and use it in GitHub Desktop.
Background subtraction processing with opencv
// This will show background subtraction from your webcam in processing using:
// https://github.com/atduskgreg/opencv-processing
import gab.opencv.*;
import processing.video.*;
import java.awt.*;
//Movie video;
Capture video;
OpenCV opencv;
void setup() {
size(640, 480, P2D);
// size(720, 480, P2D);
video = new Capture(this, 640/2, 480/2);
// video = new Movie(this, "street.mov");
// opencv = new OpenCV(this, 720, 480);
opencv = new OpenCV(this, 640/2, 480/2);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
opencv.startBackgroundSubtraction(5, 3, 0.5);
// video.loop();
// video.play();
video.start();
}
void draw() {
scale(2);
image(video, 0, 0);
opencv.loadImage(video);
opencv.updateBackground();
opencv.dilate();
opencv.erode();
noFill();
stroke(255, 0, 0);
strokeWeight(3);
for (Contour contour : opencv.findContours()) {
contour.draw();
}
}
void movieEvent(Movie m) {
m.read();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment