Created
April 10, 2012 20:48
-
-
Save slambert/2354369 to your computer and use it in GitHub Desktop.
Face blur
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
// Get OpenCV here: http://ubaa.net/shared/processing/opencv/ | |
import hypermedia.video.*; | |
import java.awt.Rectangle; | |
OpenCV opencv; | |
// contrast/brightness values | |
int contrast_value = 0; | |
int brightness_value = 0; | |
void setup() { | |
size( 640, 480 ); | |
opencv = new OpenCV( this ); | |
opencv.capture( width, height ); // open video stream | |
opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT_TREE ); // load detection description, here-> front face detection : "haarcascade_frontalface_alt.xml" | |
// print usage | |
println( "Drag mouse on X-axis inside this sketch window to change contrast" ); | |
println( "Drag mouse on Y-axis inside this sketch window to change brightness" ); | |
} | |
public void stop() { | |
opencv.stop(); | |
super.stop(); | |
} | |
void draw() { | |
// grab a new frame | |
// and convert to gray | |
opencv.read(); | |
// opencv.convert( GRAY ); | |
opencv.contrast( contrast_value ); | |
opencv.brightness( brightness_value ); | |
// proceed detection | |
Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 ); | |
// draw face area(s) | |
//fill(255,0,255); | |
noFill(); | |
stroke(255,0,0); | |
for ( int i=0; i<faces.length; i++ ) { | |
rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height ); | |
opencv.blur(OpenCV.BLUR, 9); | |
} | |
// display the image | |
image( opencv.image(), 0, 0 ); | |
opencv.ROI(null); | |
} | |
/** | |
* Changes contrast/brigthness values | |
*/ | |
void mouseDragged() { | |
contrast_value = (int) map( mouseX, 0, width, -128, 128 ); | |
brightness_value = (int) map( mouseY, 0, width, -128, 128 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment