Created
October 25, 2012 09:21
-
-
Save pokutuna/3951586 to your computer and use it in GitHub Desktop.
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 hypermedia.video.*; | |
import java.awt.Rectangle; | |
OpenCV opencv; | |
void setup() { | |
size(320, 240); | |
opencv = new OpenCV(this); | |
opencv.capture(width, height); | |
opencv.cascade(OpenCV.CASCADE_FRONTALFACE_ALT); //顔正面のカスケード識別器をロード | |
noFill(); | |
stroke(255,0,0); | |
} | |
int detected = -1; | |
void draw() { | |
opencv.read(); | |
image(opencv.image(), 0, 0); | |
Rectangle[] faces = opencv.detect(); | |
if (0 < faces.length) { | |
if (detected != -1) { | |
if (millis() - detected > 5000) { | |
println("lock on!!"); | |
} else { | |
println("keep detection"); | |
} | |
} else { | |
println("count reset"); | |
detected = millis(); | |
} | |
} else { | |
println("not detected"); | |
detected = -1; | |
} | |
for( int i=0; i<faces.length; i++ ) { | |
rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height); | |
} | |
} | |
/* | |
Rectangleは四角形を表すクラス | |
x座標, y座標, 幅(width)), 高さ(height)を持つ | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment