summaryrefslogtreecommitdiff
path: root/webcam_face/webcam_face.pde
diff options
context:
space:
mode:
authorYuval Adam <yuv.adm@gmail.com>2011-09-20 21:02:04 +0300
committerYuval Adam <yuv.adm@gmail.com>2011-09-20 21:02:04 +0300
commit3e4edaf94322ebff0a339d0898dca2126a85b0b8 (patch)
treee3e938c114549122b2d04478e9a8692747aa6b75 /webcam_face/webcam_face.pde
parentf3f45ffd9af4e029f2fb47911f63f4f255c17b69 (diff)
added webcam face detection
Diffstat (limited to 'webcam_face/webcam_face.pde')
-rw-r--r--webcam_face/webcam_face.pde37
1 files changed, 37 insertions, 0 deletions
diff --git a/webcam_face/webcam_face.pde b/webcam_face/webcam_face.pde
new file mode 100644
index 0000000..49564be
--- /dev/null
+++ b/webcam_face/webcam_face.pde
@@ -0,0 +1,37 @@
+import hypermedia.video.*;
+import java.awt.Rectangle;
+
+OpenCV opencv;
+
+void setup() {
+ size(640, 480);
+ opencv = new OpenCV(this);
+ opencv.capture(320, 240);
+ opencv.cascade(OpenCV.CASCADE_FRONTALFACE_ALT);
+}
+
+void draw() {
+ opencv.read();
+ // display the current video feed
+ image(opencv.image(), 0, 0);
+
+ // detect anything ressembling a FRONTALFACE
+ Rectangle[] faces = opencv.detect();
+
+ // draw detected face area(s)
+ fill(255,0,0);
+ stroke(255,0,0);
+ for (int i=0; i<faces.length; i++) {
+ // copy a specific area from the image in memory (the background)
+ // place the copy exactly where the face is in the current image
+ rect(faces[i].x,faces[i].y,faces[i].width,faces[i].height);
+ }
+
+ // display the image in memory
+ image(opencv.image(OpenCV.MEMORY), 329, 0);
+}
+
+void keyPressed() {
+ opencv.remember();
+}
+