summaryrefslogtreecommitdiff
path: root/webcam_face/webcam_face.pde
blob: 49564be0417c11faa62dbbf09ac90d91e94d1fce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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();
}