Created
February 21, 2012 20:32
-
-
Save resophonic/1878724 to your computer and use it in GitHub Desktop.
SMFA12_intro2hack_face_detection_v3
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 hypermedia.video.*; | |
import java.awt.Rectangle; | |
float fI; | |
float fO; | |
float fOrvs; | |
OpenCV opencv; | |
// contrast/brightness values | |
int circlesize; | |
int contrast_value = 0; | |
int brightness_value = 0; | |
void setup() { | |
size(500, 500); | |
background(255); | |
opencv = new OpenCV(this); //start opencv | |
opencv.capture(width, height); // open capture stream | |
opencv.cascade(OpenCV.CASCADE_FRONTALFACE_ALT); //frontal face detection | |
smooth(); | |
frameRate(30); | |
} | |
public void stop() { | |
opencv.stop(); | |
super.stop(); | |
} | |
void draw() { | |
opencv.read(); // grab a new frame | |
opencv.convert(GRAY); //grayscale | |
opencv.contrast(contrast_value); | |
opencv.brightness(brightness_value); | |
opencv.flip(OpenCV.FLIP_HORIZONTAL); | |
// detection | |
Rectangle[] faces = opencv.detect(1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40); | |
//image( opencv.image(), 0, 0 ); <- show video | |
//draw circles | |
noFill(); | |
stroke(fI,fI,fO,50); | |
for(int i=0; i<faces.length; i++) { | |
fI = faces[i].x; | |
fO = faces[i].y; | |
fOrvs = faces[i].y*-1; | |
ellipse(faces[i].x, faces[i].y, faces[i].width, faces[i].height); | |
} | |
//distance change | |
if(keyPressed && (key==CODED)) { | |
if(keyCode == SHIFT) { | |
background(255); | |
} | |
} | |
} | |
//brightness/contrast | |
void mouseDragged() { | |
contrast_value = (int) map(mouseX, 0, width, -128, 12); | |
brightness_value = (int) map(mouseY, 0, width, -128, 128); | |
} | |
//data value x/y | |
void mousePressed() { | |
noStroke(); | |
PFont f; | |
f = loadFont("HelveticaNeueLT-UltraLight-20.vlw"); | |
textFont(f); | |
fill(fO,fI,fO); | |
textAlign(CENTER); | |
text(fI/fO,mouseX,mouseY); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment