Last active
April 26, 2021 23:09
-
-
Save atduskgreg/5938251 to your computer and use it in GitHub Desktop.
Background Subtraction in OpenCV in Processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.video.*; | |
import gab.opencvpro.*; | |
import java.awt.Rectangle; | |
Movie video; | |
OpenCV opencv; | |
void setup() { | |
size(720, 480, P2D); | |
video = new Movie(this, "street.mov"); | |
opencv = new OpenCV(this, 720, 480); | |
opencv.startBackgroundSubtraction(5, 3, 0.5); | |
video.loop(); | |
video.play(); | |
} | |
void draw() { | |
opencv.loadImage(video); | |
opencv.updateBackground(); | |
opencv.dilate(); | |
opencv.erode(); | |
image(video, 0, 0); | |
noFill(); | |
stroke(255,0,0); | |
strokeWeight(2); | |
for(Contour contour : opencv.findContours()){ | |
Rectangle r = contour.getBoundingBox(); | |
rect(r.x, r.y, r.width, r.height); | |
} | |
} | |
void movieEvent(Movie m) { | |
m.read(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment