Created
March 5, 2012 00:27
-
-
Save neufuture/1975615 to your computer and use it in GitHub Desktop.
How to blur a region of video feed in processing
This file contains hidden or 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.*; | |
Capture feed; | |
BlurBox bb[] = new BlurBox[5]; | |
void setup() { | |
size(320, 240); | |
feed = new Capture(this, 320, 240, Capture.list()[0]); | |
feed.start(); | |
for (int i=0; i<bb.length; i++) { | |
// create multiple BlurBox objects at random locations | |
bb[i] = new BlurBox((int)random(width), (int)random(height), 40, 40); | |
} | |
} | |
void draw() { | |
if (feed.available() == true) { | |
feed.read(); | |
} | |
image(feed, 0, 0, width, height); | |
for (int i=0; i<bb.length; i++) { | |
bb[i].display(); | |
} | |
} | |
void mousePressed() { | |
for (int i=0; i<bb.length; i++) { | |
//if one box is clicked, stop checking | |
if (bb[i].clicked(mouseX, mouseY)) break; | |
} | |
} | |
void mouseReleased() { | |
for (int i=0; i<bb.length; i++) { | |
bb[i].stopDragging(); | |
} | |
} | |
void mouseDragged() { | |
for (int i=0; i<bb.length; i++) { | |
if (bb[i].dragging) bb[i].drag(mouseX, mouseY); | |
} | |
} | |
class BlurBox { | |
int x, y, w, h; | |
boolean dragging = false; // Is the object being dragged? | |
int offsetX, offsetY; // Mouseclick offset | |
PImage blurred; | |
BlurBox (int x_, int y_, int w_, int h_) { | |
x = x_; | |
y = y_; | |
w = w_; | |
h = h_; | |
offsetX = 0; | |
offsetY = 0; | |
blurred = new PImage(w_, h_); | |
} | |
void display() { | |
// pushMatrix(); you shouldn't need this | |
if (dragging) stroke(255, 255, 0); | |
else noStroke(); | |
//fill(0, 0, 0, 150); | |
noFill(); | |
//filter(BLUR, 6); | |
blurred = get(x, y, w, h); | |
blurred.filter(BLUR, 5); | |
image(blurred, x, y); | |
rect(x, y, w, h); | |
// popMatrix(); you shouldn't need this either | |
} | |
// Is a point inside the rectangle (for click)? | |
boolean clicked(int mx, int my) { | |
if (mx > x && mx < x + w && my > y && my < y + h) { | |
dragging = true; | |
// If so, keep track of relative location of click to corner of rectangle | |
offsetX = x-mx; | |
offsetY = y-my; | |
return true; | |
} | |
else return false; | |
} | |
// Is a point inside the rectangle (for rollover) | |
/*void rollover(int mx, int my) { | |
if (mx > x && mx < x + w && my > y && my < y + h) { | |
rollover = true; | |
} else { | |
rollover = false; | |
} | |
}*/ | |
// Stop dragging | |
void stopDragging() { | |
dragging = false; | |
} | |
// Drag the rectangle | |
void drag(int mx, int my) { | |
if (dragging) { | |
x = mx + offsetX; | |
y = my + offsetY; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment