OpenCV Face Recognition How To Question: only print/speak twitter update while face is detected
in
Contributed Library Questions
•
2 years ago
hi, for an art project I'm writing a Processing sketch with OpenCV
library (Face Detection) and twitter streaming library.
I want it so that
only if a face is currently detected the stream starts/continues.
so something like:
if (face detected == true) {
-- do something (println/speak "twitter update")
} else {
println ("please hold your face in front of the camera for the stream to continue")
}
Does anyone have any suggestions??
here's a sample from the sketch:
- void draw() {
- background(0);
- // grab a new frame
- // and convert to gray
- opencv.read();
- opencv.convert( GRAY );
- // proceed detection
- Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );
- // display the image
- image( opencv.image(), 0, 0 );
- // draw face area(s)
- noFill();
- stroke(255,0,0);
- for( int i=0; i<faces.length; i++ ) {
- image( a, faces[i].x, faces[i].y, faces[i].width, faces[i].height );
- //image( b, faces[i].x, faces[i].y, faces[i].width, faces[i].height );
- }
- }
- // called by twitter stream whenever a new tweet comes in
- void tweet(Status tweet) {
- // if (face detection==true) {
- println(tweets + " - You've got a new message: " + tweet.text());
- tweetText = tweet.text();
- tts.speak(tweetText);
- tweets += 1;
- // } else println "keep your face in front of the camera to receive new messages!"
- }
UPDATE: THIS SEEMS TO WORK:
- void draw() {
- background(0);
- // grab a new frame
- // and convert to gray
- opencv.read();
- opencv.convert( GRAY );
- // proceed detection
- Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );
- // display the image
- image( opencv.image(), 0, 0 );
- // draw face area(s)
- noFill();
- stroke(255,0,0);
- for( int i=0; i<faces.length; i++ ) {
- Rectangle(faces[i].x, faces[i].y, faces[i].width, faces[i].height );
- //image( b, faces[i].x, faces[i].y, faces[i].width, faces[i].height );
- detect = true;
- }
- for( int i=0; i==faces.length; i++ ) {
- detect=false;
- }
- }
- // called by twitter stream whenever a new tweet comes in
- void tweet(Status tweet) {
- // if (face detection==true) {
- if(detect==true){
- println(tweets + " - You've got a new message: " + tweet.text());
- tweetText = tweet.text();
- tts.speak(tweetText);
- // } else println "keep your face in front of the camera to receive new messages!"
- } else {
- println("keep your face in front of the camera");
- }
- tweets += 1;
- }
1